From 40d7c132a5bcbd28ef8723ceef8aefc9bc56cc3c Mon Sep 17 00:00:00 2001 From: NaruX Date: Tue, 23 Jul 2019 09:09:34 +0200 Subject: [PATCH 1/5] =?UTF-8?q?Selected=20/=20Driver=20gegen=20nun=20einen?= =?UTF-8?q?=20DeviceNotFoundError=20aus,=20wenn=20nicht=20vorhanden=20debu?= =?UTF-8?q?g=20und=20replace=5Fio=5Ffile=20=C3=BCber=20Namen=20abrufbar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/revpimodio2.__init__.html | 36 ++++++++++++++++++++++++++++++++++- doc/revpimodio2.modio.html | 30 ++++++++++++++++++++++++++++- eric-revpimodio2.api | 4 ++++ eric-revpimodio2.bas | 1 + revpimodio2/__init__.py | 7 +++++++ revpimodio2/modio.py | 26 +++++++++++++++++-------- revpimodio2/netio.py | 10 +++++----- 7 files changed, 99 insertions(+), 15 deletions(-) diff --git a/doc/revpimodio2.__init__.html b/doc/revpimodio2.__init__.html index 6441740..1554d3c 100644 --- a/doc/revpimodio2.__init__.html +++ b/doc/revpimodio2.__init__.html @@ -27,7 +27,10 @@ Global Attributes

Classes

- + + + +
None
DeviceNotFoundErrorFehler wenn ein Device nicht gefunden wird.

Functions

@@ -41,6 +44,37 @@ Functions

+ +

DeviceNotFoundError

+

+Fehler wenn ein Device nicht gefunden wird. +

+

+Derived from

+Exception +

+Class Attributes

+ + +
None
+

+Class Methods

+ + +
None
+

+Methods

+ + +
None
+

+Static Methods

+ + +
None
+ +
Up
+

acheck

acheck(check_type, **kwargs) diff --git a/doc/revpimodio2.modio.html b/doc/revpimodio2.modio.html index 2841f45..343aee3 100644 --- a/doc/revpimodio2.modio.html +++ b/doc/revpimodio2.modio.html @@ -54,7 +54,7 @@ object

Class Attributes

- +
__slots__
configrsc
cycletime
ioerrors
length
maxioerrors
monitoring
procimg
simulator
__slots__
configrsc
cycletime
debug
ioerrors
length
maxioerrors
monitoring
procimg
replace_io_file
simulator

Class Methods

@@ -89,6 +89,9 @@ Methods _get_cycletime Gibt Aktualisierungsrate in ms der Prozessabbildsynchronisierung aus. +_get_debug +Gibt Status des Debugflags zurueck. + _get_ioerrors Getter function. @@ -104,6 +107,9 @@ Methods _get_procimg Getter function. +_get_replace_io_file +Gibt Pfad zur verwendeten replace IO Datei aus. + _get_simulator Getter function. @@ -260,6 +266,17 @@ Gibt Aktualisierungsrate in ms der Prozessabbildsynchronisierung aus.
Millisekunden
+ +

+RevPiModIO._get_debug

+_get_debug() +

+Gibt Status des Debugflags zurueck. +

+
Returns:
+
+Status des Debugflags +

RevPiModIO._get_ioerrors

@@ -315,6 +332,17 @@ Getter function.
Pfad des verwendeten Prozessabbilds
+ +

+RevPiModIO._get_replace_io_file

+_get_replace_io_file() +

+Gibt Pfad zur verwendeten replace IO Datei aus. +

+
Returns:
+
+Pfad zur replace IO Datei +

RevPiModIO._get_simulator

diff --git a/eric-revpimodio2.api b/eric-revpimodio2.api index 270362a..889636a 100644 --- a/eric-revpimodio2.api +++ b/eric-revpimodio2.api @@ -145,11 +145,13 @@ revpimodio2.modio.RevPiModIO._configure_replace_io?5() revpimodio2.modio.RevPiModIO._create_myfh?5() revpimodio2.modio.RevPiModIO._get_configrsc?5() revpimodio2.modio.RevPiModIO._get_cycletime?5() +revpimodio2.modio.RevPiModIO._get_debug?5() revpimodio2.modio.RevPiModIO._get_ioerrors?5() revpimodio2.modio.RevPiModIO._get_length?5() revpimodio2.modio.RevPiModIO._get_maxioerrors?5() revpimodio2.modio.RevPiModIO._get_monitoring?5() revpimodio2.modio.RevPiModIO._get_procimg?5() +revpimodio2.modio.RevPiModIO._get_replace_io_file?5() revpimodio2.modio.RevPiModIO._get_simulator?5() revpimodio2.modio.RevPiModIO._gotioerror?5(action, e=None) revpimodio2.modio.RevPiModIO._set_cycletime?5(milliseconds) @@ -159,6 +161,7 @@ revpimodio2.modio.RevPiModIO.cleanup?4() revpimodio2.modio.RevPiModIO.configrsc?7 revpimodio2.modio.RevPiModIO.cycleloop?4(func, cycletime=50) revpimodio2.modio.RevPiModIO.cycletime?7 +revpimodio2.modio.RevPiModIO.debug?7 revpimodio2.modio.RevPiModIO.exit?4(full=True) revpimodio2.modio.RevPiModIO.export_replaced_ios?4(filename) revpimodio2.modio.RevPiModIO.get_jconfigrsc?4() @@ -170,6 +173,7 @@ revpimodio2.modio.RevPiModIO.maxioerrors?7 revpimodio2.modio.RevPiModIO.monitoring?7 revpimodio2.modio.RevPiModIO.procimg?7 revpimodio2.modio.RevPiModIO.readprocimg?4(device=None) +revpimodio2.modio.RevPiModIO.replace_io_file?7 revpimodio2.modio.RevPiModIO.resetioerrors?4() revpimodio2.modio.RevPiModIO.setdefaultvalues?4(device=None) revpimodio2.modio.RevPiModIO.simulator?7 diff --git a/eric-revpimodio2.bas b/eric-revpimodio2.bas index 56a0c5e..3eda7c3 100644 --- a/eric-revpimodio2.bas +++ b/eric-revpimodio2.bas @@ -1,6 +1,7 @@ Base Device Connect Core Core Base +DeviceNotFoundError Exception DioModule Device EventCallback Thread Gateway Device diff --git a/revpimodio2/__init__.py b/revpimodio2/__init__.py index 26c7636..3b8c1e2 100644 --- a/revpimodio2/__init__.py +++ b/revpimodio2/__init__.py @@ -38,6 +38,13 @@ MEM = 302 warnings.simplefilter(action="always") +class DeviceNotFoundError(Exception): + + """Fehler wenn ein Device nicht gefunden wird.""" + + pass + + def acheck(check_type, **kwargs): """Check type of given arguments. diff --git a/revpimodio2/modio.py b/revpimodio2/modio.py index 589d297..d08544c 100644 --- a/revpimodio2/modio.py +++ b/revpimodio2/modio.py @@ -10,7 +10,7 @@ from json import load as jload from multiprocessing import cpu_count from os import access, F_OK, R_OK from queue import Empty -from revpimodio2 import acheck +from revpimodio2 import acheck, DeviceNotFoundError from signal import signal, SIG_DFL, SIGINT, SIGTERM from threading import Thread, Event, Lock from timeit import default_timer @@ -368,9 +368,7 @@ class RevPiModIO(object): except Exception as e: raise RuntimeError( "replace_io_file: can not replace '{0}' with '{1}' " - "| RevPiModIO message: {2}".format( - parentio, io, e - ) + "| RevPiModIO message: {2}".format(parentio, io, e) ) def _create_myfh(self): @@ -389,6 +387,11 @@ class RevPiModIO(object): @return Millisekunden""" return self._imgwriter.refresh + def _get_debug(self): + """Gibt Status des Debugflags zurueck. + @return Status des Debugflags""" + return self._debug + def _get_ioerrors(self): """Getter function. @return Aktuelle Anzahl gezaehlter Fehler""" @@ -417,6 +420,11 @@ class RevPiModIO(object): @return Pfad des verwendeten Prozessabbilds""" return self._procimg + def _get_replace_io_file(self): + """Gibt Pfad zur verwendeten replace IO Datei aus. + @return Pfad zur replace IO Datei""" + return self._replace_io_file + def _get_simulator(self): """Getter function. @return True, wenn als Simulator gestartet""" @@ -992,6 +1000,7 @@ class RevPiModIO(object): return workokay + debug = property(_get_debug) configrsc = property(_get_configrsc) cycletime = property(_get_cycletime, _set_cycletime) ioerrors = property(_get_ioerrors) @@ -999,6 +1008,7 @@ class RevPiModIO(object): maxioerrors = property(_get_maxioerrors, _set_maxioerrors) monitoring = property(_get_monitoring) procimg = property(_get_procimg) + replace_io_file = property(_get_replace_io_file) simulator = property(_get_simulator) @@ -1052,20 +1062,20 @@ class RevPiModIOSelected(RevPiModIO): if len(self.device) == 0: if type(self) == RevPiModIODriver: - raise RuntimeError( + raise DeviceNotFoundError( "could not find any given VIRTUAL devices in config" ) else: - raise RuntimeError( + raise DeviceNotFoundError( "could not find any given devices in config" ) elif len(self.device) != len(self._lst_devselect): if type(self) == RevPiModIODriver: - raise RuntimeError( + raise DeviceNotFoundError( "could not find all given VIRTUAL devices in config" ) else: - raise RuntimeError( + raise DeviceNotFoundError( "could not find all given devices in config" ) diff --git a/revpimodio2/netio.py b/revpimodio2/netio.py index d8c899f..8db2607 100644 --- a/revpimodio2/netio.py +++ b/revpimodio2/netio.py @@ -3,11 +3,11 @@ __author__ = "Sven Sager" __copyright__ = "Copyright (C) 2018 Sven Sager" __license__ = "LGPLv3" - import socket import warnings from json import loads as jloads from re import compile +from revpimodio2 import DeviceNotFoundError from threading import Thread, Event, Lock from .device import Device @@ -696,20 +696,20 @@ class RevPiNetIOSelected(RevPiNetIO): if len(self.device) == 0: if type(self) == RevPiNetIODriver: - raise RuntimeError( + raise DeviceNotFoundError( "could not find any given VIRTUAL devices in config" ) else: - raise RuntimeError( + raise DeviceNotFoundError( "could not find any given devices in config" ) elif len(self.device) != len(self._lst_devselect): if type(self) == RevPiNetIODriver: - raise RuntimeError( + raise DeviceNotFoundError( "could not find all given VIRTUAL devices in config" ) else: - raise RuntimeError( + raise DeviceNotFoundError( "could not find all given devices in config" ) From 23f9095d5cacbfde44ddbcbc19952012f39c108d Mon Sep 17 00:00:00 2001 From: NaruX Date: Tue, 23 Jul 2019 09:59:24 +0200 Subject: [PATCH 2/5] Indexzugriff auf IOs eines Devices --- doc/revpimodio2.device.html | 32 ++++++++++++++++++++++++++++++-- eric-revpimodio2.api | 1 + revpimodio2/device.py | 18 ++++++++++++++++-- revpimodio2/io.py | 8 ++++++-- 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/doc/revpimodio2.device.html b/doc/revpimodio2.device.html index d88c158..0753f3b 100644 --- a/doc/revpimodio2.device.html +++ b/doc/revpimodio2.device.html @@ -556,6 +556,9 @@ Methods __getioiter Gibt mit allen IOs zurueck. +__getitem__ +Gibt IO an angegebener Stelle zurueck. + __int__ Gibt die Positon im RevPi Bus zurueck. @@ -580,6 +583,9 @@ Methods _get_producttype Gibt den Produkttypen des device zurueck. +_update_my_io_list +Erzeugt eine neue IO Liste fuer schnellen Zugriff. + autorefresh Registriert dieses Device fuer die automatische Synchronisierung. @@ -676,6 +682,22 @@ Filter fuer 'Export' Flag in piCtory
IOs als Iterator
+ +

+Device.__getitem__

+__getitem__(key) +

+Gibt IO an angegebener Stelle zurueck. +

+
key
+
+Index des IOs auf dem device als +
+
+
Returns:
+
+Gefundenes IO-Objekt +

Device.__int__

@@ -767,7 +789,13 @@ Gibt den Produkttypen des device zurueck.
Deviceprodukttyp
- + +

+Device._update_my_io_list

+_update_my_io_list() +

+Erzeugt eine neue IO Liste fuer schnellen Zugriff. +

Device.autorefresh

autorefresh(activate=True) @@ -1049,7 +1077,7 @@ DeviceList.__iter__ Gibt Iterator aller Devices zurueck.

Die Reihenfolge ist nach Position im Prozessabbild sortiert und nicht - nach Position (Dies entspricht der Positionierung aus piCtory)! + nach Positionsnummer (Dies entspricht der Positionierung aus piCtory)!

Returns:
diff --git a/eric-revpimodio2.api b/eric-revpimodio2.api index 889636a..a6a10cb 100644 --- a/eric-revpimodio2.api +++ b/eric-revpimodio2.api @@ -43,6 +43,7 @@ revpimodio2.device.Device._buildio?5(dict_io, iotype) revpimodio2.device.Device._devconfigure?5() revpimodio2.device.Device._get_offset?5() revpimodio2.device.Device._get_producttype?5() +revpimodio2.device.Device._update_my_io_list?5() revpimodio2.device.Device.autorefresh?4(activate=True) revpimodio2.device.Device.get_allios?4(export=None) revpimodio2.device.Device.get_inputs?4(export=None) diff --git a/revpimodio2/device.py b/revpimodio2/device.py index 0941f29..a668c62 100644 --- a/revpimodio2/device.py +++ b/revpimodio2/device.py @@ -72,7 +72,7 @@ class DeviceList(object): """Gibt Iterator aller Devices zurueck. Die Reihenfolge ist nach Position im Prozessabbild sortiert und nicht - nach Position (Dies entspricht der Positionierung aus piCtory)! + nach Positionsnummer (Dies entspricht der Positionierung aus piCtory)! @return aller Devices""" for dev in sorted( @@ -106,7 +106,7 @@ class Device(object): """ - __slots__ = "_ba_devdata", "_ba_datacp", \ + __slots__ = "__my_io_list", "_ba_devdata", "_ba_datacp", \ "_dict_events", "_filelock", "_length", "_modio", "_name", "_offset", \ "_position", "_producttype", "_selfupdate", "_slc_devoff", \ "_slc_inp", "_slc_inpoff", "_slc_mem", "_slc_memoff", \ @@ -126,6 +126,7 @@ class Device(object): self._dict_events = {} self._filelock = Lock() self._length = 0 + self.__my_io_list = [] self._selfupdate = False # Wertzuweisung aus dict_device @@ -182,6 +183,9 @@ class Device(object): # Spezielle Konfiguration von abgeleiteten Klassen durchführen self._devconfigure() + # IO Liste aktualisieren für schnellen Indexzugriff + self._update_my_io_list() + def __bytes__(self): """Gibt alle Daten des Devices als zurueck. @return Devicedaten als """ @@ -205,6 +209,12 @@ class Device(object): return key in self._modio.io \ and getattr(self._modio.io, key)._parentdevice == self + def __getitem__(self, key): + """Gibt IO an angegebener Stelle zurueck. + @param key Index des IOs auf dem device als + @return Gefundenes IO-Objekt""" + return self.__my_io_list[key] + def __int__(self): """Gibt die Positon im RevPi Bus zurueck. @return Positionsnummer""" @@ -312,6 +322,10 @@ class Device(object): @return Deviceprodukttyp""" return self._producttype + def _update_my_io_list(self): + """Erzeugt eine neue IO Liste fuer schnellen Zugriff.""" + self.__my_io_list = list(self.__iter__()) + def autorefresh(self, activate=True): """Registriert dieses Device fuer die automatische Synchronisierung. @param activate Default True fuegt Device zur Synchronisierung hinzu""" diff --git a/revpimodio2/io.py b/revpimodio2/io.py index ce3ba20..e274894 100644 --- a/revpimodio2/io.py +++ b/revpimodio2/io.py @@ -68,6 +68,7 @@ class IOList(object): self.__dict_iobyte[io_del.address] = [] object.__delattr__(self, key) + io_del._parentdevice._update_my_io_list() def __getattr__(self, key): """Verwaltet geloeschte IOs (Attribute, die nicht existieren). @@ -125,10 +126,10 @@ class IOList(object): def __setattr__(self, key, value): """Verbietet aus Leistungsguenden das direkte Setzen von Attributen.""" - if key in [ + if key in ( "_IOList__dict_iobyte", "_IOList__dict_iorefname" - ]: + ): object.__setattr__(self, key, value) else: raise AttributeError( @@ -221,6 +222,9 @@ class IOList(object): None, None, None, None, None, None, None, None ] self.__dict_iobyte[new_io.address][new_io._bitaddress] = new_io + + if type(new_io) is StructIO: + new_io._parentdevice._update_my_io_list() else: raise TypeError("io must be or sub class") From fc28e028be7eee6717b8fb7b355358cd837966d7 Mon Sep 17 00:00:00 2001 From: NaruX Date: Thu, 25 Jul 2019 16:44:59 +0200 Subject: [PATCH 3/5] =?UTF-8?q?Bei=20.reg=5Fevent=20Parameter=20prefire=20?= =?UTF-8?q?eingef=C3=BCgt=20um=20Event=20bei=20Eintritt=20in=20mainloop=20?= =?UTF-8?q?mit=20aktuellem=20Wert=20auszul=C3=B6sen.=20Im=20Helper=20werde?= =?UTF-8?q?n=20Event-Queues=20nur=20beim=20deaktiveren=20geleert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/revpimodio2.io.html | 12 +++++++++--- eric-revpimodio2.api | 4 ++-- revpimodio2/helper.py | 8 +++++--- revpimodio2/io.py | 24 ++++++++++++++++-------- revpimodio2/modio.py | 22 ++++++++++++++++++++-- 5 files changed, 52 insertions(+), 18 deletions(-) diff --git a/doc/revpimodio2.io.html b/doc/revpimodio2.io.html index 0637b6f..a83171d 100644 --- a/doc/revpimodio2.io.html +++ b/doc/revpimodio2.io.html @@ -241,7 +241,7 @@ Bytelaenge des IO - 0 bei BITs

IOBase.__reg_xevent

-__reg_xevent(func, delay, edge, as_thread, overwrite) +__reg_xevent(func, delay, edge, as_thread, overwrite, prefire)

Verwaltet reg_event und reg_timerevent.

@@ -260,6 +260,9 @@ Bei True, Funktion als EventCallback-Thread ausfuehren
overwrite
Wenn True, wird Event bei ueberschrieben +
prefire
+
+Ausloesen mit aktuellem Wert, wenn mainloop startet

@@ -330,7 +333,7 @@ IO-Wert als oder

IOBase.reg_event

-reg_event(func, delay=0, edge=BOTH, as_thread=False) +reg_event(func, delay=0, edge=BOTH, as_thread=False, prefire=False)

Registriert fuer IO ein Event bei der Eventueberwachung.

@@ -353,6 +356,9 @@ Ausfuehren bei RISING, FALLING or BOTH Wertaenderung

as_thread
Bei True, Funktion als EventCallback-Thread ausfuehren +
prefire
+
+Ausloesen mit aktuellem Wert, wenn mainloop startet

@@ -502,7 +508,7 @@ Static Methods

IOEvent (Constructor)

-IOEvent(func, edge, as_thread, delay, overwrite) +IOEvent(func, edge, as_thread, delay, overwrite, prefire)

Init IOEvent class.

diff --git a/eric-revpimodio2.api b/eric-revpimodio2.api index 889636a..25c1302 100644 --- a/eric-revpimodio2.api +++ b/eric-revpimodio2.api @@ -106,7 +106,7 @@ revpimodio2.io.IOBase.get_defaultvalue?4() revpimodio2.io.IOBase.get_value?4() revpimodio2.io.IOBase.length?7 revpimodio2.io.IOBase.name?7 -revpimodio2.io.IOBase.reg_event?4(func, delay=0, edge=BOTH, as_thread=False) +revpimodio2.io.IOBase.reg_event?4(func, delay=0, edge=BOTH, as_thread=False, prefire=False) revpimodio2.io.IOBase.reg_timerevent?4(func, delay, edge=BOTH, as_thread=False) revpimodio2.io.IOBase.set_value?4(value) revpimodio2.io.IOBase.type?7 @@ -114,7 +114,7 @@ revpimodio2.io.IOBase.unreg_event?4(func=None, edge=None) revpimodio2.io.IOBase.value?7 revpimodio2.io.IOBase.wait?4(edge=BOTH, exitevent=None, okvalue=None, timeout=0) revpimodio2.io.IOBase?1(parentdevice, valuelist, iotype, byteorder, signed) -revpimodio2.io.IOEvent?1(func, edge, as_thread, delay, overwrite) +revpimodio2.io.IOEvent?1(func, edge, as_thread, delay, overwrite, prefire) revpimodio2.io.IOList._private_register_new_io_object?5(new_io) revpimodio2.io.IOList?1() revpimodio2.io.IntIO._get_signed?5() diff --git a/revpimodio2/helper.py b/revpimodio2/helper.py index 37af3cb..fb5e2ce 100644 --- a/revpimodio2/helper.py +++ b/revpimodio2/helper.py @@ -413,9 +413,11 @@ class ProcimgWriter(Thread): if self.__eventwork != value: with self.lck_refresh: self.__eventwork = value - self.__eventqth = queue.Queue() - self._eventq = queue.Queue() - self.__dict_delay = {} + if not value: + # Nur leeren beim deaktivieren + self.__eventqth = queue.Queue() + self._eventq = queue.Queue() + self.__dict_delay = {} # Threadmanagement if value and not self.__eventth.is_alive(): diff --git a/revpimodio2/io.py b/revpimodio2/io.py index ce3ba20..eb5b21b 100644 --- a/revpimodio2/io.py +++ b/revpimodio2/io.py @@ -21,15 +21,16 @@ class IOEvent(object): """Basisklasse fuer IO-Events.""" - __slots__ = "as_thread", "delay", "edge", "func", "overwrite" + __slots__ = "as_thread", "delay", "edge", "func", "overwrite", "prefire" - def __init__(self, func, edge, as_thread, delay, overwrite): + def __init__(self, func, edge, as_thread, delay, overwrite, prefire): """Init IOEvent class.""" self.as_thread = as_thread self.delay = delay self.edge = edge self.func = func self.overwrite = overwrite + self.prefire = prefire class IOList(object): @@ -368,7 +369,7 @@ class IOBase(object): @return Namen des IOs""" return self._name - def __reg_xevent(self, func, delay, edge, as_thread, overwrite): + def __reg_xevent(self, func, delay, edge, as_thread, overwrite, prefire): """Verwaltet reg_event und reg_timerevent. @param func Funktion die bei Aenderung aufgerufen werden soll @@ -376,6 +377,7 @@ class IOBase(object): @param edge Ausfuehren bei RISING, FALLING or BOTH Wertaenderung @param as_thread Bei True, Funktion als EventCallback-Thread ausfuehren @param overwrite Wenn True, wird Event bei ueberschrieben + @param prefire Ausloesen mit aktuellem Wert, wenn mainloop startet """ # Prüfen ob Funktion callable ist @@ -391,11 +393,15 @@ class IOBase(object): raise ValueError( "parameter 'edge' can be used with bit io objects only" ) + if prefire and self._parentdevice._modio._looprunning: + raise RuntimeError( + "prefire can not be used if mainloop is running" + ) if self not in self._parentdevice._dict_events: with self._parentdevice._filelock: self._parentdevice._dict_events[self] = \ - [IOEvent(func, edge, as_thread, delay, overwrite)] + [IOEvent(func, edge, as_thread, delay, overwrite, prefire)] else: # Prüfen ob Funktion schon registriert ist for regfunc in self._parentdevice._dict_events[self]: @@ -429,7 +435,7 @@ class IOBase(object): # Eventfunktion einfügen with self._parentdevice._filelock: self._parentdevice._dict_events[self].append( - IOEvent(func, edge, as_thread, delay, overwrite) + IOEvent(func, edge, as_thread, delay, overwrite, prefire) ) def _get_address(self): @@ -464,7 +470,8 @@ class IOBase(object): else: return bytes(self._parentdevice._ba_devdata[self._slc_address]) - def reg_event(self, func, delay=0, edge=BOTH, as_thread=False): + def reg_event( + self, func, delay=0, edge=BOTH, as_thread=False, prefire=False): """Registriert fuer IO ein Event bei der Eventueberwachung. Die uebergebene Funktion wird ausgefuehrt, wenn sich der IO Wert @@ -478,9 +485,10 @@ class IOBase(object): @param delay Verzoegerung in ms zum Ausloesen wenn Wert gleich bleibt @param edge Ausfuehren bei RISING, FALLING or BOTH Wertaenderung @param as_thread Bei True, Funktion als EventCallback-Thread ausfuehren + @param prefire Ausloesen mit aktuellem Wert, wenn mainloop startet """ - self.__reg_xevent(func, delay, edge, as_thread, True) + self.__reg_xevent(func, delay, edge, as_thread, True, prefire) def reg_timerevent(self, func, delay, edge=BOTH, as_thread=False): """Registriert fuer IO einen Timer, welcher nach delay func ausfuehrt. @@ -501,7 +509,7 @@ class IOBase(object): @param as_thread Bei True, Funktion als EventCallback-Thread ausfuehren """ - self.__reg_xevent(func, delay, edge, as_thread, False) + self.__reg_xevent(func, delay, edge, as_thread, False, False) def set_value(self, value): """Setzt den Wert des IOs. diff --git a/revpimodio2/modio.py b/revpimodio2/modio.py index d08544c..3133c2e 100644 --- a/revpimodio2/modio.py +++ b/revpimodio2/modio.py @@ -10,7 +10,7 @@ from json import load as jload from multiprocessing import cpu_count from os import access, F_OK, R_OK from queue import Empty -from revpimodio2 import acheck, DeviceNotFoundError +from revpimodio2 import acheck, DeviceNotFoundError, BOTH, RISING, FALLING from signal import signal, SIG_DFL, SIGINT, SIGTERM from threading import Thread, Event, Lock from timeit import default_timer @@ -771,11 +771,29 @@ class RevPiModIO(object): self._exit.clear() self._looprunning = True - # Beim Eintritt in mainloop Bytecopy erstellen + # Beim Eintritt in mainloop Bytecopy erstellen und prefire anhängen for dev in self._lst_refresh: with dev._filelock: dev._ba_datacp = dev._ba_devdata[:] + # Prefire Events vorbereiten + for io in dev._dict_events: + for regfunc in dev._dict_events[io]: + if not regfunc.prefire: + continue + + if regfunc.edge == BOTH \ + or regfunc.edge == RISING and io.value \ + or regfunc.edge == FALLING and not io.value: + if regfunc.as_thread: + self._imgwriter.__eventqth.put( + (regfunc, io._name, io.value), False + ) + else: + self._imgwriter._eventq.put( + (regfunc, io._name, io.value), False + ) + # ImgWriter mit Eventüberwachung aktivieren self._imgwriter._collect_events(True) e = None From 9d645bec3754b2a1fa416aff48cdcec18b1902e5 Mon Sep 17 00:00:00 2001 From: NaruX Date: Wed, 31 Jul 2019 20:48:59 +0200 Subject: [PATCH 4/5] =?UTF-8?q?docstring=20prefire=20kann=20bei=20replace?= =?UTF-8?q?=5Fio=20direkt=20mit=20=C3=BCbergeben=20werden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/revpimodio2.io.html | 1 + revpimodio2/io.py | 1 + 2 files changed, 2 insertions(+) diff --git a/doc/revpimodio2.io.html b/doc/revpimodio2.io.html index a83171d..673584e 100644 --- a/doc/revpimodio2.io.html +++ b/doc/revpimodio2.io.html @@ -967,6 +967,7 @@ Weitere Parameter: - delay: Verzoegerung in ms zum Ausloesen wenn Wert gleich bleibt - edge: Event ausfuehren bei RISING, FALLING or BOTH Wertaenderung - as_thread: Fuehrt die event-Funktion als RevPiCallback-Thread aus + - prefire: Ausloesen mit aktuellem Wert, wenn mainloop startet
See Also:
diff --git a/revpimodio2/io.py b/revpimodio2/io.py index eb5b21b..a734f18 100644 --- a/revpimodio2/io.py +++ b/revpimodio2/io.py @@ -920,6 +920,7 @@ class IntIOReplaceable(IntIO): - delay: Verzoegerung in ms zum Ausloesen wenn Wert gleich bleibt - edge: Event ausfuehren bei RISING, FALLING or BOTH Wertaenderung - as_thread: Fuehrt die event-Funktion als RevPiCallback-Thread aus + - prefire: Ausloesen mit aktuellem Wert, wenn mainloop startet @see Python3 struct From 76392dd1d2a9a92f11dc6f4d5b0c5e525c2931e2 Mon Sep 17 00:00:00 2001 From: NaruX Date: Wed, 31 Jul 2019 20:51:09 +0200 Subject: [PATCH 5/5] =?UTF-8?q?Replace=5FIO=20file=20hatte=20bei=20export?= =?UTF-8?q?=20falschen=20namen=20f=C3=BCr=20bit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- revpimodio2/modio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/revpimodio2/modio.py b/revpimodio2/modio.py index d08544c..146629d 100644 --- a/revpimodio2/modio.py +++ b/revpimodio2/modio.py @@ -643,7 +643,7 @@ class RevPiModIO(object): # Optional values if io._bitaddress >= 0: - cp[io.name]["bitaddress"] = str(io._bitaddress) + cp[io.name]["bit"] = str(io._bitaddress) cp[io.name]["byteorder"] = io._byteorder cp[io.name]["defaultvalue"] = str(io.defaultvalue) if io.bmk != "":