From 8999e71d2e8809e9f1877f630cd893d67ee849ac Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Wed, 22 Sep 2021 16:25:12 +0200 Subject: [PATCH] Bugfix with shared process image in cycle loop Shared outputs was written after reading the process image for current cycle. So the values for the outputs was one cycle in the past. --- revpimodio2/device.py | 10 ++++++---- revpimodio2/helper.py | 23 ++++++++--------------- revpimodio2/modio.py | 2 ++ setup.py | 2 +- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/revpimodio2/device.py b/revpimodio2/device.py index c3045c7..018d0fc 100644 --- a/revpimodio2/device.py +++ b/revpimodio2/device.py @@ -151,8 +151,9 @@ class Device(object): self._filelock = Lock() self.__my_io_list = [] self._selfupdate = False - self._shared_procimg = parentmodio._shared_procimg + self._shared_procimg = False self._shared_write = [] + self.shared_procimg(parentmodio._shared_procimg) # Set with register # Wertzuweisung aus dict_device self._name = dict_device.get("name") @@ -522,14 +523,15 @@ class Device(object): """ Activate sharing of process image just for this device. - WARNING: All outputs will set immediately in process image on value - change. That is also inside the cycle loop! - :param activate: Set True to activate process image sharing """ with self._filelock: self._shared_write.clear() self._shared_procimg = True if activate else False + if self._shared_procimg and self not in self._modio._lst_shared: + self._modio._lst_shared.append(self) + elif not self._shared_procimg and self in self._modio._lst_shared: + self._modio._lst_shared.remove(self) def syncoutputs(self) -> bool: """ diff --git a/revpimodio2/helper.py b/revpimodio2/helper.py index b8364c9..1a72e1c 100644 --- a/revpimodio2/helper.py +++ b/revpimodio2/helper.py @@ -532,32 +532,25 @@ class ProcimgWriter(Thread): continue try: + for dev in self._modio._lst_shared: + # Set shared outputs before reading process image + for io in dev._shared_write: + if not io._write_to_procimg(): + raise IOError("error on _write_to_procimg") + dev._shared_write.clear() + fh.seek(0) fh.readinto(bytesbuff) for dev in self._modio._lst_refresh: with dev._filelock: - if self._modio._monitoring: + if self._modio._monitoring or dev._shared_procimg: # Inputs und Outputs in Puffer dev._ba_devdata[:] = bytesbuff[dev._slc_devoff] if self.__eventwork \ and len(dev._dict_events) > 0 \ and dev._ba_datacp != dev._ba_devdata: self.__check_change(dev) - - elif dev._shared_procimg: - for io in dev._shared_write: - if not io._write_to_procimg(): - raise IOError("error on _write_to_procimg") - dev._shared_write.clear() - - # Inputs und Outputs in Puffer - dev._ba_devdata[:] = bytesbuff[dev._slc_devoff] - if self.__eventwork \ - and len(dev._dict_events) > 0 \ - and dev._ba_datacp != dev._ba_devdata: - self.__check_change(dev) - else: # Inputs in Puffer, Outputs in Prozessabbild dev._ba_devdata[dev._slc_inp] = \ diff --git a/revpimodio2/modio.py b/revpimodio2/modio.py index 4473f14..b81e3be 100644 --- a/revpimodio2/modio.py +++ b/revpimodio2/modio.py @@ -36,6 +36,7 @@ class RevPiModIO(object): __slots__ = "__cleanupfunc", "_autorefresh", "_buffedwrite", "_exit_level", \ "_configrsc", "_shared_procimg", "_exit", "_imgwriter", "_ioerror", \ "_length", "_looprunning", "_lst_devselect", "_lst_refresh", \ + "_lst_shared", \ "_maxioerrors", "_myfh", "_myfh_lck", "_monitoring", "_procimg", \ "_simulator", "_syncoutputs", "_th_mainloop", "_waitexit", \ "core", "app", "device", "exitsignal", "io", "summary", "_debug", \ @@ -98,6 +99,7 @@ class RevPiModIO(object): self._looprunning = False self._lst_devselect = [] self._lst_refresh = [] + self._lst_shared = [] self._maxioerrors = 0 self._myfh = None self._myfh_lck = Lock() diff --git a/setup.py b/setup.py index bb2592a..315f198 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ setup( license="LGPLv3", name="revpimodio2", - version="2.5.7d", + version="2.5.7e", packages=["revpimodio2"], python_requires="~=3.2",