bin/gpib_detect

Tue, 31 Mar 2009 00:13:05 +0200

author
David Douard <david.douard@logilab.fr>
date
Tue, 31 Mar 2009 00:13:05 +0200
changeset 82
550811b4c3c1
parent 79
b8eec4f9db52
permissions
-rwxr-xr-x

fixes in HP8904 device description

64
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
1 #!/usr/bin/python
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
2 import sys
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
3 import os
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
4 import signal
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
5 import time
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
6
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
7 try:
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
8 from pygpibtoolkit.gpibcontroller import GPIBController
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
9 except ImportError:
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
10 sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
11 from pygpibtoolkit.gpibcontroller import GPIBController
65
10d218fbf86f fixes to make gpib_detect works
David Douard <david.douard@logilab.fr>
parents: 64
diff changeset
12 import pygpibtoolkit.HP3562A
79
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents: 70
diff changeset
13 from pygpibtoolkit.prologix import GPIB
64
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
14 def main():
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
15 import optparse
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
16 opt = optparse.OptionParser("A simple tool for detecting connected GPIB devices")
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
17 opt.add_option('-d', '--device', default="/dev/ttyUSB0",
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
18 dest="device",
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
19 help="Device of connected Prologix GPIB bundle [/dev/ttyUSB0]",)
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
20 options, argv = opt.parse_args(sys.argv)
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
21
70
4cd8edd2b4e7 Display an introduction message when running gpib_detect.
David Douard <david.douard@logilab.fr>
parents: 65
diff changeset
22 print "Detecting GPIB devices on the bus. Please wait until completion."
79
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents: 70
diff changeset
23 cnx = GPIB(device=options.device)
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents: 70
diff changeset
24 c = GPIBController(cnx)
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents: 70
diff changeset
25
64
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
26 signal.signal(signal.SIGINT, c.stop)
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
27 signal.signal(signal.SIGQUIT, c.stop)
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
28
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
29 time.sleep(1)
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
30 devices = c.detect_devices()
70
4cd8edd2b4e7 Display an introduction message when running gpib_detect.
David Douard <david.douard@logilab.fr>
parents: 65
diff changeset
31 c.stop()
4cd8edd2b4e7 Display an introduction message when running gpib_detect.
David Douard <david.douard@logilab.fr>
parents: 65
diff changeset
32
4cd8edd2b4e7 Display an introduction message when running gpib_detect.
David Douard <david.douard@logilab.fr>
parents: 65
diff changeset
33 print "GPIB devices:"
64
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
34 for k in sorted(devices.keys()):
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
35 print "%-3d: %s"%(k, devices[k])
79
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents: 70
diff changeset
36 return c, devices
64
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
37 if __name__ == "__main__":
79
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents: 70
diff changeset
38 c, dev = main()
64
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
39

mercurial