[prologix] small fix in the prologix emulator

Sun, 03 Jun 2018 18:04:43 +0200

author
David Douard <david.douard@logilab.fr>
date
Sun, 03 Jun 2018 18:04:43 +0200
changeset 105
89123c2af2fd
parent 104
916c255b3079
child 106
bb477c9ea28d

[prologix] small fix in the prologix emulator

pygpibtoolkit/prologix_emulator.py file | annotate | diff | comparison | revisions
--- a/pygpibtoolkit/prologix_emulator.py	Thu May 24 23:22:37 2018 +0200
+++ b/pygpibtoolkit/prologix_emulator.py	Sun Jun 03 18:04:43 2018 +0200
@@ -104,10 +104,11 @@
         while self.running:
             data = self.cnx.readline().strip()
             if data:
-                if data[:2] == b'++':
-                    self.parse_cmd(data)
-                else:
-                    self.parse_data(data)
+                for row in data.splitlines():
+                    if row[:2] == b'++':
+                        self.parse_cmd(row)
+                    else:
+                        self.parse_data(row)
             elif not self.output.empty():
                 data = self.output.get()
                 logger.info('Sending %r' % data)
@@ -187,6 +188,9 @@
             except:
                 self.output.put(b'Error\r\n')
 
+    def parse_cmd_ifc(self, args):
+        pass
+
 
 class HPGLPlotingDevice:
     def __init__(self, emulator, address=5):
@@ -200,18 +204,25 @@
         with open(fname) as fobj:
             ret = fobj.read().strip()
             if ret:
-                self.emulator.send(ret)
+                self.emulator.send(ret.encode())
 
 
 def main():
     emul = PrologixEmulator()
-    cnx = serial.Serial(emul.serialurl, timeout=0)
-    for i in range(10):
-        data = '++cmd %s' % i
-        print('SEND', data)
-        cnx.write(data.encode() + b'\r\n')
-        time.sleep(0.1)
-        print('GOT %r' % cnx.readall())
+    device = HPGLPlotingDevice(emul)
+    emul.attach_device(10, device)
+    from pygpibtoolkit.plotter.gpib_plotter import GPIBplotter
+    plotter = GPIBplotter(
+        device=emul.serialurl,
+        address=5,
+        timeout=0.06)
+    device.plot()
+
+    while True:
+        plot = plotter.load_plot()
+        if plot:
+            print('PLOT')
+            break
 
     emul.close()
 

mercurial