diff options
Diffstat (limited to 'qolab/hardware')
-rw-r--r-- | qolab/hardware/i_server/i800.py | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/qolab/hardware/i_server/i800.py b/qolab/hardware/i_server/i800.py index 318be11..2b3f55f 100644 --- a/qolab/hardware/i_server/i800.py +++ b/qolab/hardware/i_server/i800.py @@ -30,15 +30,19 @@ class I800(BasicInstrument): self.config['FnamePrefix'] = 'temperature' self.deviceProperties = {'Temperature', 'SetPoint1', 'SetPoint2'} - def query(self, cmnd): + def query(self, cmnd, trials=10): modbus_cmnd = f'{self.modbus_address}{cmnd}' qstr=f'POST / HTTP/1.1\r\n\r\n{self.cmd_start_marker}{modbus_cmnd}\r\n' s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((self.host, self.port)) s.send(qstr.encode('ascii')) reply = s.recv(100).decode('ascii') + s.close() if reply[0:5] != f'{modbus_cmnd}': # check the proper echo response + print(f'Warning: expected {modbus_cmnd} but got {reply[0:5]}') + if trials > 0: + return self.query(cmnd, trials -1 ) return None return reply[5:-1] # last symbol is '\r' @@ -46,7 +50,11 @@ class I800(BasicInstrument): @cached(cache=TTLCache(maxsize=1, ttl=TTL_MEASURED)) def getTemperature(self): command='X01'; # give decimal representation (X) of the temperature (01 address) - return float(self.query(command)) + reply=self.query(command) + if reply is not None: + return float(reply) + else: + return float('nan') def setPoinStr2value(self, spStr): raw = int(spStr, 16) @@ -75,14 +83,20 @@ class I800(BasicInstrument): def getSetPoint1(self): command='R01' reply=self.query(command) - return (self.setPoinStr2value(reply)) + if reply is not None: + return (self.setPoinStr2value(reply)) + else: + return float('nan') @BasicInstrument.tsdb_append @cached(cache=TTLCache(maxsize=1, ttl=TTL_SEATABLES)) def getSetPoint2(self): command='R02' reply=self.query(command) - return (self.setPoinStr2value(reply)) + if reply is not None: + return (self.setPoinStr2value(reply)) + else: + return float('nan') if __name__ == '__main__': tc = I800() |