bin/gpib_detect

Tue, 26 Aug 2008 21:13:12 +0200

author
David Douard <david.douard@logilab.fr>
date
Tue, 26 Aug 2008 21:13:12 +0200
changeset 75
069666c7bf6c
parent 70
4cd8edd2b4e7
child 79
b8eec4f9db52
permissions
-rwxr-xr-x

force display of opened file, instead of just adding ot to the plots list

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
64
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
13
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."
64
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
23 c = GPIBController(device=options.device)
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
24 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
25 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
26
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
27 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
28 devices = c.detect_devices()
70
4cd8edd2b4e7 Display an introduction message when running gpib_detect.
David Douard <david.douard@logilab.fr>
parents: 65
diff changeset
29 c.stop()
4cd8edd2b4e7 Display an introduction message when running gpib_detect.
David Douard <david.douard@logilab.fr>
parents: 65
diff changeset
30
4cd8edd2b4e7 Display an introduction message when running gpib_detect.
David Douard <david.douard@logilab.fr>
parents: 65
diff changeset
31 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
32 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
33 print "%-3d: %s"%(k, devices[k])
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
34
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
35 if __name__ == "__main__":
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
36 main()
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
37

mercurial