aboutsummaryrefslogtreecommitdiff
path: root/qolab
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2024-07-13 23:32:42 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2024-07-13 23:32:42 -0400
commitf2b41f44e30e791c31cc5dfc5a048e267b62730a (patch)
tree3cee18a207838d48b8bb9dd3521562a9eff27b56 /qolab
parent5b3553724b3534e3ac773dbbbf43efa559af0ee0 (diff)
downloadqolab-f2b41f44e30e791c31cc5dfc5a048e267b62730a.tar.gz
qolab-f2b41f44e30e791c31cc5dfc5a048e267b62730a.zip
black formatter
Diffstat (limited to 'qolab')
-rw-r--r--qolab/hardware/i_server/i800.py98
1 files changed, 57 insertions, 41 deletions
diff --git a/qolab/hardware/i_server/i800.py b/qolab/hardware/i_server/i800.py
index 89042d5..1d9b08a 100644
--- a/qolab/hardware/i_server/i800.py
+++ b/qolab/hardware/i_server/i800.py
@@ -9,61 +9,75 @@ Querying of this controller is slo-o-o-w at least 0.2 second and can be longer.
from qolab.hardware.basic import BasicInstrument
from cachetools import cached, TTLCache
import socket
-
import logging
-logger = logging.getLogger('qolab.hardware.i_server.i800')
+
+logger = logging.getLogger("qolab.hardware.i_server.i800")
+
class I800(BasicInstrument):
- """ Newport i800 series controller, should work with similar Omega controllers """
- TTL_MEASURED = 30 # Time To Live for device measured things, i.e. Temperature
- TTL_SEATABLES = 600 # Time To Live for user seatables, i.e. SetPoints, Gains, etc
+ """Newport i800 series controller, should work with similar Omega controllers
+
+ Example
+ -------
+
+ >>> tc = I800(host='192.168.1.200', port=1000)
+ >>> print(tc.getConfig())
+ """
- def __init__(self, *args, host='192.168.1.200', port=1000, **kwds):
+ TTL_MEASURED = 30 # Time To Live for device measured things, i.e. Temperature
+ TTL_SEATABLES = 600 # Time To Live for user seatables, i.e. SetPoints, Gains, etc
+
+ def __init__(self, *args, host="192.168.1.200", port=1000, **kwds):
"""
host - default hostname or IP of the controller unit (192.168.1.200) is factory default
port - socket port (1000 by default) which accept HTTP POST requests
"""
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.update({'Temperature', 'SetPoint1', 'SetPoint2'})
+ 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.update({"Temperature", "SetPoint1", "SetPoint2"})
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'
+ 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.send(qstr.encode("ascii"))
+ reply = s.recv(100).decode("ascii")
s.close()
- rlist=reply.split(); # occasionally there is more than one reply, it also removes \r
- lreply=rlist[-1]; # we will use the last one
- if lreply[0:5] != f'{modbus_cmnd}':
+ rlist = reply.split()
+ # occasionally there is more than one reply, it also removes \r
+ lreply = rlist[-1]
+ # we will use the last one
+ if lreply[0:5] != f"{modbus_cmnd}":
# check the proper echo response
- logger.warning(f'Warning: expected {modbus_cmnd} but got {lreply[0:5]} in full set {reply}')
+ logger.warning(
+ f"Warning: expected {modbus_cmnd} but got {lreply[0:5]} in full set {reply}"
+ )
if trials > 0:
- return self.query(cmnd, trials -1 )
+ return self.query(cmnd, trials - 1)
return None
return lreply[5:]
@BasicInstrument.tsdb_append
@cached(cache=TTLCache(maxsize=1, ttl=TTL_MEASURED))
def getTemperature(self):
- command='X01'; # give decimal representation (X) of the temperature (01 address)
- reply=self.query(command)
+ command = "X01"
+ # give decimal representation (X) of the temperature (01 address)
+ reply = self.query(command)
if reply is not None:
return float(reply)
else:
- return float('nan')
+ return float("nan")
def setPoinStr2value(self, spStr):
raw = int(spStr, 16)
- if raw & (1<<23):
+ if raw & (1 << 23):
sign = -1
else:
sign = 1
@@ -77,33 +91,35 @@ class I800(BasicInstrument):
elif raw & (0b100 << 20):
scale = 100
else:
- logger.error(f'Error: unknown decimal point position in decoded {spStr} {bin(raw)}')
- return float('nan')
+ logger.error(
+ f"Error: unknown decimal point position in decoded {spStr} {bin(raw)}"
+ )
+ return float("nan")
val = raw & 0xFFFFF
- return float(sign*val/scale)
+ return float(sign * val / scale)
@BasicInstrument.tsdb_append
@cached(cache=TTLCache(maxsize=1, ttl=TTL_SEATABLES))
def getSetPoint1(self):
- command='R01'
- reply=self.query(command)
+ command = "R01"
+ reply = self.query(command)
if reply is not None:
- return (self.setPoinStr2value(reply))
+ return self.setPoinStr2value(reply)
else:
- return float('nan')
+ return float("nan")
@BasicInstrument.tsdb_append
@cached(cache=TTLCache(maxsize=1, ttl=TTL_SEATABLES))
def getSetPoint2(self):
- command='R02'
- reply=self.query(command)
+ command = "R02"
+ reply = self.query(command)
if reply is not None:
- return (self.setPoinStr2value(reply))
+ return self.setPoinStr2value(reply)
else:
- return float('nan')
-
-if __name__ == '__main__':
+ return float("nan")
+
+
+if __name__ == "__main__":
tc = I800()
print(tc.getConfig())
-