Thu, 02 Apr 2009 16:27:29 +0200
copyright updated
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 | 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 | 23 | cnx = GPIB(device=options.device) |
24 | c = GPIBController(cnx) | |
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 | 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 | 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 |