diff -r e2587668ec72 -r 269aacbb2bf2 dump_trace.py --- a/dump_trace.py Mon Dec 10 21:19:33 2007 +0100 +++ b/dump_trace.py Mon Dec 10 21:22:33 2007 +0100 @@ -1,5 +1,6 @@ import sys import time +import gpib MODE = {'binary': 'DDBN', 'ascii': 'DDAS', @@ -25,32 +26,32 @@ return res +if __name__=='__main__': + import optparse + opt = optparse.OptionParser("A simple tool for dumping the current trace") + opt.add_option('-f', '--filename', default=None, + dest='filename', + help='Output filename. If not set, write to stdout') + opt.add_option('-d', '--device', default='/dev/ttyUSB0', + dest='device', + help='Device of the RS232 connection (default: /dev/ttyUSB0)', + ) + 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) -import optparse -opt = optparse.OptionParser() -opt.add_option('-f', '--filename', default=None, - dest='filename', - help='Output filename. If not set, write to stdout') -opt.add_option('-d', '--device', default='/dev/ttyUSB0', - dest='device', - help='Device of the RS232 connection (default: /dev/ttyUSB0)', - ) -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 = open_connection(device=options.device, + address=int(options.address), mode=1) + res = read_trace(cnx, mode=options.mode) -cnx = open_connection(device=options.device, - address=int(options.address), mode=1) -res = read_trace(cnx, mode=options.mode) - -if options.filename: - open(options.filename, 'w').write(res) -else: - print res + if options.filename: + open(options.filename, 'w').write(res) + else: + print res