]> jspc29.x-matter.uni-frankfurt.de Git - mvd_epics.git/commitdiff
OPUS20: Split off Opus20Driver into module
authorPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Thu, 10 Aug 2017 07:35:56 +0000 (09:35 +0200)
committerPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Thu, 10 Aug 2017 07:35:56 +0000 (09:35 +0200)
LUFFT_OPUS20/lufft_opus20_driver.py [new file with mode: 0644]
LUFFT_OPUS20/lufft_opus20_ioc.py

diff --git a/LUFFT_OPUS20/lufft_opus20_driver.py b/LUFFT_OPUS20/lufft_opus20_driver.py
new file mode 100644 (file)
index 0000000..c5f7588
--- /dev/null
@@ -0,0 +1,41 @@
+
+from pcaspy import Driver, Alarm, Severity
+from opus20 import Opus20, OPUS20_CHANNEL_SPEC, Opus20ConnectionException
+
+class Opus20Driver(Driver):
+    def __init__(self, hostname, opus20_port=None, opus20_timeout=0.1):
+        self.hostname = hostname
+        self.opus20_port = opus20_port
+        self.opus20_timeout = opus20_timeout
+
+        self.connect_opus20()
+
+        super(Opus20Driver, self).__init__()
+
+    def connect_opus20(self):
+        kwargs = {}
+        if self.opus20_port: kwargs['port'] = self.opus20_port
+        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'):
+            mapping = {
+                'Temperature':       0x0064,
+                'RelativeHumidity':  0x00c8,
+                'AbsoluteHumidity':  0x00cd,
+                '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
+
index 5058bb7f69d4a17f202ac2b33480a54f27263e5b..a40f02521aae0c82201360e3ccfaf9f5a300ac6b 100755 (executable)
@@ -1,51 +1,15 @@
 #!/usr/bin/env python
 
 # external dependencies: PCASpy and opus20
-from pcaspy import Driver, SimpleServer, Alarm, Severity
-from opus20 import Opus20, OPUS20_CHANNEL_SPEC, PickleStore, Opus20ConnectionException
+import pcaspy
+import opus20
 
-# local module containing our PVs:
+# local modules
 from lufft_opus20_pvdb import pvdb
+from lufft_opus20_driver import Opus20Driver
 
 prefix = '{sys}:{sub}:ENVIRON:{esys}:'
 
-class Opus20Driver(Driver):
-    def __init__(self, hostname, opus20_port=None, opus20_timeout=0.1):
-        self.hostname = hostname
-        self.opus20_port = opus20_port
-        self.opus20_timeout = opus20_timeout
-
-        self.connect_opus20()
-
-        super(Opus20Driver, self).__init__()
-
-    def connect_opus20(self):
-        kwargs = {}
-        if self.opus20_port: kwargs['port'] = self.opus20_port
-        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'):
-            mapping = {
-                'Temperature':       0x0064,
-                'RelativeHumidity':  0x00c8,
-                'AbsoluteHumidity': 0x00cd,
-                '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
-
 if __name__ == '__main__':
     import argparse
     parser = argparse.ArgumentParser()
@@ -55,7 +19,7 @@ if __name__ == '__main__':
     parser.add_argument('--esys', required=True, help='The environmental sub system')
     args = parser.parse_args()
 
-    server = SimpleServer()
+    server = pcaspy.SimpleServer()
 
     prefix = prefix.format(sys=args.sys, sub=args.sub, esys=args.esys)