From 9460c4f106da76108b4532af42a11ea0dcd49d83 Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Wed, 9 Sep 2020 09:47:55 +0200 Subject: [PATCH] Cycleloop does not raise Exception, run_plc accept debug flag. User has to use maxioerrors = n, if the program should crash on process image errors. If the ProcimgWriter helper is running but get no new data for 2500 ms, the cycleloop will print just a warning. Cycle function is paused for that time. Most interesting for RevPi NET classes. --- revpimodio2/__init__.py | 6 +++--- revpimodio2/modio.py | 36 +++++++++++++++++++++++++++--------- setup.py | 2 +- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/revpimodio2/__init__.py b/revpimodio2/__init__.py index 31a4c4f..05047c6 100644 --- a/revpimodio2/__init__.py +++ b/revpimodio2/__init__.py @@ -16,13 +16,13 @@ __all__ = [ "RevPiModIO", "RevPiModIODriver", "RevPiModIOSelected", "run_plc", "RevPiNetIO", "RevPiNetIODriver", "RevPiNetIOSelected", "Cycletools", "EventCallback", - "AIO", "DI", "DO", "DIO", + "AIO", "COMPACT", "DI", "DO", "DIO", ] __author__ = "Sven Sager " __copyright__ = "Copyright (C) 2020 Sven Sager" __license__ = "LGPLv3" __name__ = "revpimodio2" -__version__ = "2.5.3a" +__version__ = "2.5.3b" # Global package values OFF = 0 @@ -96,7 +96,7 @@ def consttostr(value) -> str: # Benötigte Klassen importieren -from .pictory import AIO, DI, DO, DIO +from .pictory import AIO, COMPACT, DI, DO, DIO from .helper import Cycletools, EventCallback from .modio import RevPiModIO, RevPiModIODriver, RevPiModIOSelected, run_plc from .netio import RevPiNetIO, RevPiNetIODriver, RevPiNetIOSelected diff --git a/revpimodio2/modio.py b/revpimodio2/modio.py index 492fd8e..e7eb312 100644 --- a/revpimodio2/modio.py +++ b/revpimodio2/modio.py @@ -741,12 +741,18 @@ class RevPiModIO(object): while ec is None and not cycleinfo.last: # Auf neue Daten warten und nur ausführen wenn set() if not self._imgwriter.newdata.wait(2.5): - self.exit(full=False) - if self._imgwriter.is_alive(): - e = RuntimeError("no new io data in cycle loop") - else: + if not self._imgwriter.is_alive(): + self.exit(full=False) e = RuntimeError("autorefresh thread not running") - break + break + + # Just warn, user has to use maxioerrors to kill program + warnings.warn(RuntimeWarning( + "no new io data in cycle loop for 2500 milliseconds" + )) + cycleinfo.last = self._exit.is_set() + continue + self._imgwriter.newdata.clear() # Vor Aufruf der Funktion autorefresh sperren @@ -1336,7 +1342,9 @@ class RevPiModIODriver(RevPiModIOSelected): ) -def run_plc(func, cycletime=50, replace_io_file=None): +def run_plc( + func, cycletime=50, replace_io_file=None, debug=True, + procimg=None, configrsc=None): """ Run Revoluton Pi as real plc with cycle loop and exclusive IO access. @@ -1344,17 +1352,27 @@ def run_plc(func, cycletime=50, replace_io_file=None): handle the program exit signal. You will access the .io, .core, .device via the cycletools in your cycle function. - Shortcut vor this source code: - rpi = RevPiModIO(autorefresh=True, replace_io_file=replace_io_file) + Shortcut for this source code: + rpi = RevPiModIO(autorefresh=True, replace_io_file=..., debug=...) rpi.handlesignalend() return rpi.cycleloop(func, cycletime) :param func: Function to run every set milliseconds :param cycletime: Cycle time in milliseconds :param replace_io_file: Load replace IO configuration from file + :param debug: Print all warnings and detailed error messages + :param procimg: Use different process image + :param configrsc: Use different piCtory configuration + :return: None or the return value of the cycle function """ - rpi = RevPiModIO(autorefresh=True, replace_io_file=replace_io_file) + rpi = RevPiModIO( + autorefresh=True, + replace_io_file=replace_io_file, + debug=debug, + procimg=procimg, + configrsc=configrsc, + ) rpi.handlesignalend() return rpi.cycleloop(func, cycletime) diff --git a/setup.py b/setup.py index 57af0c4..5300286 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ setup( license="LGPLv3", name="revpimodio2", - version="2.5.3a", + version="2.5.3b", packages=["revpimodio2"], python_requires="~=3.2",