mirror of
https://github.com/naruxde/revpimodio2.git
synced 2025-11-08 22:03:53 +01:00
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.
This commit is contained in:
@@ -151,8 +151,9 @@ class Device(object):
|
|||||||
self._filelock = Lock()
|
self._filelock = Lock()
|
||||||
self.__my_io_list = []
|
self.__my_io_list = []
|
||||||
self._selfupdate = False
|
self._selfupdate = False
|
||||||
self._shared_procimg = parentmodio._shared_procimg
|
self._shared_procimg = False
|
||||||
self._shared_write = []
|
self._shared_write = []
|
||||||
|
self.shared_procimg(parentmodio._shared_procimg) # Set with register
|
||||||
|
|
||||||
# Wertzuweisung aus dict_device
|
# Wertzuweisung aus dict_device
|
||||||
self._name = dict_device.get("name")
|
self._name = dict_device.get("name")
|
||||||
@@ -522,14 +523,15 @@ class Device(object):
|
|||||||
"""
|
"""
|
||||||
Activate sharing of process image just for this device.
|
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
|
:param activate: Set True to activate process image sharing
|
||||||
"""
|
"""
|
||||||
with self._filelock:
|
with self._filelock:
|
||||||
self._shared_write.clear()
|
self._shared_write.clear()
|
||||||
self._shared_procimg = True if activate else False
|
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:
|
def syncoutputs(self) -> bool:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -532,32 +532,25 @@ class ProcimgWriter(Thread):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
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.seek(0)
|
||||||
fh.readinto(bytesbuff)
|
fh.readinto(bytesbuff)
|
||||||
|
|
||||||
for dev in self._modio._lst_refresh:
|
for dev in self._modio._lst_refresh:
|
||||||
with dev._filelock:
|
with dev._filelock:
|
||||||
if self._modio._monitoring:
|
if self._modio._monitoring or dev._shared_procimg:
|
||||||
# Inputs und Outputs in Puffer
|
# Inputs und Outputs in Puffer
|
||||||
dev._ba_devdata[:] = bytesbuff[dev._slc_devoff]
|
dev._ba_devdata[:] = bytesbuff[dev._slc_devoff]
|
||||||
if self.__eventwork \
|
if self.__eventwork \
|
||||||
and len(dev._dict_events) > 0 \
|
and len(dev._dict_events) > 0 \
|
||||||
and dev._ba_datacp != dev._ba_devdata:
|
and dev._ba_datacp != dev._ba_devdata:
|
||||||
self.__check_change(dev)
|
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:
|
else:
|
||||||
# Inputs in Puffer, Outputs in Prozessabbild
|
# Inputs in Puffer, Outputs in Prozessabbild
|
||||||
dev._ba_devdata[dev._slc_inp] = \
|
dev._ba_devdata[dev._slc_inp] = \
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class RevPiModIO(object):
|
|||||||
__slots__ = "__cleanupfunc", "_autorefresh", "_buffedwrite", "_exit_level", \
|
__slots__ = "__cleanupfunc", "_autorefresh", "_buffedwrite", "_exit_level", \
|
||||||
"_configrsc", "_shared_procimg", "_exit", "_imgwriter", "_ioerror", \
|
"_configrsc", "_shared_procimg", "_exit", "_imgwriter", "_ioerror", \
|
||||||
"_length", "_looprunning", "_lst_devselect", "_lst_refresh", \
|
"_length", "_looprunning", "_lst_devselect", "_lst_refresh", \
|
||||||
|
"_lst_shared", \
|
||||||
"_maxioerrors", "_myfh", "_myfh_lck", "_monitoring", "_procimg", \
|
"_maxioerrors", "_myfh", "_myfh_lck", "_monitoring", "_procimg", \
|
||||||
"_simulator", "_syncoutputs", "_th_mainloop", "_waitexit", \
|
"_simulator", "_syncoutputs", "_th_mainloop", "_waitexit", \
|
||||||
"core", "app", "device", "exitsignal", "io", "summary", "_debug", \
|
"core", "app", "device", "exitsignal", "io", "summary", "_debug", \
|
||||||
@@ -98,6 +99,7 @@ class RevPiModIO(object):
|
|||||||
self._looprunning = False
|
self._looprunning = False
|
||||||
self._lst_devselect = []
|
self._lst_devselect = []
|
||||||
self._lst_refresh = []
|
self._lst_refresh = []
|
||||||
|
self._lst_shared = []
|
||||||
self._maxioerrors = 0
|
self._maxioerrors = 0
|
||||||
self._myfh = None
|
self._myfh = None
|
||||||
self._myfh_lck = Lock()
|
self._myfh_lck = Lock()
|
||||||
|
|||||||
Reference in New Issue
Block a user