fixes in gpib module

Tue, 11 Dec 2007 00:07:33 +0100

author
David Douard <david.douard@logilab.fr>
date
Tue, 11 Dec 2007 00:07:33 +0100
changeset 7
2e2742648546
parent 6
6b6dc68588b2
child 8
aa3d55f78563

fixes in gpib module

gpib.py file | annotate | diff | comparison | revisions
--- a/gpib.py	Mon Dec 10 21:40:39 2007 +0100
+++ b/gpib.py	Tue Dec 11 00:07:33 2007 +0100
@@ -10,21 +10,21 @@
     pass
 
 class GPIB(object):
-    _retries = 10
+    _retries = 15
     def __init__(self, device="/dev/ttyUSB0", baudrate=115200, timeout=0.1,
                     address=0, mode=1):        
         self._cnx = serial.Serial(port=device, baudrate=baudrate, timeout=timeout)
         self._timeout = timeout
         
         self.set_mode(mode)
-        if mode == 1:
-            self.set_address(address)
+        self.set_address(address)
 
     def _set_cmd(self, cmd, value):
         self._cnx.write('++%s %d\r'%(cmd, value))
-        rval = self._read()
+        self._cnx.write('++%s\r'%(cmd))
+        rval = self._read().strip()
         if not rval.isdigit() or int(rval) != value:
-            raise ConnectionError("Can't set GPIB %s to %s"%(cmd, value))
+            raise ConnectionError("Can't set GPIB %s to %s [ret=%s]"%(cmd, value, repr(rval)))
         
     def set_address(self, address):        
         self._set_cmd('addr', address)
@@ -35,7 +35,7 @@
         self._mode = mode
         
     def _read(self):
-        for i in range(self._retries):    
+        for i in range(self._retries):
             rdata = self._cnx.readline()
             if rdata.strip() != "":
                 break

mercurial