pygpibtoolkit/detect.py

Wed, 16 May 2018 10:07:26 +0200

author
David Douard <david.douard@logilab.fr>
date
Wed, 16 May 2018 10:07:26 +0200
changeset 91
f2a8f688dbc0
parent 87
59a0946aa3d1
permissions
-rwxr-xr-x

project moved to bitbucket

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
86
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
2 # This program is free software; you can redistribute it and/or modify it under
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
3 # the terms of the GNU General Public License as published by the Free Software
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
4 # Foundation; either version 2 of the License, or (at your option) any later
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
5 # version.
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
6 #
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
7 # This program is distributed in the hope that it will be useful, but WITHOUT
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
8 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
9 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
10 #
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
11 # You should have received a copy of the GNU General Public License along with
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
12 # this program; if not, write to the Free Software Foundation, Inc.,
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
13 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
14 """ Copyright (c) 2007-2018 David Douard (Paris, FRANCE).
91
f2a8f688dbc0 project moved to bitbucket
David Douard <david.douard@logilab.fr>
parents: 87
diff changeset
15 https://bitbucket.org/dddouard/pygpibtoolkit -- mailto:david.douard@sdfa3.org
86
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
16 """
64
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
17 import sys
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
18 import signal
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
19 import time
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
20
86
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
21 from pygpibtoolkit.gpibcontroller import GPIBController
79
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents: 70
diff changeset
22 from pygpibtoolkit.prologix import GPIB
86
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
23
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
24
64
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
25 def main():
86
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
26 import argparse
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
27 opt = argparse.ArgumentParser(
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
28 "A simple tool for detecting connected GPIB devices")
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
29 opt.add_argument(
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
30 '-d', '--device', default="/dev/ttyUSB0",
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
31 dest="device",
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
32 help="Device of connected Prologix GPIB bundle [/dev/ttyUSB0]",)
87
59a0946aa3d1 port HPGL plotter emulator to PyQt5
David Douard <david.douard@logilab.fr>
parents: 86
diff changeset
33 opt.add_argument('-v', '--verbose', action='store_true', default=False)
59a0946aa3d1 port HPGL plotter emulator to PyQt5
David Douard <david.douard@logilab.fr>
parents: 86
diff changeset
34 options = opt.parse_args()
64
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
35
86
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
36 print("Detecting GPIB devices on the bus. Please wait until completion.")
79
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents: 70
diff changeset
37 cnx = GPIB(device=options.device)
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents: 70
diff changeset
38 c = GPIBController(cnx)
86
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
39
64
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
40 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
41 signal.signal(signal.SIGQUIT, c.stop)
86
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
42
64
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
43 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
44 devices = c.detect_devices()
70
4cd8edd2b4e7 Display an introduction message when running gpib_detect.
David Douard <david.douard@logilab.fr>
parents: 65
diff changeset
45 c.stop()
86
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
46
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
47 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
48 for k in sorted(devices.keys()):
86
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
49 print("%-3d: %s" % (k, devices[k]))
79
b8eec4f9db52 many improvements:
David Douard <david.douard@logilab.fr>
parents: 70
diff changeset
50 return c, devices
86
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
51
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
52
64
624157f78b77 add a simple 'gpib_detect' command line tool and some minor fixes
David Douard <david.douard@logilab.fr>
parents:
diff changeset
53 if __name__ == "__main__":
86
96e30b092f70 [py3k] beginning to port to py3k
David Douard <david.douard@logilab.fr>
parents: 79
diff changeset
54 main()

mercurial