bin/gpib_detect

changeset 79
b8eec4f9db52
parent 70
4cd8edd2b4e7
equal deleted inserted replaced
78:b73a9d9e45ec 79:b8eec4f9db52
8 from pygpibtoolkit.gpibcontroller import GPIBController 8 from pygpibtoolkit.gpibcontroller import GPIBController
9 except ImportError: 9 except ImportError:
10 sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) 10 sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
11 from pygpibtoolkit.gpibcontroller import GPIBController 11 from pygpibtoolkit.gpibcontroller import GPIBController
12 import pygpibtoolkit.HP3562A 12 import pygpibtoolkit.HP3562A
13 13 from pygpibtoolkit.prologix import GPIB
14 def main(): 14 def main():
15 import optparse 15 import optparse
16 opt = optparse.OptionParser("A simple tool for detecting connected GPIB devices") 16 opt = optparse.OptionParser("A simple tool for detecting connected GPIB devices")
17 opt.add_option('-d', '--device', default="/dev/ttyUSB0", 17 opt.add_option('-d', '--device', default="/dev/ttyUSB0",
18 dest="device", 18 dest="device",
19 help="Device of connected Prologix GPIB bundle [/dev/ttyUSB0]",) 19 help="Device of connected Prologix GPIB bundle [/dev/ttyUSB0]",)
20 options, argv = opt.parse_args(sys.argv) 20 options, argv = opt.parse_args(sys.argv)
21 21
22 print "Detecting GPIB devices on the bus. Please wait until completion." 22 print "Detecting GPIB devices on the bus. Please wait until completion."
23 c = GPIBController(device=options.device) 23 cnx = GPIB(device=options.device)
24 c = GPIBController(cnx)
25
24 signal.signal(signal.SIGINT, c.stop) 26 signal.signal(signal.SIGINT, c.stop)
25 signal.signal(signal.SIGQUIT, c.stop) 27 signal.signal(signal.SIGQUIT, c.stop)
26 28
27 time.sleep(1) 29 time.sleep(1)
28 devices = c.detect_devices() 30 devices = c.detect_devices()
29 c.stop() 31 c.stop()
30 32
31 print "GPIB devices:" 33 print "GPIB devices:"
32 for k in sorted(devices.keys()): 34 for k in sorted(devices.keys()):
33 print "%-3d: %s"%(k, devices[k]) 35 print "%-3d: %s"%(k, devices[k])
36 return c, devices
37 if __name__ == "__main__":
38 c, dev = main()
34 39
35 if __name__ == "__main__":
36 main()
37

mercurial