mirror of
https://github.com/naruxde/revpimodio2.git
synced 2025-11-08 22:03:53 +01:00
Errortypen angepasst
NetFh.__init__ Parameterprüfung geändert NetFh._direct_send implementiert
This commit is contained in:
@@ -80,6 +80,9 @@ Methods</h3>
|
|||||||
<td><a style="color:#0000FF" href="#NetFH._connect">_connect</a></td>
|
<td><a style="color:#0000FF" href="#NetFH._connect">_connect</a></td>
|
||||||
<td>Stellt die Verbindung zu einem RevPiSlave her.</td>
|
<td>Stellt die Verbindung zu einem RevPiSlave her.</td>
|
||||||
</tr><tr>
|
</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><a style="color:#0000FF" href="#NetFH.clear_dirtybytes">clear_dirtybytes</a></td>
|
||||||
<td>Entfernt die konfigurierten Dirtybytes vom RevPi Slave.</td>
|
<td>Entfernt die konfigurierten Dirtybytes vom RevPi Slave.</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
@@ -174,7 +177,26 @@ NetFH._connect</h3>
|
|||||||
<b>_connect</b>(<i></i>)
|
<b>_connect</b>(<i></i>)
|
||||||
<p>
|
<p>
|
||||||
Stellt die Verbindung zu einem RevPiSlave her.
|
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">
|
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||||
NetFH.clear_dirtybytes</h3>
|
NetFH.clear_dirtybytes</h3>
|
||||||
<b>clear_dirtybytes</b>(<i>position=None</i>)
|
<b>clear_dirtybytes</b>(<i>position=None</i>)
|
||||||
|
|||||||
@@ -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.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.RevPiModIOSelected?1(deviceselection, autorefresh=False, monitoring=False, syncoutputs=True, procimg=None, configrsc=None, simulator=False)
|
||||||
revpimodio2.netio.NetFH._connect?5()
|
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.clear_dirtybytes?4(position=None)
|
||||||
revpimodio2.netio.NetFH.close?4()
|
revpimodio2.netio.NetFH.close?4()
|
||||||
revpimodio2.netio.NetFH.closed?7
|
revpimodio2.netio.NetFH.closed?7
|
||||||
|
|||||||
@@ -403,7 +403,7 @@ class ProcimgWriter(Thread):
|
|||||||
@param value True aktiviert / False deaktiviert
|
@param value True aktiviert / False deaktiviert
|
||||||
@return True, wenn Anforderung erfolgreich war"""
|
@return True, wenn Anforderung erfolgreich war"""
|
||||||
if type(value) != bool:
|
if type(value) != bool:
|
||||||
raise ValueError("value must be <class 'bool'>")
|
raise TypeError("value must be <class 'bool'>")
|
||||||
|
|
||||||
# Nur starten, wenn System läuft
|
# Nur starten, wenn System läuft
|
||||||
if not self.is_alive():
|
if not self.is_alive():
|
||||||
@@ -561,10 +561,13 @@ class ProcimgWriter(Thread):
|
|||||||
def set_maxioerrors(self, value):
|
def set_maxioerrors(self, value):
|
||||||
"""Setzt die Anzahl der maximal erlaubten Fehler.
|
"""Setzt die Anzahl der maximal erlaubten Fehler.
|
||||||
@param value Anzahl erlaubte Fehler"""
|
@param value Anzahl erlaubte Fehler"""
|
||||||
if type(value) == int and value >= 0:
|
if type(value) == int:
|
||||||
|
if value >= 0:
|
||||||
self._maxioerrors = value
|
self._maxioerrors = value
|
||||||
else:
|
else:
|
||||||
raise ValueError("value must be 0 or a positive integer")
|
raise ValueError("value must be 0 or a positive integer")
|
||||||
|
else:
|
||||||
|
raise TypeError("value must be <class 'int'>")
|
||||||
|
|
||||||
def set_refresh(self, value):
|
def set_refresh(self, value):
|
||||||
"""Setzt die Zykluszeit in Millisekunden.
|
"""Setzt die Zykluszeit in Millisekunden.
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ class IOList(object):
|
|||||||
]:
|
]:
|
||||||
object.__setattr__(self, key, value)
|
object.__setattr__(self, key, value)
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise AttributeError(
|
||||||
"direct assignment is not supported - use .value Attribute"
|
"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
|
self.__dict_iobyte[new_io.address][new_io._bitaddress] = new_io
|
||||||
else:
|
else:
|
||||||
raise AttributeError("io must be <class 'IOBase'> or sub class")
|
raise TypeError("io must be <class 'IOBase'> or sub class")
|
||||||
|
|
||||||
|
|
||||||
class DeadIO(object):
|
class DeadIO(object):
|
||||||
@@ -380,15 +380,15 @@ class IOBase(object):
|
|||||||
"""
|
"""
|
||||||
# Prüfen ob Funktion callable ist
|
# Prüfen ob Funktion callable ist
|
||||||
if not callable(func):
|
if not callable(func):
|
||||||
raise AttributeError(
|
raise ValueError(
|
||||||
"registered function '{0}' is not callable".format(func)
|
"registered function '{0}' is not callable".format(func)
|
||||||
)
|
)
|
||||||
if type(delay) != int or delay < 0:
|
if type(delay) != int or delay < 0:
|
||||||
raise AttributeError(
|
raise ValueError(
|
||||||
"'delay' must be <class 'int'> and greater or equal 0"
|
"'delay' must be <class 'int'> and greater or equal 0"
|
||||||
)
|
)
|
||||||
if edge != BOTH and self._bitaddress < 0:
|
if edge != BOTH and self._bitaddress < 0:
|
||||||
raise AttributeError(
|
raise ValueError(
|
||||||
"parameter 'edge' can be used with bit io objects only"
|
"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 edge == BOTH or regfunc.edge == BOTH:
|
||||||
if self._bitaddress < 0:
|
if self._bitaddress < 0:
|
||||||
raise AttributeError(
|
raise RuntimeError(
|
||||||
"io '{0}' with function '{1}' already in list."
|
"io '{0}' with function '{1}' already in list."
|
||||||
"".format(self._name, func)
|
"".format(self._name, func)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise AttributeError(
|
raise RuntimeError(
|
||||||
"io '{0}' with function '{1}' already in list "
|
"io '{0}' with function '{1}' already in list "
|
||||||
"with edge '{2}' - edge '{3}' not allowed anymore"
|
"with edge '{2}' - edge '{3}' not allowed anymore"
|
||||||
"".format(
|
"".format(
|
||||||
@@ -419,7 +419,7 @@ class IOBase(object):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif regfunc.edge == edge:
|
elif regfunc.edge == edge:
|
||||||
raise AttributeError(
|
raise RuntimeError(
|
||||||
"io '{0}' with function '{1}' for given edge '{2}' "
|
"io '{0}' with function '{1}' for given edge '{2}' "
|
||||||
"already in list".format(
|
"already in list".format(
|
||||||
self._name, func, consttostr(edge)
|
self._name, func, consttostr(edge)
|
||||||
@@ -543,24 +543,24 @@ class IOBase(object):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise TypeError(
|
||||||
"'{0}' requires a <class 'bytes'> object, not {1}"
|
"'{0}' requires a <class 'bytes'> object, not {1}"
|
||||||
"".format(self._name, type(value))
|
"".format(self._name, type(value))
|
||||||
)
|
)
|
||||||
|
|
||||||
elif self._iotype == INP:
|
elif self._iotype == INP:
|
||||||
if self._parentdevice._modio._simulator:
|
if self._parentdevice._modio._simulator:
|
||||||
raise AttributeError(
|
raise RuntimeError(
|
||||||
"can not write to output '{0}' in simulator mode"
|
"can not write to output '{0}' in simulator mode"
|
||||||
"".format(self._name)
|
"".format(self._name)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise AttributeError(
|
raise RuntimeError(
|
||||||
"can not write to input '{0}'".format(self._name)
|
"can not write to input '{0}'".format(self._name)
|
||||||
)
|
)
|
||||||
|
|
||||||
elif self._iotype == MEM:
|
elif self._iotype == MEM:
|
||||||
raise AttributeError(
|
raise RuntimeError(
|
||||||
"can not write to memory '{0}'".format(self._name)
|
"can not write to memory '{0}'".format(self._name)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -640,20 +640,20 @@ class IOBase(object):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
if not (RISING <= edge <= BOTH):
|
if not (RISING <= edge <= BOTH):
|
||||||
raise AttributeError(
|
raise ValueError(
|
||||||
"parameter 'edge' must be revpimodio2.RISING, "
|
"parameter 'edge' must be revpimodio2.RISING, "
|
||||||
"revpimodio2.FALLING or revpimodio2.BOTH"
|
"revpimodio2.FALLING or revpimodio2.BOTH"
|
||||||
)
|
)
|
||||||
if not (exitevent is None or type(exitevent) == Event):
|
if not (exitevent is None or type(exitevent) == Event):
|
||||||
raise AttributeError(
|
raise TypeError(
|
||||||
"parameter 'exitevent' must be <class 'threading.Event'>"
|
"parameter 'exitevent' must be <class 'threading.Event'>"
|
||||||
)
|
)
|
||||||
if type(timeout) != int or timeout < 0:
|
if type(timeout) != int or timeout < 0:
|
||||||
raise AttributeError(
|
raise ValueError(
|
||||||
"parameter 'timeout' must be <class 'int'> and greater than 0"
|
"parameter 'timeout' must be <class 'int'> and greater than 0"
|
||||||
)
|
)
|
||||||
if edge != BOTH and self._bitaddress < 0:
|
if edge != BOTH and self._bitaddress < 0:
|
||||||
raise AttributeError(
|
raise ValueError(
|
||||||
"parameter 'edge' can be used with bit Inputs only"
|
"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.
|
"""Left fest, ob der Wert Vorzeichenbehaftet behandelt werden soll.
|
||||||
@param value True, wenn mit Vorzeichen behandel"""
|
@param value True, wenn mit Vorzeichen behandel"""
|
||||||
if type(value) != bool:
|
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
|
self._signed = value
|
||||||
|
|
||||||
def get_intdefaultvalue(self):
|
def get_intdefaultvalue(self):
|
||||||
@@ -781,7 +781,7 @@ class IntIO(IOBase):
|
|||||||
signed=self._signed
|
signed=self._signed
|
||||||
))
|
))
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise TypeError(
|
||||||
"'{0}' need a <class 'int'> value, but {1} was given"
|
"'{0}' need a <class 'int'> value, but {1} was given"
|
||||||
"".format(self._name, type(value))
|
"".format(self._name, type(value))
|
||||||
)
|
)
|
||||||
@@ -825,7 +825,7 @@ class IntIOCounter(IntIO):
|
|||||||
"can not reset counter, while system is in monitoring mode"
|
"can not reset counter, while system is in monitoring mode"
|
||||||
)
|
)
|
||||||
if self._parentdevice._modio._simulator:
|
if self._parentdevice._modio._simulator:
|
||||||
raise AttributeError(
|
raise RuntimeError(
|
||||||
"can not reset counter, while system is in simulator mode"
|
"can not reset counter, while system is in simulator mode"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -841,7 +841,10 @@ class IntIOCounter(IntIO):
|
|||||||
|
|
||||||
elif self._parentdevice._modio._procimg != "/dev/piControl0":
|
elif self._parentdevice._modio._procimg != "/dev/piControl0":
|
||||||
# NOTE: Soll hier eine 0 in den Input geschrieben werden?
|
# 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:
|
else:
|
||||||
# IOCTL auf dem RevPi
|
# IOCTL auf dem RevPi
|
||||||
@@ -957,7 +960,7 @@ class StructIO(IOBase):
|
|||||||
bitaddress = kwargs.get("bit", 0)
|
bitaddress = kwargs.get("bit", 0)
|
||||||
max_bits = parentio._length * 8
|
max_bits = parentio._length * 8
|
||||||
if not (0 <= bitaddress < max_bits):
|
if not (0 <= bitaddress < max_bits):
|
||||||
raise AttributeError(
|
raise ValueError(
|
||||||
"bitaddress must be a value between 0 and {0}"
|
"bitaddress must be a value between 0 and {0}"
|
||||||
"".format(max_bits - 1)
|
"".format(max_bits - 1)
|
||||||
)
|
)
|
||||||
@@ -986,7 +989,7 @@ class StructIO(IOBase):
|
|||||||
bitaddress
|
bitaddress
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
raise AttributeError(
|
raise ValueError(
|
||||||
"parameter frm has to be a single sign or 'COUNTs' e.g. '8s'"
|
"parameter frm has to be a single sign or 'COUNTs' e.g. '8s'"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -321,14 +321,12 @@ class RevPiModIO(object):
|
|||||||
self._ioerror += 1
|
self._ioerror += 1
|
||||||
if self._maxioerrors != 0 and self._ioerror >= self._maxioerrors:
|
if self._maxioerrors != 0 and self._ioerror >= self._maxioerrors:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"reach max io error count {0} on process image".format(
|
"reach max io error count {0} on process image"
|
||||||
self._maxioerrors
|
"".format(self._maxioerrors)
|
||||||
)
|
|
||||||
)
|
)
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"got io error during {0} and count {1} errors now".format(
|
"got io error during {0} and count {1} errors now"
|
||||||
action, self._ioerror
|
"".format(action, self._ioerror),
|
||||||
),
|
|
||||||
RuntimeWarning
|
RuntimeWarning
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -45,13 +45,6 @@ class NetFH(Thread):
|
|||||||
"""Init NetFH-class.
|
"""Init NetFH-class.
|
||||||
@param address IP Adresse, Port des RevPi als <class 'tuple'>
|
@param address IP Adresse, Port des RevPi als <class 'tuple'>
|
||||||
@param timeout Timeout in Millisekunden der Verbindung"""
|
@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__()
|
super().__init__()
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
|
|
||||||
@@ -66,11 +59,18 @@ class NetFH(Thread):
|
|||||||
self.__timeout = None
|
self.__timeout = None
|
||||||
self.__trigger = False
|
self.__trigger = False
|
||||||
self.__waitsync = None
|
self.__waitsync = None
|
||||||
|
|
||||||
# Verbindung herstellen
|
|
||||||
self._address = address
|
self._address = address
|
||||||
self._slavesock = None
|
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.__set_systimeout(timeout)
|
||||||
self._connect()
|
self._connect()
|
||||||
|
|
||||||
@@ -143,6 +143,23 @@ class NetFH(Thread):
|
|||||||
for pos in self.__dictdirty:
|
for pos in self.__dictdirty:
|
||||||
self.set_dirtybytes(pos, self.__dictdirty[pos])
|
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):
|
def clear_dirtybytes(self, position=None):
|
||||||
"""Entfernt die konfigurierten Dirtybytes vom RevPi Slave.
|
"""Entfernt die konfigurierten Dirtybytes vom RevPi Slave.
|
||||||
@param position Startposition der Dirtybytes"""
|
@param position Startposition der Dirtybytes"""
|
||||||
@@ -251,7 +268,7 @@ class NetFH(Thread):
|
|||||||
raise ValueError("read of closed file")
|
raise ValueError("read of closed file")
|
||||||
|
|
||||||
if not (isinstance(arg, bytes) and len(arg) <= 1024):
|
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:
|
with self.__socklock:
|
||||||
self._slavesock.send(
|
self._slavesock.send(
|
||||||
@@ -500,11 +517,11 @@ class RevPiNetIO(_RevPiModIO):
|
|||||||
|
|
||||||
self._address = address
|
self._address = address
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise TypeError(
|
||||||
"address tuple must be (<class 'str'>, <class 'int'>)"
|
"address tuple must be (<class 'str'>, <class 'int'>)"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise TypeError(
|
||||||
"parameter address must be <class 'str'> or <class 'tuple'> "
|
"parameter address must be <class 'str'> or <class 'tuple'> "
|
||||||
"like (<class 'str'>, <class 'int'>)"
|
"like (<class 'str'>, <class 'int'>)"
|
||||||
)
|
)
|
||||||
@@ -663,7 +680,7 @@ class RevPiNetIOSelected(RevPiNetIO):
|
|||||||
|
|
||||||
for vdev in self._lst_devselect:
|
for vdev in self._lst_devselect:
|
||||||
if type(vdev) != int and type(vdev) != str:
|
if type(vdev) != int and type(vdev) != str:
|
||||||
raise ValueError(
|
raise TypeError(
|
||||||
"need device position as <class 'int'> or device name as "
|
"need device position as <class 'int'> or device name as "
|
||||||
"<class 'str'>"
|
"<class 'str'>"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user