|
1 #!/usr/bin/python |
|
2 import sys |
|
3 import os |
|
4 import signal |
|
5 import time |
|
6 |
|
7 try: |
|
8 from pygpibtoolkit.gpibcontroller import GPIBController |
|
9 except ImportError: |
|
10 sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) |
|
11 from pygpibtoolkit.gpibcontroller import GPIBController |
|
12 |
|
13 def main(): |
|
14 import optparse |
|
15 opt = optparse.OptionParser("A simple tool for detecting connected GPIB devices") |
|
16 opt.add_option('-d', '--device', default="/dev/ttyUSB0", |
|
17 dest="device", |
|
18 help="Device of connected Prologix GPIB bundle [/dev/ttyUSB0]",) |
|
19 options, argv = opt.parse_args(sys.argv) |
|
20 |
|
21 c = GPIBController(device=options.device) |
|
22 signal.signal(signal.SIGINT, c.stop) |
|
23 signal.signal(signal.SIGQUIT, c.stop) |
|
24 |
|
25 time.sleep(1) |
|
26 devices = c.detect_devices() |
|
27 print "Found devices:" |
|
28 for k in sorted(devices.keys()): |
|
29 print "%-3d: %s"%(k, devices[k]) |
|
30 c.stop() |
|
31 |
|
32 if __name__ == "__main__": |
|
33 main() |
|
34 |