Errortypen angepasst

NetFh.__init__ Parameterprüfung geändert
NetFh._direct_send implementiert
This commit is contained in:
2018-12-12 08:49:21 +01:00
parent 325bb23bba
commit 38ba012f38
6 changed files with 90 additions and 46 deletions

View File

@@ -80,6 +80,9 @@ Methods</h3>
<td><a style="color:#0000FF" href="#NetFH._connect">_connect</a></td>
<td>Stellt die Verbindung zu einem RevPiSlave her.</td>
</tr><tr>
<td><a style="color:#0000FF" href="#NetFH._direct_send">_direct_send</a></td>
<td>Fuer debugging direktes Senden von Daten.</td>
</tr><tr>
<td><a style="color:#0000FF" href="#NetFH.clear_dirtybytes">clear_dirtybytes</a></td>
<td>Entfernt die konfigurierten Dirtybytes vom RevPi Slave.</td>
</tr><tr>
@@ -174,7 +177,26 @@ NetFH._connect</h3>
<b>_connect</b>(<i></i>)
<p>
Stellt die Verbindung zu einem RevPiSlave her.
</p><a NAME="NetFH.clear_dirtybytes" ID="NetFH.clear_dirtybytes"></a>
</p><a NAME="NetFH._direct_send" ID="NetFH._direct_send"></a>
<h3 style="background-color:#FFFFFF;color:#FF0000">
NetFH._direct_send</h3>
<b>_direct_send</b>(<i>send_bytes, recv_count</i>)
<p>
Fuer debugging direktes Senden von Daten.
</p><dl>
<dt><i>send_bytes</i></dt>
<dd>
Bytes, die gesendet werden sollen
</dd><dt><i>recv_count</i></dt>
<dd>
Anzahl der Empfangsbytes
</dd>
</dl><dl>
<dt>Returns:</dt>
<dd>
Empfangende Bytes
</dd>
</dl><a NAME="NetFH.clear_dirtybytes" ID="NetFH.clear_dirtybytes"></a>
<h3 style="background-color:#FFFFFF;color:#FF0000">
NetFH.clear_dirtybytes</h3>
<b>clear_dirtybytes</b>(<i>position=None</i>)

View File

@@ -176,6 +176,7 @@ revpimodio2.modio.RevPiModIO?1(autorefresh=False, monitoring=False, syncoutputs=
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.netio.NetFH._connect?5()
revpimodio2.netio.NetFH._direct_send?5(send_bytes, recv_count)
revpimodio2.netio.NetFH.clear_dirtybytes?4(position=None)
revpimodio2.netio.NetFH.close?4()
revpimodio2.netio.NetFH.closed?7

View File

@@ -403,7 +403,7 @@ class ProcimgWriter(Thread):
@param value True aktiviert / False deaktiviert
@return True, wenn Anforderung erfolgreich war"""
if type(value) != bool:
raise ValueError("value must be <class 'bool'>")
raise TypeError("value must be <class 'bool'>")
# Nur starten, wenn System läuft
if not self.is_alive():
@@ -561,10 +561,13 @@ class ProcimgWriter(Thread):
def set_maxioerrors(self, value):
"""Setzt die Anzahl der maximal erlaubten Fehler.
@param value Anzahl erlaubte Fehler"""
if type(value) == int and value >= 0:
self._maxioerrors = value
if type(value) == int:
if value >= 0:
self._maxioerrors = value
else:
raise ValueError("value must be 0 or a positive integer")
else:
raise ValueError("value must be 0 or a positive integer")
raise TypeError("value must be <class 'int'>")
def set_refresh(self, value):
"""Setzt die Zykluszeit in Millisekunden.

View File

@@ -131,7 +131,7 @@ class IOList(object):
]:
object.__setattr__(self, key, value)
else:
raise ValueError(
raise AttributeError(
"direct assignment is not supported - use .value Attribute"
)
@@ -222,7 +222,7 @@ class IOList(object):
]
self.__dict_iobyte[new_io.address][new_io._bitaddress] = new_io
else:
raise AttributeError("io must be <class 'IOBase'> or sub class")
raise TypeError("io must be <class 'IOBase'> or sub class")
class DeadIO(object):
@@ -380,15 +380,15 @@ class IOBase(object):
"""
# Prüfen ob Funktion callable ist
if not callable(func):
raise AttributeError(
raise ValueError(
"registered function '{0}' is not callable".format(func)
)
if type(delay) != int or delay < 0:
raise AttributeError(
raise ValueError(
"'delay' must be <class 'int'> and greater or equal 0"
)
if edge != BOTH and self._bitaddress < 0:
raise AttributeError(
raise ValueError(
"parameter 'edge' can be used with bit io objects only"
)
@@ -405,12 +405,12 @@ class IOBase(object):
if edge == BOTH or regfunc.edge == BOTH:
if self._bitaddress < 0:
raise AttributeError(
raise RuntimeError(
"io '{0}' with function '{1}' already in list."
"".format(self._name, func)
)
else:
raise AttributeError(
raise RuntimeError(
"io '{0}' with function '{1}' already in list "
"with edge '{2}' - edge '{3}' not allowed anymore"
"".format(
@@ -419,7 +419,7 @@ class IOBase(object):
)
)
elif regfunc.edge == edge:
raise AttributeError(
raise RuntimeError(
"io '{0}' with function '{1}' for given edge '{2}' "
"already in list".format(
self._name, func, consttostr(edge)
@@ -543,24 +543,24 @@ class IOBase(object):
)
)
else:
raise ValueError(
raise TypeError(
"'{0}' requires a <class 'bytes'> object, not {1}"
"".format(self._name, type(value))
)
elif self._iotype == INP:
if self._parentdevice._modio._simulator:
raise AttributeError(
raise RuntimeError(
"can not write to output '{0}' in simulator mode"
"".format(self._name)
)
else:
raise AttributeError(
raise RuntimeError(
"can not write to input '{0}'".format(self._name)
)
elif self._iotype == MEM:
raise AttributeError(
raise RuntimeError(
"can not write to memory '{0}'".format(self._name)
)
@@ -640,20 +640,20 @@ class IOBase(object):
)
)
if not (RISING <= edge <= BOTH):
raise AttributeError(
raise ValueError(
"parameter 'edge' must be revpimodio2.RISING, "
"revpimodio2.FALLING or revpimodio2.BOTH"
)
if not (exitevent is None or type(exitevent) == Event):
raise AttributeError(
raise TypeError(
"parameter 'exitevent' must be <class 'threading.Event'>"
)
if type(timeout) != int or timeout < 0:
raise AttributeError(
raise ValueError(
"parameter 'timeout' must be <class 'int'> and greater than 0"
)
if edge != BOTH and self._bitaddress < 0:
raise AttributeError(
raise ValueError(
"parameter 'edge' can be used with bit Inputs only"
)
@@ -752,7 +752,7 @@ class IntIO(IOBase):
"""Left fest, ob der Wert Vorzeichenbehaftet behandelt werden soll.
@param value True, wenn mit Vorzeichen behandel"""
if type(value) != bool:
raise ValueError("signed must be <class 'bool'> True or False")
raise TypeError("signed must be <class 'bool'> True or False")
self._signed = value
def get_intdefaultvalue(self):
@@ -781,7 +781,7 @@ class IntIO(IOBase):
signed=self._signed
))
else:
raise ValueError(
raise TypeError(
"'{0}' need a <class 'int'> value, but {1} was given"
"".format(self._name, type(value))
)
@@ -825,7 +825,7 @@ class IntIOCounter(IntIO):
"can not reset counter, while system is in monitoring mode"
)
if self._parentdevice._modio._simulator:
raise AttributeError(
raise RuntimeError(
"can not reset counter, while system is in simulator mode"
)
@@ -841,7 +841,10 @@ class IntIOCounter(IntIO):
elif self._parentdevice._modio._procimg != "/dev/piControl0":
# NOTE: Soll hier eine 0 in den Input geschrieben werden?
warnings.warn("this will work on a revolution pi only")
warnings.warn(
"this will work on a revolution pi only",
RuntimeWarning
)
else:
# IOCTL auf dem RevPi
@@ -957,7 +960,7 @@ class StructIO(IOBase):
bitaddress = kwargs.get("bit", 0)
max_bits = parentio._length * 8
if not (0 <= bitaddress < max_bits):
raise AttributeError(
raise ValueError(
"bitaddress must be a value between 0 and {0}"
"".format(max_bits - 1)
)
@@ -986,7 +989,7 @@ class StructIO(IOBase):
bitaddress
]
else:
raise AttributeError(
raise ValueError(
"parameter frm has to be a single sign or 'COUNTs' e.g. '8s'"
)

View File

@@ -321,14 +321,12 @@ class RevPiModIO(object):
self._ioerror += 1
if self._maxioerrors != 0 and self._ioerror >= self._maxioerrors:
raise RuntimeError(
"reach max io error count {0} on process image".format(
self._maxioerrors
)
"reach max io error count {0} on process image"
"".format(self._maxioerrors)
)
warnings.warn(
"got io error during {0} and count {1} errors now".format(
action, self._ioerror
),
"got io error during {0} and count {1} errors now"
"".format(action, self._ioerror),
RuntimeWarning
)

View File

@@ -45,13 +45,6 @@ class NetFH(Thread):
"""Init NetFH-class.
@param address IP Adresse, Port des RevPi als <class 'tuple'>
@param timeout Timeout in Millisekunden der Verbindung"""
if not isinstance(address, tuple):
raise ValueError(
"parameter address must be <class 'tuple'> ('IP', PORT)"
)
if not isinstance(timeout, int):
raise ValueError("parameter timeout must be <class 'int'>")
super().__init__()
self.daemon = True
@@ -66,11 +59,18 @@ class NetFH(Thread):
self.__timeout = None
self.__trigger = False
self.__waitsync = None
# Verbindung herstellen
self._address = address
self._slavesock = None
# Parameterprüfung
if not isinstance(address, tuple):
raise TypeError(
"parameter address must be <class 'tuple'> ('IP', PORT)"
)
if not isinstance(timeout, int):
raise TypeError("parameter timeout must be <class 'int'>")
# Verbindung herstellen
self.__set_systimeout(timeout)
self._connect()
@@ -143,6 +143,23 @@ class NetFH(Thread):
for pos in self.__dictdirty:
self.set_dirtybytes(pos, self.__dictdirty[pos])
def _direct_send(self, send_bytes, recv_count):
"""Fuer debugging direktes Senden von Daten.
@param send_bytes Bytes, die gesendet werden sollen
@param recv_count Anzahl der Empfangsbytes
@returns Empfangende Bytes
"""
if self.__sockend:
raise ValueError("I/O operation on closed file")
with self.__socklock:
self._slavesock.sendall(send_bytes)
recv = self._slavesock.recv(recv_count)
self.__trigger = True
return recv
def clear_dirtybytes(self, position=None):
"""Entfernt die konfigurierten Dirtybytes vom RevPi Slave.
@param position Startposition der Dirtybytes"""
@@ -251,7 +268,7 @@ class NetFH(Thread):
raise ValueError("read of closed file")
if not (isinstance(arg, bytes) and len(arg) <= 1024):
raise ValueError("arg must be <class 'bytes'>")
raise TypeError("arg must be <class 'bytes'>")
with self.__socklock:
self._slavesock.send(
@@ -500,11 +517,11 @@ class RevPiNetIO(_RevPiModIO):
self._address = address
else:
raise ValueError(
raise TypeError(
"address tuple must be (<class 'str'>, <class 'int'>)"
)
else:
raise ValueError(
raise TypeError(
"parameter address must be <class 'str'> or <class 'tuple'> "
"like (<class 'str'>, <class 'int'>)"
)
@@ -663,7 +680,7 @@ class RevPiNetIOSelected(RevPiNetIO):
for vdev in self._lst_devselect:
if type(vdev) != int and type(vdev) != str:
raise ValueError(
raise TypeError(
"need device position as <class 'int'> or device name as "
"<class 'str'>"
)