fix: Wrong values in buffer with autorefresh and shared_procimg active

When using `autofresh` in combination with `shared_procimg`, the
outputs were written to the process image, but kept with old values
in the local buffer. A query to a set output could therefore display
an incorrect value under certain circumstances.

Closes: #25
Signed-off-by: Sven Sager <akira@narux.de>
This commit is contained in:
2023-08-17 12:08:08 +02:00
parent 1afe16053d
commit 521a0eb589
2 changed files with 13 additions and 9 deletions

View File

@@ -531,20 +531,23 @@ class ProcimgWriter(Thread):
continue
try:
for dev in self._modio._lst_refresh:
if not dev._shared_procimg:
continue
# 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 dev._shared_procimg:
# Set modified outputs one by one
for io in dev._shared_write:
if not io._write_to_procimg():
raise IOError("error on _write_to_procimg")
dev._shared_write.clear()
# Read all device bytes, because it is shared
fh.seek(dev.offset)
bytesbuff[dev._slc_devoff] = \
fh.read(len(dev._ba_devdata))
if self._modio._monitoring or dev._shared_procimg:
# Inputs und Outputs in Puffer
dev._ba_devdata[:] = bytesbuff[dev._slc_devoff]

View File

@@ -594,6 +594,7 @@ class IOBase(object):
return False
else:
# Write one or more bytes to process image
value = bytes(self._parentdevice._ba_devdata[self._slc_address])
with self._parentdevice._modio._myfh_lck:
try: