aboutsummaryrefslogtreecommitdiff
path: root/qolab/hardware/i_server/i800.py
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2022-01-06 20:08:53 -0500
committerEugeniy E. Mikhailov <evgmik@gmail.com>2022-01-06 20:08:53 -0500
commit8c982a8371c029e3592ca047f70e0d3422884f91 (patch)
treef7ec4ed00135d7d841b8347393bf4b8d187c2475 /qolab/hardware/i_server/i800.py
parent1a85082804467fe5269101a75e10aa81b4bae54a (diff)
downloadqolab-8c982a8371c029e3592ca047f70e0d3422884f91.tar.gz
qolab-8c982a8371c029e3592ca047f70e0d3422884f91.zip
addded safety net against misreported values by the temperature controller
Diffstat (limited to 'qolab/hardware/i_server/i800.py')
-rw-r--r--qolab/hardware/i_server/i800.py22
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()