Mon, 10 Dec 2007 21:28:14 +0100
ported 'dump_trace' to gpib API
dump_trace.py | file | annotate | diff | comparison | revisions |
--- a/dump_trace.py Mon Dec 10 21:22:33 2007 +0100 +++ b/dump_trace.py Mon Dec 10 21:28:14 2007 +0100 @@ -2,28 +2,32 @@ import time import gpib -MODE = {'binary': 'DDBN', - 'ascii': 'DDAS', - 'ansi': 'DDAN', - } +class GPIBtracedumper(gpib.GPIB): + + MODE = {'binary': 'DDBN', + 'ascii': 'DDAS', + 'ansi': 'DDAN', + } + def __init__(self, device="/dev/ttyUSB0", baudrate=115200, timeout=0.1, + address=0): + super(GPIBtracedumper, self).__init__(device, baudrate, timeout, address, mode=1) -def read_trace(cnx, mode="binary"): - mode = mode.lower() - assert mode in MODE - mode = MODE[mode] - res = "" - cnx.write('%s\r'%mode) - i = 0 - while i<5: - l = cnx.readline() - if l.strip() == "": - i += 1 - time.sleep(0.1) - continue - #print "got a new line (%s chars) [i=%s]"%(len(l), i) - res += l + def read_trace(self, mode="binary"): + mode = mode.lower() + assert mode in MODE + mode = MODE[mode] + res = "" + self._cnx.write('%s\r'%mode) i = 0 - return res + while i<self._retries: + l = self._cnx.readline() + if l.strip() == "": + i += 1 + time.sleep(self._timeout) + continue + res += l + i = 0 + return res if __name__=='__main__': @@ -46,9 +50,9 @@ ) options, argv = opt.parse_args(sys.argv) - cnx = open_connection(device=options.device, - address=int(options.address), mode=1) - res = read_trace(cnx, mode=options.mode) + cnx = GPIBtracedumper(device=options.device, + address=int(options.address)) + res = cnx.read_trace(mode=options.mode) if options.filename: open(options.filename, 'w').write(res)