bin/gpib_detect

Tue, 19 Aug 2008 23:01:19 +0200

author
David Douard <david.douard@logilab.fr>
date
Tue, 19 Aug 2008 23:01:19 +0200
changeset 65
10d218fbf86f
parent 64
624157f78b77
child 70
4cd8edd2b4e7
permissions
-rwxr-xr-x

fixes to make gpib_detect works

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
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
22 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
23 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
24 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
25
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
26 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
27 devices = c.detect_devices()
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
28 print "Found devices:"
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
29 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
30 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
31 c.stop()
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
32
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
33 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
34 main()
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
35

mercurial