diff --git a/.idea/misc.xml b/.idea/misc.xml
index 3999087..bc8d735 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -4,4 +4,7 @@
+
+
+
\ No newline at end of file
diff --git a/revpimodio2/__init__.py b/revpimodio2/__init__.py
index 5b1089d..708b616 100644
--- a/revpimodio2/__init__.py
+++ b/revpimodio2/__init__.py
@@ -13,7 +13,7 @@ Auf alle IOs kann der Benutzer Funktionen als Events registrieren. Diese
fuehrt das Modul bei Datenaenderung aus.
"""
__all__ = [
- "RevPiModIO", "RevPiModIODriver", "RevPiModIOSelected",
+ "RevPiModIO", "RevPiModIODriver", "RevPiModIOSelected", "run_plc",
"RevPiNetIO", "RevPiNetIODriver", "RevPiNetIOSelected",
"Cycletools", "EventCallback"
]
@@ -21,7 +21,7 @@ __author__ = "Sven Sager "
__copyright__ = "Copyright (C) 2018 Sven Sager"
__license__ = "LGPLv3"
__name__ = "revpimodio2"
-__version__ = "2.4.5c"
+__version__ = "2.5.0"
# Global package values
OFF = 0
@@ -95,5 +95,5 @@ def consttostr(value) -> str:
# Benötigte Klassen importieren
from .helper import Cycletools, EventCallback
-from .modio import RevPiModIO, RevPiModIODriver, RevPiModIOSelected
+from .modio import RevPiModIO, RevPiModIODriver, RevPiModIOSelected, run_plc
from .netio import RevPiNetIO, RevPiNetIODriver, RevPiNetIOSelected
diff --git a/revpimodio2/device.py b/revpimodio2/device.py
index 08092e8..c6475a4 100644
--- a/revpimodio2/device.py
+++ b/revpimodio2/device.py
@@ -1254,7 +1254,7 @@ class Virtual(Gateway):
for io in self.get_inputs():
self._ba_devdata[io._slc_address] = io._defaultvalue
- # Outputs auf Bus schreiben
+ # Inputs auf Bus schreiben
self._modio._myfh_lck.acquire()
try:
self._modio._myfh.seek(self._slc_inpoff.start)
diff --git a/revpimodio2/helper.py b/revpimodio2/helper.py
index 1b93ece..ae04d68 100644
--- a/revpimodio2/helper.py
+++ b/revpimodio2/helper.py
@@ -86,9 +86,10 @@ class Cycletools:
"""
__slots__ = "__cycle", "__cycletime", "__ucycle", "__dict_ton", \
- "__dict_tof", "__dict_tp", "_start_timer", "core", "first", \
- "io", "last", "flag1c", "flag5c", "flag10c", "flag15c", \
- "flag20c", "flank5c", "flank10c", "flank15c", "flank20c", "var"
+ "__dict_tof", "__dict_tp", "_start_timer", "core", "device", \
+ "first", "io", "last", "var", \
+ "flag1c", "flag5c", "flag10c", "flag15c", "flag20c", \
+ "flank5c", "flank10c", "flank15c", "flank20c"
def __init__(self, cycletime, revpi_object):
"""Init Cycletools class."""
@@ -102,6 +103,7 @@ class Cycletools:
# Access to core and io
self.core = revpi_object.core
+ self.device = revpi_object.device
self.io = revpi_object.io
# Taktmerker
@@ -476,6 +478,7 @@ class ProcimgWriter(Thread):
mrk_warn = True
mrk_dt = default_timer()
+ bytesbuff = bytearray(self._modio._length)
while not self._work.is_set():
ot = mrk_dt
@@ -491,7 +494,7 @@ class ProcimgWriter(Thread):
try:
fh.seek(0)
- bytesbuff = bytearray(fh.read(self._modio._length))
+ fh.readinto(bytesbuff)
if self._modio._monitoring or self._modio._direct_output:
# Inputs und Outputs in Puffer
diff --git a/revpimodio2/io.py b/revpimodio2/io.py
index 8ac2f45..fadeaec 100644
--- a/revpimodio2/io.py
+++ b/revpimodio2/io.py
@@ -4,7 +4,7 @@ import struct
from re import match as rematch
from threading import Event
-from revpimodio2 import BOTH, FALLING, INP, MEM, RISING, consttostr
+from revpimodio2 import BOTH, FALLING, INP, MEM, OUT, RISING, consttostr
__author__ = "Sven Sager"
__copyright__ = "Copyright (C) 2018 Sven Sager"
@@ -291,7 +291,7 @@ class IOBase(object):
__slots__ = "__bit_ioctl_off", "__bit_ioctl_on", "_bitaddress", \
"_bitshift", "_bitlength", "_byteorder", "_defaultvalue", \
"_iotype", "_length", "_name", "_parentdevice", \
- "_signed", "_slc_address", "bmk", "export"
+ "_read_only_io", "_signed", "_slc_address", "bmk", "export"
def __init__(self, parentdevice, valuelist: list, iotype: int, byteorder: str, signed: bool):
"""
@@ -318,6 +318,7 @@ class IOBase(object):
self.__bit_ioctl_off = None
self.__bit_ioctl_on = None
+ self._read_only_io = iotype != OUT
self._byteorder = byteorder
self._iotype = iotype
self._name = valuelist[0]
@@ -576,19 +577,23 @@ class IOBase(object):
:param value: IO-Wert als oder
"""
- if self._iotype == INP:
- if self._parentdevice._modio._simulator:
+ if self._read_only_io:
+ if self._iotype == INP:
+ if self._parentdevice._modio._simulator:
+ raise RuntimeError(
+ "can not write to output '{0}' in simulator mode"
+ "".format(self._name)
+ )
+ else:
+ raise RuntimeError(
+ "can not write to input '{0}'".format(self._name)
+ )
+ elif self._iotype == MEM:
raise RuntimeError(
- "can not write to output '{0}' in simulator mode"
- "".format(self._name)
+ "can not write to memory '{0}'".format(self._name)
)
- else:
- raise RuntimeError(
- "can not write to input '{0}'".format(self._name)
- )
- if self._iotype == MEM:
raise RuntimeError(
- "can not write to memory '{0}'".format(self._name)
+ "the io object '{0}' is read only".format(self._name)
)
if self._bitshift:
diff --git a/revpimodio2/modio.py b/revpimodio2/modio.py
index 75ef4b7..8a7dda7 100644
--- a/revpimodio2/modio.py
+++ b/revpimodio2/modio.py
@@ -1336,6 +1336,29 @@ class RevPiModIODriver(RevPiModIOSelected):
)
+def run_plc(func, cycletime=50, replace_io_file=None):
+ """
+ Run Revoluton Pi as real plc with cycle loop and exclusive IO access.
+
+ This function is just a shortcut to run the module in cycle loop mode and
+ 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)
+ 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
+ :return: None or the return value of the cycle function
+ """
+ rpi = RevPiModIO(autorefresh=True, replace_io_file=replace_io_file)
+ rpi.handlesignalend()
+ return rpi.cycleloop(func, cycletime)
+
+
# Nachträglicher Import
from . import app as appmodule
from . import device as devicemodule
diff --git a/setup.py b/setup.py
index 10c68e1..89e4ece 100644
--- a/setup.py
+++ b/setup.py
@@ -17,7 +17,7 @@ setup(
license="LGPLv3",
name="revpimodio2",
- version="2.4.5d",
+ version="2.5.0",
packages=["revpimodio2"],
python_requires="~=3.2",