From 230f442ce877366db582ac84e9c08e3249692999 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Tue, 6 Apr 2021 14:36:55 +0200 Subject: [PATCH] added classes for PV/Image --- morioc/channels.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 morioc/channels.py diff --git a/morioc/channels.py b/morioc/channels.py new file mode 100644 index 0000000..193502e --- /dev/null +++ b/morioc/channels.py @@ -0,0 +1,51 @@ +from types import SimpleNamespace + + +class PV: + + def __init__(self, ioc, name): + self.ioc = ioc + self.name = name + + def get(self): + name = self.name + return self.ioc.get(name) + + def put(self, value): + name = self.name + data = {name: value} + self.ioc.serve(**data) + + + +class Image: + + def __init__(self, ioc, name): + self.ioc = ioc + self.name = name + self.pvs = SimpleNamespace( + fpicture = PV(ioc, name + ":FPICTURE"), + width = PV(ioc, name + ":WIDTH"), + height = PV(ioc, name + ":HEIGHT") + ) + + + def get(self): + fpicture = self.pvs.fpicture.get() + width = self.pvs.width.get() + height = self.pvs.height.get() + + fpicture.shape = (width, height) + return fpicture + + + def put(self, img): + width, height = img.shape + fpicture = img.ravel() + + self.pvs.fpicture.put(fpicture) + self.pvs.width.put(width) + self.pvs.height.put(height) + + +