]> jspc29.x-matter.uni-frankfurt.de Git - mvd_epics.git/commitdiff
LUFFT_OPUS20: first version (based on Py packages PCASpy & opus20)
authorPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Wed, 9 Aug 2017 15:16:02 +0000 (17:16 +0200)
committerPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Wed, 9 Aug 2017 15:16:02 +0000 (17:16 +0200)
LUFFT_OPUS20/lufft_opus20_ioc.py [new file with mode: 0755]

diff --git a/LUFFT_OPUS20/lufft_opus20_ioc.py b/LUFFT_OPUS20/lufft_opus20_ioc.py
new file mode 100755 (executable)
index 0000000..42f134a
--- /dev/null
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+
+from pcaspy import Driver, SimpleServer
+
+from opus20 import Opus20, OPUS20_CHANNEL_SPEC, PickleStore, Opus20ConnectionException
+
+import random
+
+prefix = '{sys}:{sub}:ENVIRON:{esys}:'
+pvdb = {
+    'Temperature' : {
+        'prec' : 3,
+        #'scan' : 1,
+    },
+    'RelativeHumidity' : {
+        'prec' : 3,
+        #'scan' : 1,
+    },
+    'AbsoluteHumidity' : {
+        'prec' : 3,
+        #'scan' : 1,
+    },
+    'Dewpoint' : {
+        'prec' : 3,
+        #'scan' : 1,
+    },
+    'BatteryVoltage' : {
+        'prec' : 3,
+        #'scan' : 1,
+    },
+}
+
+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,
+            }
+            value = self.o20.channel_value(mapping[reason])
+        else:
+            value = self.getParam(reason)
+        return value
+
+if __name__ == '__main__':
+    import argparse
+    parser = argparse.ArgumentParser()
+    parser.add_argument('--opus20-hostname', '-o', help='The hostname of IP address of the OPUS20 logger.', required=True)
+    parser.add_argument('--sys',  required=True, help='The detector system')
+    parser.add_argument('--sub',  required=True, help='The detector sub-system')
+    parser.add_argument('--esys', required=True, help='The environmental sub system')
+    args = parser.parse_args()
+
+    server = SimpleServer()
+
+    prefix = prefix.format(sys=args.sys, sub=args.sub, esys=args.esys)
+
+    server.createPV(prefix, pvdb)
+    driver = Opus20Driver(args.opus20_hostname)
+
+    print("Starting the IOC with the following prefix:")
+    print(prefix)
+    while True:
+        server.process(0.1)