From 0edfb4ef85fe3c668d075394863b56ea911efb90 Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Wed, 28 Jul 2021 07:38:34 +0200 Subject: [PATCH] Check device offsets in piCtory file and ignore IOs with wrong offsets The modbus 150 Device has a memory gap and piCtory does not calculate the right offset of the following device - We will warn the user. --- revpimodio2/device.py | 29 ++++++++++++++++++++++------- revpimodio2/modio.py | 2 +- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/revpimodio2/device.py b/revpimodio2/device.py index e61dacc..37dca3d 100644 --- a/revpimodio2/device.py +++ b/revpimodio2/device.py @@ -1,13 +1,13 @@ # -*- coding: utf-8 -*- """Modul fuer die Verwaltung der Devices.""" +__author__ = "Sven Sager" +__copyright__ = "Copyright (C) 2021 Sven Sager" +__license__ = "LGPLv3" + +import warnings from threading import Event, Lock, Thread from .helper import ProcimgWriter - -__author__ = "Sven Sager" -__copyright__ = "Copyright (C) 2020 Sven Sager" -__license__ = "LGPLv3" - from .pictory import ProductType @@ -160,6 +160,14 @@ class Device(object): self._position = int(dict_device.get("position")) self._producttype = int(dict_device.get("productType")) + # Offset-Check for broken piCtory configuration + if self._offset != parentmodio.length: + warnings.warn( + "Device offset ERROR in piCtory configuration! Offset of '{0}' " + "must be {1} but is {2} - Overlapping devices overwrite the " + "same memory, which has unpredictable effects!!!" + "".format(self._name, parentmodio.length, self._offset) + ) # IOM-Objekte erstellen und Adressen in SLCs speichern if simulator: self._slc_inp = self._buildio( @@ -345,8 +353,15 @@ class Device(object): self._producttype == ProductType.AIO ) - # IO registrieren - self._modio.io._private_register_new_io_object(io_new) + if io_new.address < self._modio.length: + warnings.warn( + "IO {0} is not in the device offset and will be ignored" + "".format(io_new.name), + Warning + ) + else: + # IO registrieren + self._modio.io._private_register_new_io_object(io_new) # Kleinste und größte Speicheradresse ermitteln if io_new._slc_address.start < int_min: diff --git a/revpimodio2/modio.py b/revpimodio2/modio.py index 4b5423b..d9a1c5b 100644 --- a/revpimodio2/modio.py +++ b/revpimodio2/modio.py @@ -227,7 +227,7 @@ class RevPiModIO(object): # Devices initialisieren err_names = [] - for device in sorted(lst_devices, key=lambda x: x["position"]): + for device in sorted(lst_devices, key=lambda x: x["offset"]): # VDev alter piCtory Versionen auf Kunbus-Standard ändern if device["position"] == "adap.":