Parameterprüfung für Instantiierung eingeführt

Debug-Parameter für alle Vererbungen übernommen
This commit is contained in:
2019-05-01 12:25:45 +02:00
parent 6782e9431a
commit 2463eb019d
8 changed files with 92 additions and 26 deletions

View File

@@ -33,11 +33,32 @@ Classes</h3>
Functions</h3>
<table>
<tr>
<td><a style="color:#0000FF" href="#acheck">acheck</a></td>
<td>Check type of given arguments.</td>
</tr><tr>
<td><a style="color:#0000FF" href="#consttostr">consttostr</a></td>
<td>Gibt <class 'str'> fuer Konstanten zurueck.</td>
</tr>
</table>
<hr /><hr />
<a NAME="acheck" ID="acheck"></a>
<h2 style="background-color:#FFFFFF;color:#0000FF">acheck</h2>
<b>acheck</b>(<i>check_type, **kwargs</i>)
<p>
Check type of given arguments.
</p><p>
Use the argument name as keyword and the argument itself as value.
</p><dl>
<dt><i>check_type</i></dt>
<dd>
Type to check
</dd><dt><i>kwargs</i></dt>
<dd>
Arguments to check
</dd>
</dl>
<div align="right"><a style="color:#0000FF" href="#top">Up</a></div>
<hr /><hr />
<a NAME="consttostr" ID="consttostr"></a>
<h2 style="background-color:#FFFFFF;color:#0000FF">consttostr</h2>
<b>consttostr</b>(<i>value</i>)

View File

@@ -180,6 +180,9 @@ Abweichender Pfad zur piCtory Konfigurationsdatei
</dd><dt><i>simulator</i></dt>
<dd>
Laedt das Modul als Simulator und vertauscht IOs
</dd><dt><i>debug</i></dt>
<dd>
Gibt bei allen Fehlern komplette Meldungen aus
</dd>
</dl><a NAME="RevPiModIO.__del__" ID="RevPiModIO.__del__"></a>
<h3 style="background-color:#FFFFFF;color:#FF0000">
@@ -592,7 +595,7 @@ Static Methods</h3>
<a NAME="RevPiModIODriver.__init__" ID="RevPiModIODriver.__init__"></a>
<h3 style="background-color:#FFFFFF;color:#FF0000">
RevPiModIODriver (Constructor)</h3>
<b>RevPiModIODriver</b>(<i>virtdev, autorefresh=False, monitoring=False, syncoutputs=True, procimg=None, configrsc=None</i>)
<b>RevPiModIODriver</b>(<i>virtdev, autorefresh=False, monitoring=False, syncoutputs=True, procimg=None, configrsc=None, debug=False</i>)
<p>
Instantiiert die Grundfunktionen.
</p><p>
@@ -652,7 +655,7 @@ Static Methods</h3>
<a NAME="RevPiModIOSelected.__init__" ID="RevPiModIOSelected.__init__"></a>
<h3 style="background-color:#FFFFFF;color:#FF0000">
RevPiModIOSelected (Constructor)</h3>
<b>RevPiModIOSelected</b>(<i>deviceselection, autorefresh=False, monitoring=False, syncoutputs=True, procimg=None, configrsc=None, simulator=False</i>)
<b>RevPiModIOSelected</b>(<i>deviceselection, autorefresh=False, monitoring=False, syncoutputs=True, procimg=None, configrsc=None, simulator=False, debug=False</i>)
<p>
Instantiiert nur fuer angegebene Devices die Grundfunktionen.
</p><p>

View File

@@ -423,7 +423,7 @@ Static Methods</h3>
<a NAME="RevPiNetIO.__init__" ID="RevPiNetIO.__init__"></a>
<h3 style="background-color:#FFFFFF;color:#FF0000">
RevPiNetIO (Constructor)</h3>
<b>RevPiNetIO</b>(<i>address, autorefresh=False, monitoring=False, syncoutputs=True, simulator=False</i>)
<b>RevPiNetIO</b>(<i>address, autorefresh=False, monitoring=False, syncoutputs=True, simulator=False, debug=False</i>)
<p>
Instantiiert die Grundfunktionen.
</p><dl>
@@ -442,6 +442,9 @@ Aktuell gesetzte Outputs vom Prozessabbild einlesen
</dd><dt><i>simulator</i></dt>
<dd>
Laedt das Modul als Simulator und vertauscht IOs
</dd><dt><i>debug</i></dt>
<dd>
Gibt bei allen Fehlern komplette Meldungen aus
</dd>
</dl><a NAME="RevPiNetIO._create_myfh" ID="RevPiNetIO._create_myfh"></a>
<h3 style="background-color:#FFFFFF;color:#FF0000">
@@ -533,7 +536,7 @@ Static Methods</h3>
<a NAME="RevPiNetIODriver.__init__" ID="RevPiNetIODriver.__init__"></a>
<h3 style="background-color:#FFFFFF;color:#FF0000">
RevPiNetIODriver (Constructor)</h3>
<b>RevPiNetIODriver</b>(<i>address, virtdev, autorefresh=False, monitoring=False, syncoutputs=True</i>)
<b>RevPiNetIODriver</b>(<i>address, virtdev, autorefresh=False, monitoring=False, syncoutputs=True, debug=False</i>)
<p>
Instantiiert die Grundfunktionen.
</p><p>
@@ -596,7 +599,7 @@ Static Methods</h3>
<a NAME="RevPiNetIOSelected.__init__" ID="RevPiNetIOSelected.__init__"></a>
<h3 style="background-color:#FFFFFF;color:#FF0000">
RevPiNetIOSelected (Constructor)</h3>
<b>RevPiNetIOSelected</b>(<i>address, deviceselection, autorefresh=False, monitoring=False, syncoutputs=True, simulator=False</i>)
<b>RevPiNetIOSelected</b>(<i>address, deviceselection, autorefresh=False, monitoring=False, syncoutputs=True, simulator=False, debug=False</i>)
<p>
Instantiiert nur fuer angegebene Devices die Grundfunktionen.
</p><p>

View File

@@ -7,6 +7,7 @@ revpimodio2.OFF?7
revpimodio2.OUT?7
revpimodio2.RED?7
revpimodio2.RISING?7
revpimodio2.acheck?4(check_type, **kwargs)
revpimodio2.app.App?1(app)
revpimodio2.consttostr?4(value)
revpimodio2.device.Connect.A3?7
@@ -173,8 +174,8 @@ revpimodio2.modio.RevPiModIO.simulator?7
revpimodio2.modio.RevPiModIO.syncoutputs?4(device=None)
revpimodio2.modio.RevPiModIO.writeprocimg?4(device=None)
revpimodio2.modio.RevPiModIO?1(autorefresh=False, monitoring=False, syncoutputs=True, procimg=None, configrsc=None, simulator=False, debug=False)
revpimodio2.modio.RevPiModIODriver?1(virtdev, autorefresh=False, monitoring=False, syncoutputs=True, procimg=None, configrsc=None)
revpimodio2.modio.RevPiModIOSelected?1(deviceselection, autorefresh=False, monitoring=False, syncoutputs=True, procimg=None, configrsc=None, simulator=False)
revpimodio2.modio.RevPiModIODriver?1(virtdev, autorefresh=False, monitoring=False, syncoutputs=True, procimg=None, configrsc=None, debug=False)
revpimodio2.modio.RevPiModIOSelected?1(deviceselection, autorefresh=False, monitoring=False, syncoutputs=True, procimg=None, configrsc=None, simulator=False, debug=False)
revpimodio2.netio.NetFH._connect?5()
revpimodio2.netio.NetFH._direct_send?5(send_bytes, recv_count)
revpimodio2.netio.NetFH.clear_dirtybytes?4(position=None)
@@ -201,9 +202,9 @@ revpimodio2.netio.RevPiNetIO.disconnect?4()
revpimodio2.netio.RevPiNetIO.get_jconfigrsc?4()
revpimodio2.netio.RevPiNetIO.net_cleardefaultvalues?4(device=None)
revpimodio2.netio.RevPiNetIO.net_setdefaultvalues?4(device=None)
revpimodio2.netio.RevPiNetIO?1(address, autorefresh=False, monitoring=False, syncoutputs=True, simulator=False)
revpimodio2.netio.RevPiNetIODriver?1(address, virtdev, autorefresh=False, monitoring=False, syncoutputs=True)
revpimodio2.netio.RevPiNetIOSelected?1(address, deviceselection, autorefresh=False, monitoring=False, syncoutputs=True, simulator=False)
revpimodio2.netio.RevPiNetIO?1(address, autorefresh=False, monitoring=False, syncoutputs=True, simulator=False, debug=False)
revpimodio2.netio.RevPiNetIODriver?1(address, virtdev, autorefresh=False, monitoring=False, syncoutputs=True, debug=False)
revpimodio2.netio.RevPiNetIOSelected?1(address, deviceselection, autorefresh=False, monitoring=False, syncoutputs=True, simulator=False, debug=False)
revpimodio2.netio._sysdeldirty?8
revpimodio2.netio._sysexit?8
revpimodio2.netio._sysflush?8

View File

@@ -38,6 +38,28 @@ MEM = 302
warnings.simplefilter(action="always")
def acheck(check_type, **kwargs):
"""Check type of given arguments.
Use the argument name as keyword and the argument itself as value.
@param check_type Type to check
@param kwargs Arguments to check
"""
for var_name in kwargs:
none_okay = var_name.endswith("_noneok")
if not (isinstance(kwargs[var_name], check_type) or
none_okay and kwargs[var_name] is None):
msg = "Argument '{0}' must be {1}{2}".format(
var_name.rstrip("_noneok"), str(check_type),
" or <class 'NoneType'>" if none_okay else ""
)
raise TypeError(msg)
def consttostr(value):
"""Gibt <class 'str'> fuer Konstanten zurueck.

View File

@@ -446,7 +446,7 @@ class ProcimgWriter(Thread):
RuntimeWarning
)
if self._modio._debug and e is not None:
warnings.warn(str(e))
warnings.warn(str(e), RuntimeWarning)
def get_maxioerrors(self):
"""Gibt die Anzahl der maximal erlaubten Fehler zurueck.

View File

@@ -9,6 +9,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 signal import signal, SIG_DFL, SIGINT, SIGTERM
from threading import Thread, Event, Lock
from timeit import default_timer
@@ -45,8 +46,18 @@ class RevPiModIO(object):
@param procimg Abweichender Pfad zum Prozessabbild
@param configrsc Abweichender Pfad zur piCtory Konfigurationsdatei
@param simulator Laedt das Modul als Simulator und vertauscht IOs
@param debug Gibt bei allen Fehlern komplette Meldungen aus
"""
# Parameterprüfung
acheck(
bool, autorefresh=autorefresh, monitoring=monitoring,
syncoutputs=syncoutputs, simulator=simulator, debug=debug
)
acheck(
str, procimg_noneok=procimg, configrsc_noneok=configrsc
)
self._autorefresh = autorefresh
self._configrsc = configrsc
self._monitoring = monitoring
@@ -336,7 +347,7 @@ class RevPiModIO(object):
RuntimeWarning
)
if self._debug and e is not None:
warnings.warn(str(e))
warnings.warn(str(e), RuntimeWarning)
def _set_cycletime(self, milliseconds):
"""Setzt Aktualisierungsrate der Prozessabbild-Synchronisierung.
@@ -819,7 +830,7 @@ class RevPiModIO(object):
)
mylist = [dev]
e = None
global_ex = None
workokay = True
for dev in mylist:
if not dev._selfupdate:
@@ -831,7 +842,7 @@ class RevPiModIO(object):
self._myfh.seek(dev._slc_outoff.start)
self._myfh.write(dev._ba_devdata[dev._slc_out])
except IOError as e:
e = e
global_ex = e
workokay = False
finally:
self._myfh_lck.release()
@@ -842,11 +853,11 @@ class RevPiModIO(object):
try:
self._myfh.flush()
except IOError as e:
e = e
global_ex = e
workokay = False
if not workokay:
self._gotioerror("writeprocimg", e)
self._gotioerror("writeprocimg", global_ex)
return workokay
@@ -875,7 +886,8 @@ class RevPiModIOSelected(RevPiModIO):
def __init__(
self, deviceselection, autorefresh=False, monitoring=False,
syncoutputs=True, procimg=None, configrsc=None, simulator=False):
syncoutputs=True, procimg=None, configrsc=None,
simulator=False, debug=False):
"""Instantiiert nur fuer angegebene Devices die Grundfunktionen.
Der Parameter deviceselection kann eine einzelne
@@ -887,7 +899,8 @@ class RevPiModIOSelected(RevPiModIO):
"""
super().__init__(
autorefresh, monitoring, syncoutputs, procimg, configrsc, simulator
autorefresh, monitoring, syncoutputs, procimg, configrsc,
simulator, debug
)
# Device liste erstellen
@@ -941,7 +954,7 @@ class RevPiModIODriver(RevPiModIOSelected):
def __init__(
self, virtdev, autorefresh=False, monitoring=False,
syncoutputs=True, procimg=None, configrsc=None):
syncoutputs=True, procimg=None, configrsc=None, debug=False):
"""Instantiiert die Grundfunktionen.
Parameter 'monitoring' und 'simulator' stehen hier nicht zur
@@ -953,7 +966,8 @@ class RevPiModIODriver(RevPiModIOSelected):
"""
# Parent mit monitoring=False und simulator=True laden
super().__init__(
virtdev, autorefresh, False, syncoutputs, procimg, configrsc, True
virtdev, autorefresh, False, syncoutputs, procimg, configrsc,
True, debug
)

View File

@@ -489,7 +489,7 @@ class RevPiNetIO(_RevPiModIO):
def __init__(
self, address, autorefresh=False, monitoring=False,
syncoutputs=True, simulator=False):
syncoutputs=True, simulator=False, debug=False):
"""Instantiiert die Grundfunktionen.
@param address: IP-Adresse <class 'str'> / (IP, Port) <class 'tuple'>
@@ -497,6 +497,7 @@ class RevPiNetIO(_RevPiModIO):
@param monitoring In- und Outputs werden gelesen, niemals geschrieben
@param syncoutputs Aktuell gesetzte Outputs vom Prozessabbild einlesen
@param simulator Laedt das Modul als Simulator und vertauscht IOs
@param debug Gibt bei allen Fehlern komplette Meldungen aus
"""
check_ip = compile(
@@ -544,7 +545,8 @@ class RevPiNetIO(_RevPiModIO):
syncoutputs,
"{0}:{1}".format(*self._address),
None,
simulator
simulator,
debug
)
# Netzwerkfilehandler anlegen
@@ -655,7 +657,7 @@ class RevPiNetIOSelected(RevPiNetIO):
def __init__(
self, address, deviceselection, autorefresh=False,
monitoring=False, syncoutputs=True, simulator=False):
monitoring=False, syncoutputs=True, simulator=False, debug=False):
"""Instantiiert nur fuer angegebene Devices die Grundfunktionen.
Der Parameter deviceselection kann eine einzelne
@@ -668,7 +670,7 @@ class RevPiNetIOSelected(RevPiNetIO):
"""
super().__init__(
address, autorefresh, monitoring, syncoutputs, simulator
address, autorefresh, monitoring, syncoutputs, simulator, debug
)
# Device liste erstellen
@@ -722,7 +724,7 @@ class RevPiNetIODriver(RevPiNetIOSelected):
def __init__(
self, address, virtdev, autorefresh=False, monitoring=False,
syncoutputs=True):
syncoutputs=True, debug=False):
"""Instantiiert die Grundfunktionen.
Parameter 'monitoring' und 'simulator' stehen hier nicht zur
@@ -735,5 +737,5 @@ class RevPiNetIODriver(RevPiNetIOSelected):
"""
# Parent mit monitoring=False und simulator=True laden
super().__init__(
address, virtdev, autorefresh, False, syncoutputs, True
address, virtdev, autorefresh, False, syncoutputs, True, debug
)