mirror of
https://github.com/naruxde/revpipyload.git
synced 2025-11-08 23:23:52 +01:00
Sync Paket verarbeiten
Timeouts verarbeiten und das Socket Objekt auf diesen einstellen
This commit is contained in:
@@ -51,10 +51,10 @@ Classes</h3>
|
|||||||
<td>Hauptklasse, die alle Funktionen zur Verfuegung stellt.</td>
|
<td>Hauptklasse, die alle Funktionen zur Verfuegung stellt.</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td><a style="color:#0000FF" href="#RevPiSlave">RevPiSlave</a></td>
|
<td><a style="color:#0000FF" href="#RevPiSlave">RevPiSlave</a></td>
|
||||||
<td></td>
|
<td>RevPi PLC-Server.</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<td><a style="color:#0000FF" href="#RevPiSlaveDev">RevPiSlaveDev</a></td>
|
<td><a style="color:#0000FF" href="#RevPiSlaveDev">RevPiSlaveDev</a></td>
|
||||||
<td></td>
|
<td>Klasse um eine RevPiModIO Verbindung zu verwalten.</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||||
@@ -828,7 +828,16 @@ Statuscode:
|
|||||||
<hr /><hr />
|
<hr /><hr />
|
||||||
<a NAME="RevPiSlave" ID="RevPiSlave"></a>
|
<a NAME="RevPiSlave" ID="RevPiSlave"></a>
|
||||||
<h2 style="background-color:#FFFFFF;color:#0000FF">RevPiSlave</h2>
|
<h2 style="background-color:#FFFFFF;color:#0000FF">RevPiSlave</h2>
|
||||||
|
<p>
|
||||||
|
RevPi PLC-Server.
|
||||||
|
</p><p>
|
||||||
|
Diese Klasste stellt den RevPi PLC-Server zur verfuegung und akzeptiert
|
||||||
|
neue Verbindungen. Dieser werden dann als RevPiSlaveDev abgebildet.
|
||||||
|
</p><p>
|
||||||
|
Ueber die angegebenen ACLs koennen Zugriffsbeschraenkungen vergeben werden.
|
||||||
|
</p><p>
|
||||||
|
|
||||||
|
</p>
|
||||||
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||||
Derived from</h3>
|
Derived from</h3>
|
||||||
Thread
|
Thread
|
||||||
@@ -901,7 +910,14 @@ Beendet Slaveausfuehrung.
|
|||||||
<hr /><hr />
|
<hr /><hr />
|
||||||
<a NAME="RevPiSlaveDev" ID="RevPiSlaveDev"></a>
|
<a NAME="RevPiSlaveDev" ID="RevPiSlaveDev"></a>
|
||||||
<h2 style="background-color:#FFFFFF;color:#0000FF">RevPiSlaveDev</h2>
|
<h2 style="background-color:#FFFFFF;color:#0000FF">RevPiSlaveDev</h2>
|
||||||
|
<p>
|
||||||
|
Klasse um eine RevPiModIO Verbindung zu verwalten.
|
||||||
|
</p><p>
|
||||||
|
Diese Klasste stellt die Funktionen zur Verfuegung um Daten ueber das
|
||||||
|
Netzwerk mit dem Prozessabbild auszutauschen.
|
||||||
|
</p><p>
|
||||||
|
|
||||||
|
</p>
|
||||||
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||||
Derived from</h3>
|
Derived from</h3>
|
||||||
Thread
|
Thread
|
||||||
@@ -937,7 +953,7 @@ Static Methods</h3>
|
|||||||
<a NAME="RevPiSlaveDev.__init__" ID="RevPiSlaveDev.__init__"></a>
|
<a NAME="RevPiSlaveDev.__init__" ID="RevPiSlaveDev.__init__"></a>
|
||||||
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||||
RevPiSlaveDev (Constructor)</h3>
|
RevPiSlaveDev (Constructor)</h3>
|
||||||
<b>RevPiSlaveDev</b>(<i>devcon, deadtime, acl</i>)
|
<b>RevPiSlaveDev</b>(<i>devcon, acl</i>)
|
||||||
<p>
|
<p>
|
||||||
Init RevPiSlaveDev-Class.
|
Init RevPiSlaveDev-Class.
|
||||||
</p><dl>
|
</p><dl>
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ revpipyload.RevPiSlave.stop?4()
|
|||||||
revpipyload.RevPiSlave?1(acl, port=55234)
|
revpipyload.RevPiSlave?1(acl, port=55234)
|
||||||
revpipyload.RevPiSlaveDev.run?4()
|
revpipyload.RevPiSlaveDev.run?4()
|
||||||
revpipyload.RevPiSlaveDev.stop?4()
|
revpipyload.RevPiSlaveDev.stop?4()
|
||||||
revpipyload.RevPiSlaveDev?1(devcon, deadtime, acl)
|
revpipyload.RevPiSlaveDev?1(devcon, acl)
|
||||||
revpipyload._ipmatch?5(ipaddress, dict_acl)
|
revpipyload._ipmatch?5(ipaddress, dict_acl)
|
||||||
revpipyload._zeroprocimg?5()
|
revpipyload._zeroprocimg?5()
|
||||||
revpipyload.configrsc?7
|
revpipyload.configrsc?7
|
||||||
|
|||||||
@@ -467,12 +467,20 @@ class RevPiPlc(Thread):
|
|||||||
|
|
||||||
class RevPiSlave(Thread):
|
class RevPiSlave(Thread):
|
||||||
|
|
||||||
|
"""RevPi PLC-Server.
|
||||||
|
|
||||||
|
Diese Klasste stellt den RevPi PLC-Server zur verfuegung und akzeptiert
|
||||||
|
neue Verbindungen. Dieser werden dann als RevPiSlaveDev abgebildet.
|
||||||
|
|
||||||
|
Ueber die angegebenen ACLs koennen Zugriffsbeschraenkungen vergeben werden.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, acl, port=55234):
|
def __init__(self, acl, port=55234):
|
||||||
"""Instantiiert RevPiSlave-Klasse.
|
"""Instantiiert RevPiSlave-Klasse.
|
||||||
@param acl Stringliste mit Leerstellen getrennt
|
@param acl Stringliste mit Leerstellen getrennt
|
||||||
@param port Listen Port fuer plc Slaveserver"""
|
@param port Listen Port fuer plc Slaveserver"""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.deadtime = 0.5
|
|
||||||
self._evt_exit = Event()
|
self._evt_exit = Event()
|
||||||
self.exitcode = None
|
self.exitcode = None
|
||||||
self._port = port
|
self._port = port
|
||||||
@@ -531,7 +539,7 @@ class RevPiSlave(Thread):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# Thread starten
|
# Thread starten
|
||||||
th = RevPiSlaveDev(tup_sock, self.deadtime, aclstatus)
|
th = RevPiSlaveDev(tup_sock, aclstatus)
|
||||||
th.start()
|
th.start()
|
||||||
self._th_dev.append(th)
|
self._th_dev.append(th)
|
||||||
|
|
||||||
@@ -558,14 +566,24 @@ class RevPiSlave(Thread):
|
|||||||
|
|
||||||
self._evt_exit.set()
|
self._evt_exit.set()
|
||||||
if self.so is not None:
|
if self.so is not None:
|
||||||
self.so.shutdown(socket.SHUT_RDWR)
|
try:
|
||||||
|
self.so.shutdown(socket.SHUT_RDWR)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
proginit.logger.debug("leave RevPiSlave.stop()")
|
proginit.logger.debug("leave RevPiSlave.stop()")
|
||||||
|
|
||||||
|
|
||||||
class RevPiSlaveDev(Thread):
|
class RevPiSlaveDev(Thread):
|
||||||
|
|
||||||
def __init__(self, devcon, deadtime, acl):
|
"""Klasse um eine RevPiModIO Verbindung zu verwalten.
|
||||||
|
|
||||||
|
Diese Klasste stellt die Funktionen zur Verfuegung um Daten ueber das
|
||||||
|
Netzwerk mit dem Prozessabbild auszutauschen.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, devcon, acl):
|
||||||
"""Init RevPiSlaveDev-Class.
|
"""Init RevPiSlaveDev-Class.
|
||||||
|
|
||||||
@param devcon Tuple der Verbindung
|
@param devcon Tuple der Verbindung
|
||||||
@@ -576,7 +594,7 @@ class RevPiSlaveDev(Thread):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self._acl = acl
|
self._acl = acl
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
self._deadtime = deadtime
|
self._deadtime = None
|
||||||
self._devcon, self._addr = devcon
|
self._devcon, self._addr = devcon
|
||||||
self._evt_exit = Event()
|
self._evt_exit = Event()
|
||||||
|
|
||||||
@@ -589,11 +607,6 @@ class RevPiSlaveDev(Thread):
|
|||||||
self._addr, self._acl)
|
self._addr, self._acl)
|
||||||
)
|
)
|
||||||
|
|
||||||
# CMDs anhand ACL aufbauen
|
|
||||||
msgcli = [b'DA', b'PI', b'\x06\x16']
|
|
||||||
if self._acl == 1:
|
|
||||||
msgcli.append(b'SD')
|
|
||||||
|
|
||||||
# Prozessabbild öffnen
|
# Prozessabbild öffnen
|
||||||
fh_proc = open(procimg, "r+b", 0)
|
fh_proc = open(procimg, "r+b", 0)
|
||||||
|
|
||||||
@@ -615,16 +628,8 @@ class RevPiSlaveDev(Thread):
|
|||||||
)
|
)
|
||||||
break
|
break
|
||||||
|
|
||||||
# CMD prüfen
|
|
||||||
cmd = netcmd[1:3]
|
cmd = netcmd[1:3]
|
||||||
if cmd not in msgcli:
|
if cmd == b'DA':
|
||||||
break
|
|
||||||
|
|
||||||
if cmd == b'\x06\x16':
|
|
||||||
# Just sync
|
|
||||||
pass
|
|
||||||
|
|
||||||
elif cmd == b'DA':
|
|
||||||
# Processabbild übertragen
|
# Processabbild übertragen
|
||||||
# bCMiiii00000000b = 16
|
# bCMiiii00000000b = 16
|
||||||
|
|
||||||
@@ -638,8 +643,8 @@ class RevPiSlaveDev(Thread):
|
|||||||
proginit.logger.error("error while send read data")
|
proginit.logger.error("error while send read data")
|
||||||
break
|
break
|
||||||
|
|
||||||
elif cmd == b'SD':
|
elif cmd == b'SD' and self._acl == 1:
|
||||||
# Ausgänge empfangen
|
# Ausgänge empfangen, wenn acl es erlaubt
|
||||||
# bCMiiii00000000b = 16
|
# bCMiiii00000000b = 16
|
||||||
|
|
||||||
position = int.from_bytes(netcmd[3:5], byteorder="little")
|
position = int.from_bytes(netcmd[3:5], byteorder="little")
|
||||||
@@ -662,6 +667,22 @@ class RevPiSlaveDev(Thread):
|
|||||||
# Record seperator character
|
# Record seperator character
|
||||||
self._devcon.send(b'\x1e')
|
self._devcon.send(b'\x1e')
|
||||||
|
|
||||||
|
elif cmd == b'\x06\x16':
|
||||||
|
# Just sync
|
||||||
|
self._devcon.send(b'\x06\x16')
|
||||||
|
|
||||||
|
elif cmd == b'CF':
|
||||||
|
# Socket konfigurieren
|
||||||
|
# bCMii0000000000b = 16
|
||||||
|
|
||||||
|
timeoutms = int.from_bytes(netcmd[3:5], byteorder="little")
|
||||||
|
|
||||||
|
self._deadtime = timeoutms / 1000
|
||||||
|
self._devcon.settimeout(self._deadtime)
|
||||||
|
|
||||||
|
# Record seperator character
|
||||||
|
self._devcon.send(b'\x1e')
|
||||||
|
|
||||||
elif cmd == b'PI':
|
elif cmd == b'PI':
|
||||||
# piCtory Konfiguration senden
|
# piCtory Konfiguration senden
|
||||||
proginit.logger.debug(
|
proginit.logger.debug(
|
||||||
@@ -680,14 +701,20 @@ class RevPiSlaveDev(Thread):
|
|||||||
self._devcon.send(b'\x04')
|
self._devcon.send(b'\x04')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Kein gültiges CMD gefunden, abbruch!
|
||||||
|
break
|
||||||
|
|
||||||
# Verarbeitungszeit prüfen
|
# Verarbeitungszeit prüfen
|
||||||
comtime = default_timer() - ot
|
if self._deadtime is not None:
|
||||||
if comtime > self._deadtime:
|
comtime = default_timer() - ot
|
||||||
proginit.logger.warning(
|
if comtime > self._deadtime:
|
||||||
"runtime more than {} ms: {}".format(
|
proginit.logger.warning(
|
||||||
int(self._deadtime * 1000), int(comtime * 1000)
|
"runtime more than {} ms: {}!".format(
|
||||||
|
int(self._deadtime * 1000), comtime
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
# TODO: Soll ein Fehler ausgelöst werden?
|
||||||
|
|
||||||
fh_proc.close()
|
fh_proc.close()
|
||||||
self._devcon.close()
|
self._devcon.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user