Mon, 25 Feb 2008 23:21:08 +0100
Try to be a little more robust when instanciating the GPIB class (serial connector)
pygpibtoolkit/prologix.py | file | annotate | diff | comparison | revisions |
--- a/pygpibtoolkit/prologix.py Mon Feb 25 23:19:42 2008 +0100 +++ b/pygpibtoolkit/prologix.py Mon Feb 25 23:21:08 2008 +0100 @@ -24,11 +24,17 @@ """ self._cnx = serial.Serial(port=device, baudrate=baudrate, timeout=timeout) self._timeout = timeout - - self.set_mode(mode) - self.set_address(address) - self._set_cmd('auto', 0) - + + try: + res = self._cnx.readlines() + if res: # empty evetual read buffer + print "there where pending stuffs in buffer", repr(res) + self.set_mode(mode) + self.set_address(address) + self._set_cmd('auto', 0) + except Exception, e: + print "Humm, something went wrong", e + def set_address(self, address, check=True): """ Set the address of the GPIB device: @@ -54,6 +60,8 @@ """ self._set_cmd('mode', mode) self._mode = mode + if self._mode: + self._cnx.write('++ifc\r') def set_controller(self): """ @@ -89,7 +97,7 @@ self._cnx.write('++read eoi\r') # idem ret = "" i = 0 - while not ret.endswith('\r\n') and i<2: + while not ret.endswith('\r\n') and i<3: ret += ''.join(self._cnx.readlines()) time.sleep(self._timeout) # required? i += 1 @@ -148,3 +156,15 @@ rval = self._read().strip() if not rval.isdigit() or int(rval) != value: raise ConnectionError("Can't set GPIB %s to %s [ret=%s]"%(cmd, value, repr(rval))) + + def reset(self): + """ + Perform a reset of the USB device + + """ + print "Resetting GPIB controller" + self._cnx.write('++rst\r') + print "Must wait for 5 seconds" + time.sleep(5) + +