dump_trace.py

changeset 1
0670b1f5c155
parent 0
9af1509775b6
child 4
269aacbb2bf2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dump_trace.py	Mon Dec 10 21:18:31 2007 +0100
@@ -0,0 +1,56 @@
+import sys
+import time
+
+MODE = {'binary': 'DDBN',
+        'ascii': 'DDAS',
+        'ansi': 'DDAN',
+        }
+
+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 
+        i = 0
+    return res
+
+
+
+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)
+
+if options.filename:
+    open(options.filename, 'w').write(res)
+else:
+    print res
+    

mercurial