aboutsummaryrefslogtreecommitdiff
path: root/qolab/hardware/i_server/i800.py
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2022-01-05 21:49:48 -0500
committerEugeniy E. Mikhailov <evgmik@gmail.com>2022-01-05 21:49:48 -0500
commite377658e7c414318d5bcdc72b477a8e78e846fd0 (patch)
treeabd4fbd0db6f30c14ac1e38c8d7d1964f0680ec8 /qolab/hardware/i_server/i800.py
parent5a0acbc09e600a2bbc4e2d35d8b082476b7c04c2 (diff)
downloadqolab-e377658e7c414318d5bcdc72b477a8e78e846fd0.tar.gz
qolab-e377658e7c414318d5bcdc72b477a8e78e846fd0.zip
isolate communication logic
Diffstat (limited to 'qolab/hardware/i_server/i800.py')
-rw-r--r--qolab/hardware/i_server/i800.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/qolab/hardware/i_server/i800.py b/qolab/hardware/i_server/i800.py
index c42b5dd..e7b8dcb 100644
--- a/qolab/hardware/i_server/i800.py
+++ b/qolab/hardware/i_server/i800.py
@@ -19,19 +19,22 @@ class I800(BasicInstrument):
self.config['Device type']='TemperatureController'
self.config['Device model'] = 'i800'
self.config['FnamePrefix'] = 'temperature'
- self.deviceProperties = {'Temerature'}
+ self.deviceProperties = {'Temperature'}
- @BasicInstrument.tsdb_append
- def getTemperature(self):
+ def query(self, qstr):
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')
+
+ @BasicInstrument.tsdb_append
+ def getTemperature(self):
cmd_start_marker='*'
modbus_address='01'
command='X01'; # give decimal representation (X) of the temperature (01 address)
- cmnd=f'POST / HTTP/1.1\r\n\r\n{cmd_start_marker}{modbus_address}{command}\r\n'
- s.send(cmnd.encode('ascii'))
- reply=s.recv(100).decode('ascii')
- if reply[0:5] != '01X01':
+ 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:]