from pcaspy import Driver, Alarm, Severity
from opus20 import Opus20, OPUS20_CHANNEL_SPEC, Opus20ConnectionException
+import time, threading
+
class Opus20Driver(Driver):
- def __init__(self, hostname, opus20_port=None, opus20_timeout=0.1):
+ def __init__(self, hostname, opus20_port=None, opus20_timeout=0.1, scan_period=5.0):
self.hostname = hostname
self.opus20_port = opus20_port
self.opus20_timeout = opus20_timeout
+ self.scan_period = scan_period
self.connect_opus20()
if self.opus20_timeout: kwargs['timeout'] = self.opus20_timeout
self.o20 = Opus20(self.hostname, **kwargs)
- def read(self, reason):
- if reason in ('Temperature', 'RelativeHumidity', 'AbsoluteHumidity', 'Dewpoint', 'BatteryVoltage'):
+ if self.scan_period > 0:
+ self.tid = threading.Thread(target=self.scan_all)
+ self.tid.setDaemon(True)
+ self.tid.start()
+
+ def scan_all(self):
+ while True:
+ start = time.time()
+
mapping = {
'Temperature': 0x0064,
'RelativeHumidity': 0x00c8,
'Dewpoint': 0x006e,
'BatteryVoltage': 0x2724,
}
- try:
- value = self.o20.channel_value(mapping[reason])
- self.setParamStatus(reason, Alarm.NO_ALARM, Severity.NO_ALARM)
- self.setParam(reason, value)
- except:
- self.setParamStatus(reason, Alarm.COMM_ALARM, Severity.MINOR_ALARM)
- value = self.getParam(reason)
- else:
- value = self.getParam(reason)
-
- return value
-
+ for reason in mapping.keys():
+ try:
+ value = self.o20.channel_value(mapping[reason])
+ self.setParamStatus(reason, Alarm.NO_ALARM, Severity.NO_ALARM)
+ self.setParam(reason, value)
+ except:
+ self.setParamStatus(reason, Alarm.COMM_ALARM, Severity.MINOR_ALARM)
+ value = self.getParam(reason)
+
+ time.sleep(self.scan_period - (time.time() - start))