diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2022-01-05 22:06:23 -0500 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2022-01-05 22:06:23 -0500 |
commit | 80f87a4667bf318737a0e48027363fdda29665a1 (patch) | |
tree | 3831953d8fdb3c4e109521181621d7116ddae57e /qolab/hardware | |
parent | e377658e7c414318d5bcdc72b477a8e78e846fd0 (diff) | |
download | qolab-80f87a4667bf318737a0e48027363fdda29665a1.tar.gz qolab-80f87a4667bf318737a0e48027363fdda29665a1.zip |
further simplification of the i800 code
Diffstat (limited to 'qolab/hardware')
-rw-r--r-- | qolab/hardware/i_server/i800.py | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/qolab/hardware/i_server/i800.py b/qolab/hardware/i_server/i800.py index e7b8dcb..7743d84 100644 --- a/qolab/hardware/i_server/i800.py +++ b/qolab/hardware/i_server/i800.py @@ -16,29 +16,30 @@ class I800(BasicInstrument): BasicInstrument.__init__(self, *args, **kwds) self.host=host self.port=port + self.modbus_address='01' + self.cmd_start_marker='*' self.config['Device type']='TemperatureController' self.config['Device model'] = 'i800' self.config['FnamePrefix'] = 'temperature' self.deviceProperties = {'Temperature'} - def query(self, qstr): + def query(self, cmnd): + 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')) - return s.recv(100).decode('ascii') + reply = s.recv(100).decode('ascii') + if reply[0:5] != f'{modbus_cmnd}': + # check the proper echo response + return None + return reply[5:-1] # last symbol is '\r' @BasicInstrument.tsdb_append def getTemperature(self): - cmd_start_marker='*' - modbus_address='01' command='X01'; # give decimal representation (X) of the temperature (01 address) - qstr=f'POST / HTTP/1.1\r\n\r\n{cmd_start_marker}{modbus_address}{command}\r\n' - reply=self.query(qstr) - if reply[0:5] != f'{modbus_address}{command}': - # check the proper echo response - return None - t = reply[5:] - t = float(t) + reply=self.query(command) + t = float(reply) return t |