diff --git a/doc/revpimodio2.netio.html b/doc/revpimodio2.netio.html index 58f6735..9a11e8f 100644 --- a/doc/revpimodio2.netio.html +++ b/doc/revpimodio2.netio.html @@ -80,6 +80,9 @@ Methods _connect Stellt die Verbindung zu einem RevPiSlave her. +_direct_send +Fuer debugging direktes Senden von Daten. + clear_dirtybytes Entfernt die konfigurierten Dirtybytes vom RevPi Slave. @@ -174,7 +177,26 @@ NetFH._connect _connect()

Stellt die Verbindung zu einem RevPiSlave her. -

+

+

+NetFH._direct_send

+_direct_send(send_bytes, recv_count) +

+Fuer debugging direktes Senden von Daten. +

+
send_bytes
+
+Bytes, die gesendet werden sollen +
recv_count
+
+Anzahl der Empfangsbytes +
+
+
Returns:
+
+Empfangende Bytes +
+

NetFH.clear_dirtybytes

clear_dirtybytes(position=None) diff --git a/eric-revpimodio2.api b/eric-revpimodio2.api index 2a52b49..9f887cb 100644 --- a/eric-revpimodio2.api +++ b/eric-revpimodio2.api @@ -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 diff --git a/revpimodio2/helper.py b/revpimodio2/helper.py index 5405082..328bafe 100644 --- a/revpimodio2/helper.py +++ b/revpimodio2/helper.py @@ -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 ") + raise TypeError("value must be ") # 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 ") def set_refresh(self, value): """Setzt die Zykluszeit in Millisekunden. diff --git a/revpimodio2/io.py b/revpimodio2/io.py index 5e7ca21..2a203d8 100644 --- a/revpimodio2/io.py +++ b/revpimodio2/io.py @@ -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 or sub class") + raise TypeError("io must be 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 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 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 " ) if type(timeout) != int or timeout < 0: - raise AttributeError( + raise ValueError( "parameter 'timeout' must be 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 True or False") + raise TypeError("signed must be 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 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'" ) diff --git a/revpimodio2/modio.py b/revpimodio2/modio.py index af85b87..dc870da 100644 --- a/revpimodio2/modio.py +++ b/revpimodio2/modio.py @@ -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 ) diff --git a/revpimodio2/netio.py b/revpimodio2/netio.py index 7b231db..04cdd2b 100644 --- a/revpimodio2/netio.py +++ b/revpimodio2/netio.py @@ -45,13 +45,6 @@ class NetFH(Thread): """Init NetFH-class. @param address IP Adresse, Port des RevPi als @param timeout Timeout in Millisekunden der Verbindung""" - if not isinstance(address, tuple): - raise ValueError( - "parameter address must be ('IP', PORT)" - ) - if not isinstance(timeout, int): - raise ValueError("parameter timeout must be ") - 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 ('IP', PORT)" + ) + if not isinstance(timeout, int): + raise TypeError("parameter timeout must be ") + + # 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 ") + raise TypeError("arg must be ") 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 (, )" ) else: - raise ValueError( + raise TypeError( "parameter address must be or " "like (, )" ) @@ -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 or device name as " "" )