]> jspc29.x-matter.uni-frankfurt.de Git - mvd_epics.git/commitdiff
OPUS20: use daemon thread to scan PVs
authorPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Thu, 10 Aug 2017 09:08:31 +0000 (11:08 +0200)
committerPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Thu, 10 Aug 2017 09:08:31 +0000 (11:08 +0200)
LUFFT_OPUS20/lufft_opus20_driver.py
LUFFT_OPUS20/lufft_opus20_pvdb.py

index c5f7588e0a6e96378f5b2a8b3727ca1529d0eddf..c4d5d9d3e8b0168d466d6fc9177683beb969a24f 100644 (file)
@@ -2,11 +2,14 @@
 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()
 
@@ -18,8 +21,15 @@ class Opus20Driver(Driver):
         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,
@@ -27,15 +37,13 @@ class Opus20Driver(Driver):
                 '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))
index 7fb9342858e9d1d955c9d3cb2166c5227598512f..ad81e3236b8e07b36baa28ea68fb64a021a2ffce 100644 (file)
@@ -6,7 +6,7 @@ pvdb = {
         'low'  : 20,
         'high' : 28,
         'hihi' : 30,
-        #'scan' : 1,
+        'scan' :  5,
     },
     'RelativeHumidity' : {
         'prec' : 3,
@@ -15,23 +15,23 @@ pvdb = {
         'low'  : 40,
         'high' : 60,
         'hihi' : 70,
-        #'scan' : 1,
+        'scan' :  5,
     },
     'AbsoluteHumidity' : {
         'prec' : 3,
-        #'scan' : 1,
         'unit' : 'g/m3',
         'low'  :  5,
         'high' : 20,
+        'scan' :  5,
     },
     'Dewpoint' : {
         'prec' : 3,
         'unit' : 'deg C',
-        #'scan' : 1,
         'lolo' : -30,
         'low'  : -10,
         'high' :  16,
         'hihi' :  20,
+        'scan' :   5,
     },
     'BatteryVoltage' : {
         'prec' : 3,
@@ -40,6 +40,6 @@ pvdb = {
         'low'  : 5.3,
         'high' : 6.2,
         'hihi' : 6.5,
-        #'scan' : 1,
+        'scan' :   5,
     },
 }