102 |
102 |
103 def run(self): |
103 def run(self): |
104 while self.running: |
104 while self.running: |
105 data = self.cnx.readline().strip() |
105 data = self.cnx.readline().strip() |
106 if data: |
106 if data: |
107 if data[:2] == b'++': |
107 for row in data.splitlines(): |
108 self.parse_cmd(data) |
108 if row[:2] == b'++': |
109 else: |
109 self.parse_cmd(row) |
110 self.parse_data(data) |
110 else: |
|
111 self.parse_data(row) |
111 elif not self.output.empty(): |
112 elif not self.output.empty(): |
112 data = self.output.get() |
113 data = self.output.get() |
113 logger.info('Sending %r' % data) |
114 logger.info('Sending %r' % data) |
114 self.cnx.write(data) |
115 self.cnx.write(data) |
115 else: |
116 else: |
185 else: |
186 else: |
186 raise Exception() |
187 raise Exception() |
187 except: |
188 except: |
188 self.output.put(b'Error\r\n') |
189 self.output.put(b'Error\r\n') |
189 |
190 |
|
191 def parse_cmd_ifc(self, args): |
|
192 pass |
|
193 |
190 |
194 |
191 class HPGLPlotingDevice: |
195 class HPGLPlotingDevice: |
192 def __init__(self, emulator, address=5): |
196 def __init__(self, emulator, address=5): |
193 self.plotter_address = address |
197 self.plotter_address = address |
194 self.filenames = glob.glob('examples/hpgl_plots/*.plt') |
198 self.filenames = glob.glob('examples/hpgl_plots/*.plt') |
198 if fname is None: |
202 if fname is None: |
199 fname = random.choice(self.filenames) |
203 fname = random.choice(self.filenames) |
200 with open(fname) as fobj: |
204 with open(fname) as fobj: |
201 ret = fobj.read().strip() |
205 ret = fobj.read().strip() |
202 if ret: |
206 if ret: |
203 self.emulator.send(ret) |
207 self.emulator.send(ret.encode()) |
204 |
208 |
205 |
209 |
206 def main(): |
210 def main(): |
207 emul = PrologixEmulator() |
211 emul = PrologixEmulator() |
208 cnx = serial.Serial(emul.serialurl, timeout=0) |
212 device = HPGLPlotingDevice(emul) |
209 for i in range(10): |
213 emul.attach_device(10, device) |
210 data = '++cmd %s' % i |
214 from pygpibtoolkit.plotter.gpib_plotter import GPIBplotter |
211 print('SEND', data) |
215 plotter = GPIBplotter( |
212 cnx.write(data.encode() + b'\r\n') |
216 device=emul.serialurl, |
213 time.sleep(0.1) |
217 address=5, |
214 print('GOT %r' % cnx.readall()) |
218 timeout=0.06) |
|
219 device.plot() |
|
220 |
|
221 while True: |
|
222 plot = plotter.load_plot() |
|
223 if plot: |
|
224 print('PLOT') |
|
225 break |
215 |
226 |
216 emul.close() |
227 emul.close() |
217 |
228 |
218 |
229 |
219 if __name__ == '__main__': |
230 if __name__ == '__main__': |