[plotter] add a --mockup option to the demo main function default tip

Mon, 04 Jun 2018 22:28:05 +0200

author
David Douard <david.douard@logilab.fr>
date
Mon, 04 Jun 2018 22:28:05 +0200
changeset 109
c2d93abebab3
parent 108
dadf7c8d43ad

[plotter] add a --mockup option to the demo main function

pygpibtoolkit/plotter/gpib_plotter.py file | annotate | diff | comparison | revisions
--- a/pygpibtoolkit/plotter/gpib_plotter.py	Mon Jun 04 22:27:41 2018 +0200
+++ b/pygpibtoolkit/plotter/gpib_plotter.py	Mon Jun 04 22:28:05 2018 +0200
@@ -97,7 +97,9 @@
         return res
 
 
-if __name__ == '__main__':
+def main():
+    global GPIBplotter
+
     import optparse
     opt = optparse.OptionParser(
         'A simple HP7470A GPIB plotter emulator for '
@@ -125,6 +127,11 @@
         action="store_true",
         dest="verbose",
         help="Verbose mode")
+    opt.add_option(
+        '-m', '--mockup', default=False,
+        action="store_true",
+        dest='mockup',
+        help='Use a pseudo GPIB connection (for test purpose)')
 
     options, argv = opt.parse_args(sys.argv)
 
@@ -136,6 +143,9 @@
     else:
         outf = sys.stdout
 
+    if options.mockup:
+        from pygpibtoolkit.plotter.gpib_plotter_mockup import GPIBplotter
+
     try:
         plotter = GPIBplotter(
             device=options.device, address=int(options.address),
@@ -166,3 +176,7 @@
                 nloop += 1
                 fname, ext = os.path.splitext(options.filename)
                 outf = open(fname + "_%d" % nloop + ext, 'w')
+
+
+if __name__ == '__main__':
+    main()

mercurial