mirror of
https://github.com/naruxde/revpimodio2.git
synced 2025-11-08 22:03:53 +01:00
Added .device to Cycletools, added revpimodio2.run_plc shortcut to run cycleloop
Changed readinto buffer in ProcimgWriter
This commit is contained in:
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@@ -4,4 +4,7 @@
|
|||||||
<option name="languageLevel" value="ES6" />
|
<option name="languageLevel" value="ES6" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6" project-jdk-type="Python SDK" />
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6" project-jdk-type="Python SDK" />
|
||||||
|
<component name="PythonCompatibilityInspectionAdvertiser">
|
||||||
|
<option name="version" value="3" />
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -13,7 +13,7 @@ Auf alle IOs kann der Benutzer Funktionen als Events registrieren. Diese
|
|||||||
fuehrt das Modul bei Datenaenderung aus.
|
fuehrt das Modul bei Datenaenderung aus.
|
||||||
"""
|
"""
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"RevPiModIO", "RevPiModIODriver", "RevPiModIOSelected",
|
"RevPiModIO", "RevPiModIODriver", "RevPiModIOSelected", "run_plc",
|
||||||
"RevPiNetIO", "RevPiNetIODriver", "RevPiNetIOSelected",
|
"RevPiNetIO", "RevPiNetIODriver", "RevPiNetIOSelected",
|
||||||
"Cycletools", "EventCallback"
|
"Cycletools", "EventCallback"
|
||||||
]
|
]
|
||||||
@@ -21,7 +21,7 @@ __author__ = "Sven Sager <akira@revpimodio.org>"
|
|||||||
__copyright__ = "Copyright (C) 2018 Sven Sager"
|
__copyright__ = "Copyright (C) 2018 Sven Sager"
|
||||||
__license__ = "LGPLv3"
|
__license__ = "LGPLv3"
|
||||||
__name__ = "revpimodio2"
|
__name__ = "revpimodio2"
|
||||||
__version__ = "2.4.5c"
|
__version__ = "2.5.0"
|
||||||
|
|
||||||
# Global package values
|
# Global package values
|
||||||
OFF = 0
|
OFF = 0
|
||||||
@@ -95,5 +95,5 @@ def consttostr(value) -> str:
|
|||||||
|
|
||||||
# Benötigte Klassen importieren
|
# Benötigte Klassen importieren
|
||||||
from .helper import Cycletools, EventCallback
|
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
|
from .netio import RevPiNetIO, RevPiNetIODriver, RevPiNetIOSelected
|
||||||
|
|||||||
@@ -1254,7 +1254,7 @@ class Virtual(Gateway):
|
|||||||
for io in self.get_inputs():
|
for io in self.get_inputs():
|
||||||
self._ba_devdata[io._slc_address] = io._defaultvalue
|
self._ba_devdata[io._slc_address] = io._defaultvalue
|
||||||
|
|
||||||
# Outputs auf Bus schreiben
|
# Inputs auf Bus schreiben
|
||||||
self._modio._myfh_lck.acquire()
|
self._modio._myfh_lck.acquire()
|
||||||
try:
|
try:
|
||||||
self._modio._myfh.seek(self._slc_inpoff.start)
|
self._modio._myfh.seek(self._slc_inpoff.start)
|
||||||
|
|||||||
@@ -86,9 +86,10 @@ class Cycletools:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = "__cycle", "__cycletime", "__ucycle", "__dict_ton", \
|
__slots__ = "__cycle", "__cycletime", "__ucycle", "__dict_ton", \
|
||||||
"__dict_tof", "__dict_tp", "_start_timer", "core", "first", \
|
"__dict_tof", "__dict_tp", "_start_timer", "core", "device", \
|
||||||
"io", "last", "flag1c", "flag5c", "flag10c", "flag15c", \
|
"first", "io", "last", "var", \
|
||||||
"flag20c", "flank5c", "flank10c", "flank15c", "flank20c", "var"
|
"flag1c", "flag5c", "flag10c", "flag15c", "flag20c", \
|
||||||
|
"flank5c", "flank10c", "flank15c", "flank20c"
|
||||||
|
|
||||||
def __init__(self, cycletime, revpi_object):
|
def __init__(self, cycletime, revpi_object):
|
||||||
"""Init Cycletools class."""
|
"""Init Cycletools class."""
|
||||||
@@ -102,6 +103,7 @@ class Cycletools:
|
|||||||
|
|
||||||
# Access to core and io
|
# Access to core and io
|
||||||
self.core = revpi_object.core
|
self.core = revpi_object.core
|
||||||
|
self.device = revpi_object.device
|
||||||
self.io = revpi_object.io
|
self.io = revpi_object.io
|
||||||
|
|
||||||
# Taktmerker
|
# Taktmerker
|
||||||
@@ -476,6 +478,7 @@ class ProcimgWriter(Thread):
|
|||||||
mrk_warn = True
|
mrk_warn = True
|
||||||
mrk_dt = default_timer()
|
mrk_dt = default_timer()
|
||||||
|
|
||||||
|
bytesbuff = bytearray(self._modio._length)
|
||||||
while not self._work.is_set():
|
while not self._work.is_set():
|
||||||
ot = mrk_dt
|
ot = mrk_dt
|
||||||
|
|
||||||
@@ -491,7 +494,7 @@ class ProcimgWriter(Thread):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
fh.seek(0)
|
fh.seek(0)
|
||||||
bytesbuff = bytearray(fh.read(self._modio._length))
|
fh.readinto(bytesbuff)
|
||||||
|
|
||||||
if self._modio._monitoring or self._modio._direct_output:
|
if self._modio._monitoring or self._modio._direct_output:
|
||||||
# Inputs und Outputs in Puffer
|
# Inputs und Outputs in Puffer
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import struct
|
|||||||
from re import match as rematch
|
from re import match as rematch
|
||||||
from threading import Event
|
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"
|
__author__ = "Sven Sager"
|
||||||
__copyright__ = "Copyright (C) 2018 Sven Sager"
|
__copyright__ = "Copyright (C) 2018 Sven Sager"
|
||||||
@@ -291,7 +291,7 @@ class IOBase(object):
|
|||||||
__slots__ = "__bit_ioctl_off", "__bit_ioctl_on", "_bitaddress", \
|
__slots__ = "__bit_ioctl_off", "__bit_ioctl_on", "_bitaddress", \
|
||||||
"_bitshift", "_bitlength", "_byteorder", "_defaultvalue", \
|
"_bitshift", "_bitlength", "_byteorder", "_defaultvalue", \
|
||||||
"_iotype", "_length", "_name", "_parentdevice", \
|
"_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):
|
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_off = None
|
||||||
self.__bit_ioctl_on = None
|
self.__bit_ioctl_on = None
|
||||||
|
self._read_only_io = iotype != OUT
|
||||||
self._byteorder = byteorder
|
self._byteorder = byteorder
|
||||||
self._iotype = iotype
|
self._iotype = iotype
|
||||||
self._name = valuelist[0]
|
self._name = valuelist[0]
|
||||||
@@ -576,6 +577,7 @@ class IOBase(object):
|
|||||||
|
|
||||||
:param value: IO-Wert als <class bytes'> oder <class 'bool'>
|
:param value: IO-Wert als <class bytes'> oder <class 'bool'>
|
||||||
"""
|
"""
|
||||||
|
if self._read_only_io:
|
||||||
if self._iotype == INP:
|
if self._iotype == INP:
|
||||||
if self._parentdevice._modio._simulator:
|
if self._parentdevice._modio._simulator:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
@@ -586,10 +588,13 @@ class IOBase(object):
|
|||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"can not write to input '{0}'".format(self._name)
|
"can not write to input '{0}'".format(self._name)
|
||||||
)
|
)
|
||||||
if self._iotype == MEM:
|
elif self._iotype == MEM:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"can not write to memory '{0}'".format(self._name)
|
"can not write to memory '{0}'".format(self._name)
|
||||||
)
|
)
|
||||||
|
raise RuntimeError(
|
||||||
|
"the io object '{0}' is read only".format(self._name)
|
||||||
|
)
|
||||||
|
|
||||||
if self._bitshift:
|
if self._bitshift:
|
||||||
# Versuchen egal welchen Typ in Bool zu konvertieren
|
# Versuchen egal welchen Typ in Bool zu konvertieren
|
||||||
|
|||||||
@@ -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
|
# Nachträglicher Import
|
||||||
from . import app as appmodule
|
from . import app as appmodule
|
||||||
from . import device as devicemodule
|
from . import device as devicemodule
|
||||||
|
|||||||
Reference in New Issue
Block a user