--- a/dump_trace.py Fri Dec 14 00:21:47 2007 +0100 +++ b/dump_trace.py Fri Dec 14 00:24:11 2007 +0100 @@ -2,22 +2,31 @@ import time import gpib -class GPIBtracedumper(gpib.GPIB): +class HP3562dumper(gpib.GPIB): - MODE = {'binary': 'DDBN', - 'ascii': 'DDAS', - 'ansi': 'DDAN', - } + MODES = {'trace': 'DD', + 'state': 'DS', + 'coord': 'DC', + } + + FORMATS = {'binary': 'BN', + 'ascii': 'AS', + 'ansi': 'AN'} + def __init__(self, device="/dev/ttyUSB0", baudrate=115200, timeout=0.1, address=0): - super(GPIBtracedumper, self).__init__(device, baudrate, timeout, address, mode=1) + super(HP3562dumper, self).__init__(device, baudrate, timeout, address, mode=1) - def read_trace(self, mode="binary"): + def dump(self, mode='trace', format="binary"): + format = format.lower() mode = mode.lower() - assert mode in MODE - mode = MODE[mode] + assert mode in self.MODES + assert format in self.FORMATS + cmd = self.MODES[mode] + self.FORMATS[format] + res = "" - self._cnx.write('%s\r'%mode) + print "command = ", cmd + self._cnx.write('%s\r'%cmd) i = 0 while i<self._retries: l = self._cnx.readline() @@ -29,6 +38,7 @@ i = 0 return res + if __name__=='__main__': import optparse @@ -40,20 +50,23 @@ dest='device', help='Device of the RS232 connection (default: /dev/ttyUSB0)', ) + opt.add_option('-a', '--address', default=0, + dest='address', + help='GPIB address of the device', + ) + opt.add_option('-b', '--block', default='trace', + dest='block', + help='Data block to dump (may be "trace" [default], "state" or "coord")', + ) opt.add_option('-m', '--mode', default='binary', dest='mode', help='Dumping mode (may be "binary" [default], "ascii" or "ansi")', ) - opt.add_option('-a', '--address', default=0, - dest='address', - help='GPIB address of the device', - ) options, argv = opt.parse_args(sys.argv) - cnx = GPIBtracedumper(device=options.device, - address=int(options.address)) - res = cnx.read_trace(mode=options.mode) - + cnx = HP3562dumper(device=options.device, address=int(options.address)) + res = cnx.dump(mode=options.block, format=options.mode) + sys.stderr.write("read %s bytes\n"%(len(res))) if options.filename: open(options.filename, 'w').write(res) else: