From 89a447abb9128d3669d5fdc32ec06c45d95f63d3 Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Wed, 14 Apr 2021 09:09:10 +0200 Subject: [PATCH] Bugfix: Calculate correct lengths despite IO gaps in incorrect piCtory file --- revpimodio2/device.py | 20 ++++++++------------ revpimodio2/modio.py | 2 +- setup.py | 2 +- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/revpimodio2/device.py b/revpimodio2/device.py index 271d557..12ac290 100644 --- a/revpimodio2/device.py +++ b/revpimodio2/device.py @@ -125,7 +125,7 @@ class Device(object): """ __slots__ = "__my_io_list", "_ba_devdata", "_ba_datacp", \ - "_dict_events", "_filelock", "_length", "_modio", "_name", \ + "_dict_events", "_filelock", "_modio", "_name", \ "_offset", "_position", "_producttype", "_selfupdate", \ "_slc_devoff", "_slc_inp", "_slc_inpoff", "_slc_mem", \ "_slc_memoff", "_slc_out", "_slc_outoff", "_shared_procimg", \ @@ -143,9 +143,10 @@ class Device(object): """ self._modio = parentmodio + self._ba_devdata = bytearray() + self._ba_datacp = bytearray() # Copy for event detection self._dict_events = {} self._filelock = Lock() - self._length = 0 self.__my_io_list = [] self._selfupdate = False self._shared_procimg = parentmodio._shared_procimg @@ -173,7 +174,7 @@ class Device(object): ) # SLCs mit offset berechnen - self._slc_devoff = slice(self._offset, self._offset + self._length) + self._slc_devoff = slice(self._offset, self._offset + self.length) self._slc_inpoff = slice( self._slc_inp.start + self._offset, self._slc_inp.stop + self._offset @@ -187,10 +188,6 @@ class Device(object): self._slc_mem.stop + self._offset ) - # Neues bytearray und Kopie für mainloop anlegen - self._ba_devdata = bytearray(self._length) - self._ba_datacp = bytearray() - # Alle restlichen attribute an Klasse anhängen self.bmk = dict_device.get("bmk", "") self.catalognr = dict_device.get("catalogNr", "") @@ -268,7 +265,7 @@ class Device(object): :return: """ - return self._length + return len(self._ba_devdata) def __str__(self): """ @@ -349,14 +346,13 @@ class Device(object): # IO registrieren self._modio.io._private_register_new_io_object(io_new) - self._length += io_new._length - # Kleinste und größte Speicheradresse ermitteln if io_new._slc_address.start < int_min: int_min = io_new._slc_address.start if io_new._slc_address.stop > int_max: int_max = io_new._slc_address.stop + self._ba_devdata += bytearray(int_max - int_min) return slice(int_min, int_max) def _devconfigure(self): @@ -586,14 +582,14 @@ class Core(Base): self._slc_errorcnt = None self._slc_errorlimit1 = None self._slc_errorlimit2 = None - if self._length == 9: + if self.length == 9: # 9 Byte = Core1.1 self._slc_cycle = slice(1, 2) self._slc_errorcnt = slice(2, 4) self._slc_led = slice(4, 5) self._slc_errorlimit1 = slice(5, 7) self._slc_errorlimit2 = slice(7, 9) - elif self._length == 11: + elif self.length == 11: # 11 Byte = Core1.2 / Connect self._slc_cycle = slice(1, 2) self._slc_errorcnt = slice(2, 4) diff --git a/revpimodio2/modio.py b/revpimodio2/modio.py index 0553dab..c6e6d93 100644 --- a/revpimodio2/modio.py +++ b/revpimodio2/modio.py @@ -305,7 +305,7 @@ class RevPiModIO(object): if self._length < dev_new._offset: self._length = dev_new._offset - self._length += dev_new._length + self._length += dev_new.length # Auf doppelte Namen prüfen, da piCtory dies zulässt if hasattr(self.device, dev_new._name): diff --git a/setup.py b/setup.py index 1f7fb72..d006215 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ setup( license="LGPLv3", name="revpimodio2", - version="2.5.6a", + version="2.5.6b", packages=["revpimodio2"], python_requires="~=3.2",