bin/3456logger.py

Mon, 04 Jun 2018 22:28:05 +0200

author
David Douard <david.douard@logilab.fr>
date
Mon, 04 Jun 2018 22:28:05 +0200
changeset 109
c2d93abebab3
parent 79
b8eec4f9db52
permissions
-rw-r--r--

[plotter] add a --mockup option to the demo main function

79
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
1 #!/usr/bin/python
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
2 import sys
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
3 import os
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
4 import signal
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
5 import time
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
6 import optparse
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
7
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
8 try:
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
9 from pygpibtoolkit.gpibcontroller import GPIBController, deviceRegister
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
10 except ImportError:
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
11 sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
12 from pygpibtoolkit.gpibcontroller import GPIBController, deviceRegister
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
13
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
14 import pygpibtoolkit.HP3562A
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
15 import pygpibtoolkit.HP3456
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
16
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
17 from pygpibtoolkit.prologix import GPIB
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
18
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
19 opt = optparse.OptionParser("A simple tool for detecting connected GPIB devices")
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
20 opt.add_option('-d', '--device', default="/dev/ttyUSB0",
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
21 dest="device",
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
22 help="Device of connected Prologix GPIB bundle [/dev/ttyUSB0]",)
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
23 options, argv = opt.parse_args(sys.argv)
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
24
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
25
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
26 cnx = GPIB(device=options.device)
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
27 c = GPIBController(cnx)
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
28
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
29 m = c.register_device(24, "HP3456A")
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
30
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
31 def cb(val):
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
32 print val
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
33
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
34 m.register_data_cb(cb)
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
35 m.send_command('SM004')
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
36 m.send_command('T1SO1')
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
37
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
38 try:
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
39 while True:
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
40 time.sleep(0.1)
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
41 except KeyboardInterrupt:
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
42 pass
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
43
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
44 m.send_command('SO0')
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents:
diff changeset
45 c.stop()

mercurial