From 5cb806bbc5a9dbb63118ea7cc8558976aa871491 Mon Sep 17 00:00:00 2001 From: NaruX Date: Wed, 1 Aug 2018 12:43:49 +0200 Subject: [PATCH] =?UTF-8?q?Berechnung=20von=20Bit-IOs=20=C3=BCber=20mehr?= =?UTF-8?q?=20als=202=20Bytes=20angepasst=20wd=20und=20x2out=20Ansteuerung?= =?UTF-8?q?=20verbessert=20Connect=20Funkscheiben=20werden=20als=20Devices?= =?UTF-8?q?=20ignoriert=20Alle=20Cores=20werden=20bei=20syncoutputs=20nich?= =?UTF-8?q?t=20mehr=20mit=20\x00=20vorbelegt=20issubclass=20gegen=20isinst?= =?UTF-8?q?ance=20getauscht=20.exitsignal-Event=20f=C3=BCr=20den=20Benutze?= =?UTF-8?q?r=20hinzugef=C3=BCgt=20Bei=20Core-Klasse=20a*green=20/=20a*red?= =?UTF-8?q?=20als=20echte=20IOs=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- revpimodio2.e4p | 3 ++- revpimodio2/device.py | 49 ++++++++++++++++++++++++++++--------------- revpimodio2/io.py | 6 +++--- revpimodio2/modio.py | 40 ++++++++++++++++++++++++++++++----- revpimodio2/netio.py | 4 ++-- 5 files changed, 74 insertions(+), 28 deletions(-) diff --git a/revpimodio2.e4p b/revpimodio2.e4p index 662e053..75b395d 100644 --- a/revpimodio2.e4p +++ b/revpimodio2.e4p @@ -1,7 +1,7 @@ - + en_US @@ -38,6 +38,7 @@ test/web_startseite.py test/web_rpidaten.py test/web_rpii2c.py + test/test_unit_fh.py diff --git a/revpimodio2/device.py b/revpimodio2/device.py index b7b2d08..a842899 100644 --- a/revpimodio2/device.py +++ b/revpimodio2/device.py @@ -55,7 +55,7 @@ class DeviceList(object): def __delitem__(self, key): """Entfernt Device an angegebener Position. @param key Deviceposition zum entfernen""" - if issubclass(type(key), Device): + if isinstance(key, Device): key = key._position self.__delattr__(key) @@ -91,7 +91,7 @@ class DeviceList(object): """Setzt Attribute nur wenn Device. @param key Attributname @param value Attributobjekt""" - if issubclass(type(value), Device): + if isinstance(value, Device): object.__setattr__(self, key, value) self.__dict_position[value._position] = value elif key == "_DeviceList__dict_position": @@ -178,7 +178,7 @@ class Device(object): """Prueft ob IO auf diesem Device liegt. @param key IO-Name / IO-Bytenummer @return True, wenn IO auf Device vorhanden""" - if issubclass(type(key), IOBase): + if isinstance(key, IOBase): # Umwandlung für key key = key._name @@ -432,18 +432,23 @@ class Core(Device): self._ioerrorlimit1 = lst_io[6] self._ioerrorlimit2 = lst_io[7] - if not (self._modio._monitoring or self._modio._simulator): - # Für RS485 errors defaults laden sollte procimg NULL sein - if self._ioerrorlimit1 is not None: - self._ioerrorlimit1.set_value( - self._ioerrorlimit1._defaultvalue - ) - if self._ioerrorlimit2 is not None: - self._ioerrorlimit2.set_value( - self._ioerrorlimit2._defaultvalue - ) - # RS485 errors schreiben - self._modio.writeprocimg(self) + # Echte IOs erzeugen + self.a1green = IOBase(self, [ + "a1green", 0, 1, self._ioled.address, + False, None, "LED_A1_GREEN", "0" + ], OUT, "little", False) + self.a1red = IOBase(self, [ + "a1red", 0, 1, self._ioled.address, + False, None, "LED_A1_RED", "1" + ], OUT, "little", False) + self.a2green = IOBase(self, [ + "a2green", 0, 1, self._ioled.address, + False, None, "LED_A2_GREEN", "2" + ], OUT, "little", False) + self.a2red = IOBase(self, [ + "a2red", 0, 1, self._ioled.address, + False, None, "LED_A2_RED", "3" + ], OUT, "little", False) def __errorlimit(self, io, errorlimit): """Verwaltet das Lesen und Schreiben der ErrorLimits. @@ -648,10 +653,20 @@ class Connect(Core): """Connect-Klasse vorbereiten.""" super()._devconfigure() + # Echte IOs erzeugen + self.a3green = IOBase(self, [ + "a3green", 0, 1, self._ioled.address, + False, None, "LED_A3_GREEN", "4" + ], OUT, "little", False) + self.a3red = IOBase(self, [ + "a3red", 0, 1, self._ioled.address, + False, None, "LED_A3_RED", "5" + ], OUT, "little", False) + # IO Objekte für WD und X2 in/out erzeugen self.wd = IOBase(self, [ "wd", 0, 1, self._ioled.address, - False, None, "Connect_WatchDog", "6" + False, None, "Connect_WatchDog", "7" ], OUT, "little", False) self.x2in = IOBase(self, [ "x2in", 0, 1, self._iostatusbyte.address, @@ -659,7 +674,7 @@ class Connect(Core): ], INP, "little", False) self.x2out = IOBase(self, [ "x2out", 0, 1, self._ioled.address, - False, None, "Connect_X2_OUT", "7" + False, None, "Connect_X2_OUT", "6" ], OUT, "little", False) def _get_leda3(self): diff --git a/revpimodio2/io.py b/revpimodio2/io.py index abdbbbf..b62b04e 100644 --- a/revpimodio2/io.py +++ b/revpimodio2/io.py @@ -191,7 +191,7 @@ class IOList(object): def _private_register_new_io_object(self, new_io): """Registriert neues IO Objekt unabhaenging von __setattr__. @param new_io Neues IO Objekt""" - if issubclass(type(new_io), IOBase): + if isinstance(new_io, IOBase): if hasattr(self, new_io._name): raise AttributeError( "attribute {} already exists - can not set io".format( @@ -317,7 +317,7 @@ class IOBase(object): else: # Höhere Bits als 7 auf nächste Bytes umbrechen - int_startaddress += int((int(valuelist[7]) % 16) / 8) + int_startaddress += int(int(valuelist[7]) / 8) self._slc_address = slice( int_startaddress, int_startaddress + 1 ) @@ -519,7 +519,7 @@ class IOBase(object): >Python3 struct """ - if not issubclass(type(self._parentdevice), Gateway): + if not isinstance(self._parentdevice, Gateway): raise RuntimeError( "this function can be used for ios on gatway or virtual " "devices only" diff --git a/revpimodio2/modio.py b/revpimodio2/modio.py index 15472a7..a367f77 100644 --- a/revpimodio2/modio.py +++ b/revpimodio2/modio.py @@ -79,6 +79,9 @@ class RevPiModIO(object): self.io = None self.summary = None + # Event für Benutzeraktionen + self.exitsignal = Event() + # Nur Konfigurieren, wenn nicht vererbt if type(self) == RevPiModIO: self._configure(self.get_jconfigrsc()) @@ -177,6 +180,9 @@ class RevPiModIO(object): dev_new = devicemodule.Gateway( self, device, simulator=self._simulator ) + elif device["type"] == "RIGHT": + # Connectdevice + dev_new = None else: # Device-Type nicht gefunden warnings.warn( @@ -216,6 +222,20 @@ class RevPiModIO(object): if self._syncoutputs: self.syncoutputs() + # Für RS485 errors am core defaults laden sollte procimg NULL sein + if not (self.core is None or self._monitoring or self._simulator): + if self.core._ioerrorlimit1 is not None: + self.core._ioerrorlimit1.set_value( + self.core._ioerrorlimit1._defaultvalue + ) + if self.core._ioerrorlimit2 is not None: + self.core._ioerrorlimit2.set_value( + self.core._ioerrorlimit2._defaultvalue + ) + + # RS485 errors schreiben + self.writeprocimg(self.core) + # Optional ins autorefresh aufnehmen if self._autorefresh: self.autorefresh_all() @@ -374,6 +394,9 @@ class RevPiModIO(object): # Zeitänderung in _imgwriter neuladen self._imgwriter.newdata.clear() + # Benutzerevent + self.exitsignal.clear() + # Cycleloop starten self._exit.clear() self._looprunning = True @@ -423,6 +446,10 @@ class RevPiModIO(object): wird dann gestoppt und das Programm kann sauber beendet werden. @param full Entfernt auch alle Devices aus autorefresh""" + + # Benutzerevent + self.exitsignal.set() + self._exit.set() self._waitexit.set() @@ -544,6 +571,9 @@ class RevPiModIO(object): self._th_mainloop.start() return + # Benutzerevent + self.exitsignal.clear() + # Event säubern vor Eintritt in Mainloop self._exit.clear() self._looprunning = True @@ -592,7 +622,7 @@ class RevPiModIO(object): if device is None: mylist = self.device else: - dev = device if issubclass(type(device), devicemodule.Device) \ + dev = device if isinstance(device, devicemodule.Device) \ else self.device.__getitem__(device) if dev._selfupdate: @@ -647,7 +677,7 @@ class RevPiModIO(object): if device is None: mylist = self.device else: - dev = device if issubclass(type(device), devicemodule.Device) \ + dev = device if isinstance(device, devicemodule.Device) \ else self.device.__getitem__(device) mylist = [dev] @@ -667,12 +697,12 @@ class RevPiModIO(object): if device is None: mylist = self.device else: - dev = device if issubclass(type(device), devicemodule.Device) \ + dev = device if isinstance(device, devicemodule.Device) \ else self.device.__getitem__(device) if dev._selfupdate: raise RuntimeError( - "can not sync process image, while device '{}|{}'" + "can not sync outputs, while device '{}|{}'" "is in autorefresh mode".format(dev._position, dev._name) ) mylist = [dev] @@ -710,7 +740,7 @@ class RevPiModIO(object): if device is None: mylist = self.device else: - dev = device if issubclass(type(device), devicemodule.Device) \ + dev = device if isinstance(device, devicemodule.Device) \ else self.device.__getitem__(device) if dev._selfupdate: diff --git a/revpimodio2/netio.py b/revpimodio2/netio.py index 2d8b7b3..f2c1981 100644 --- a/revpimodio2/netio.py +++ b/revpimodio2/netio.py @@ -466,7 +466,7 @@ class RevPiNetIO(_RevPiModIO): if device is None: self._myfh.clear_dirtybytes() else: - dev = device if issubclass(type(device), Device) \ + dev = device if isinstance(device, Device) \ else self.device.__getitem__(device) mylist = [dev] @@ -486,7 +486,7 @@ class RevPiNetIO(_RevPiModIO): if device is None: mylist = self.device else: - dev = device if issubclass(type(device), Device) \ + dev = device if isinstance(device, Device) \ else self.device.__getitem__(device) mylist = [dev]