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.
This commit is contained in:
2020-09-09 09:47:55 +02:00
parent 6f5415a567
commit 9460c4f106
3 changed files with 31 additions and 13 deletions

View File

@@ -16,13 +16,13 @@ __all__ = [
"RevPiModIO", "RevPiModIODriver", "RevPiModIOSelected", "run_plc", "RevPiModIO", "RevPiModIODriver", "RevPiModIOSelected", "run_plc",
"RevPiNetIO", "RevPiNetIODriver", "RevPiNetIOSelected", "RevPiNetIO", "RevPiNetIODriver", "RevPiNetIOSelected",
"Cycletools", "EventCallback", "Cycletools", "EventCallback",
"AIO", "DI", "DO", "DIO", "AIO", "COMPACT", "DI", "DO", "DIO",
] ]
__author__ = "Sven Sager <akira@revpimodio.org>" __author__ = "Sven Sager <akira@revpimodio.org>"
__copyright__ = "Copyright (C) 2020 Sven Sager" __copyright__ = "Copyright (C) 2020 Sven Sager"
__license__ = "LGPLv3" __license__ = "LGPLv3"
__name__ = "revpimodio2" __name__ = "revpimodio2"
__version__ = "2.5.3a" __version__ = "2.5.3b"
# Global package values # Global package values
OFF = 0 OFF = 0
@@ -96,7 +96,7 @@ def consttostr(value) -> str:
# Benötigte Klassen importieren # 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 .helper import Cycletools, EventCallback
from .modio import RevPiModIO, RevPiModIODriver, RevPiModIOSelected, run_plc from .modio import RevPiModIO, RevPiModIODriver, RevPiModIOSelected, run_plc
from .netio import RevPiNetIO, RevPiNetIODriver, RevPiNetIOSelected from .netio import RevPiNetIO, RevPiNetIODriver, RevPiNetIOSelected

View File

@@ -741,12 +741,18 @@ class RevPiModIO(object):
while ec is None and not cycleinfo.last: while ec is None and not cycleinfo.last:
# Auf neue Daten warten und nur ausführen wenn set() # Auf neue Daten warten und nur ausführen wenn set()
if not self._imgwriter.newdata.wait(2.5): if not self._imgwriter.newdata.wait(2.5):
if not self._imgwriter.is_alive():
self.exit(full=False) self.exit(full=False)
if self._imgwriter.is_alive():
e = RuntimeError("no new io data in cycle loop")
else:
e = RuntimeError("autorefresh thread not running") 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() self._imgwriter.newdata.clear()
# Vor Aufruf der Funktion autorefresh sperren # 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. 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 handle the program exit signal. You will access the .io, .core, .device
via the cycletools in your cycle function. via the cycletools in your cycle function.
Shortcut vor this source code: Shortcut for this source code:
rpi = RevPiModIO(autorefresh=True, replace_io_file=replace_io_file) rpi = RevPiModIO(autorefresh=True, replace_io_file=..., debug=...)
rpi.handlesignalend() rpi.handlesignalend()
return rpi.cycleloop(func, cycletime) return rpi.cycleloop(func, cycletime)
:param func: Function to run every set milliseconds :param func: Function to run every set milliseconds
:param cycletime: Cycle time in milliseconds :param cycletime: Cycle time in milliseconds
:param replace_io_file: Load replace IO configuration from file :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 :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() rpi.handlesignalend()
return rpi.cycleloop(func, cycletime) return rpi.cycleloop(func, cycletime)

View File

@@ -17,7 +17,7 @@ setup(
license="LGPLv3", license="LGPLv3",
name="revpimodio2", name="revpimodio2",
version="2.5.3a", version="2.5.3b",
packages=["revpimodio2"], packages=["revpimodio2"],
python_requires="~=3.2", python_requires="~=3.2",