pygpibtoolkit/plotter/gpib_plotter.py

changeset 109
c2d93abebab3
parent 108
dadf7c8d43ad
equal deleted inserted replaced
108:dadf7c8d43ad 109:c2d93abebab3
95 if res: 95 if res:
96 print("DONE (received %d characters)" % len(res)) 96 print("DONE (received %d characters)" % len(res))
97 return res 97 return res
98 98
99 99
100 if __name__ == '__main__': 100 def main():
101 global GPIBplotter
102
101 import optparse 103 import optparse
102 opt = optparse.OptionParser( 104 opt = optparse.OptionParser(
103 'A simple HP7470A GPIB plotter emulator for ' 105 'A simple HP7470A GPIB plotter emulator for '
104 'USB-GPIB bundle (ProLogix)') 106 'USB-GPIB bundle (ProLogix)')
105 opt.add_option( 107 opt.add_option(
123 opt.add_option( 125 opt.add_option(
124 '-v', '--verbose', default=False, 126 '-v', '--verbose', default=False,
125 action="store_true", 127 action="store_true",
126 dest="verbose", 128 dest="verbose",
127 help="Verbose mode") 129 help="Verbose mode")
130 opt.add_option(
131 '-m', '--mockup', default=False,
132 action="store_true",
133 dest='mockup',
134 help='Use a pseudo GPIB connection (for test purpose)')
128 135
129 options, argv = opt.parse_args(sys.argv) 136 options, argv = opt.parse_args(sys.argv)
130 137
131 if options.loop and not options.filename: 138 if options.loop and not options.filename:
132 opt.error('If loop is set, you *must* provide a filename') 139 opt.error('If loop is set, you *must* provide a filename')
133 140
134 if options.filename: 141 if options.filename:
135 outf = open(options.filename, "w") 142 outf = open(options.filename, "w")
136 else: 143 else:
137 outf = sys.stdout 144 outf = sys.stdout
145
146 if options.mockup:
147 from pygpibtoolkit.plotter.gpib_plotter_mockup import GPIBplotter
138 148
139 try: 149 try:
140 plotter = GPIBplotter( 150 plotter = GPIBplotter(
141 device=options.device, address=int(options.address), 151 device=options.device, address=int(options.address),
142 timeout=0.06) 152 timeout=0.06)
164 loop = False 174 loop = False
165 else: 175 else:
166 nloop += 1 176 nloop += 1
167 fname, ext = os.path.splitext(options.filename) 177 fname, ext = os.path.splitext(options.filename)
168 outf = open(fname + "_%d" % nloop + ext, 'w') 178 outf = open(fname + "_%d" % nloop + ext, 'w')
179
180
181 if __name__ == '__main__':
182 main()

mercurial