gpib_plotter.py

changeset 8
aa3d55f78563
parent 1
0670b1f5c155
child 12
a04bea92c509
--- a/gpib_plotter.py	Tue Dec 11 00:07:33 2007 +0100
+++ b/gpib_plotter.py	Tue Dec 11 00:07:54 2007 +0100
@@ -3,7 +3,7 @@
 import gpib
 
 class GPIBplotter(gpib.GPIB):
-    replies={
+    _replies={
         "OE": "0",
         "OH": "0,0,10000,7500",
         "OI": "7470A",
@@ -28,8 +28,8 @@
         res = ""
         i=0
         replies = self._replies.copy()
-        if wait_timeout is not None or not isinstance(wait_timeout, int):
-            raise TypeError
+        if wait_timeout is not None and not isinstance(wait_timeout, (float, int)):
+            raise TypeError, "wait_timeout (%s:%s) has wrong type"%(repr(wait_timeout), type(wait_timeout))
         if wait_timeout<0:
             raise ValueError
         
@@ -42,18 +42,20 @@
                 firstloop = False
             if l == "":
                 i += 1
-                for k, v in replies.items():
-                    if res.endswith(k) or res.endswith(k+';'):
-                        self._cnx.write("%s"%v)
-                        if k == "OS":
-                            replies[k] = "16"
-                        break
-                self._cnx.write('\r')
+                if i == (self._retries-1):
+                    for k, v in replies.items():
+                        eres = res.strip()
+                        if eres.endswith(k) or eres.endswith(k+';') or eres.endswith(k+';OE'):
+                            self._cnx.write("%s"%v)
+                            if k == "OS":
+                                replies[k] = "16"
+                            break
+                    self._cnx.write('\r')
                 if i > self._retries/2:
                     time.sleep(self._timeout)
-                continue
-            res += l + "\n"
-            i = 0
+            else:
+                res += l + "\n"
+                i = 0
         return res
 
 if __name__ == '__main__':
@@ -91,7 +93,8 @@
 
 
     try:
-        plotter = GPIBplotter(device=options.device, address=options.address)
+        plotter = GPIBplotter(device=options.device, address=int(options.address),
+                              timeout=0.06)
     except (gpib.SerialException, gpib.ConnectionError), e:
         sys.stderr.write('Connection error:\n\t' + '\n\t'.join([str(x) for x in e.args]) + '\n')
         sys.stderr.write('Check your parameters\n')

mercurial