Tue, 19 Aug 2008 22:47:16 +0200
add a simple 'gpib_detect' command line tool and some minor fixes
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 |
624157f78b77
add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
12 | |
624157f78b77
add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
13 | def main(): |
624157f78b77
add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
14 | import optparse |
624157f78b77
add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
15 | 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
|
16 | 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
|
17 | dest="device", |
624157f78b77
add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
18 | 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
|
19 | 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
|
20 | |
624157f78b77
add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
21 | 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
|
22 | 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
|
23 | 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
|
24 | |
624157f78b77
add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
25 | 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
|
26 | 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
|
27 | 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
|
28 | 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
|
29 | 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
|
30 | c.stop() |
624157f78b77
add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
31 | |
624157f78b77
add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
32 | 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
|
33 | main() |
624157f78b77
add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
34 |