Disconnect on alive signal error#29
Conversation
Pull latest changes
|
Hi Mathias, thanks for the reply and for the amazing work with node-snap7! Having read your comment, the call |
|
The issue with raw sockets is that the software does not get any information by the system if the socket is timed out or disconnected until you actually try to write or read to that socket. Most user software or higher level network APIs implement a Ping/pong mechanic to get information about the status of the connection. That is what @psi-4ward implemented here with the PlcStatus(). |
|
Ok, but the problem is that the node-snap7 client doesn't seem to change the status itself. However, when s7client writes with the PlcStatus(), it gets an error, which it is currently ignoring. I feel we should not ignore this error. Do you think that the proposed change is useful then? |
|
I think about a more generic solution: protected _getErr(s7err: number | string[]): Error {
if (Array.isArray(s7err)) return new Error(`${ this.opts.name } Errors: ` + s7err.join('; '));
const errStr = this.client.ErrorText(s7err).trim();
if(errStr.includes('TCP : ') && this.client.Connected()) {
debug(`Set disconnected cause of TCP Error`);
this.client.Disconnect();
}
return new Error(`${ this.opts.name }: ` + errStr);
}Ie, manually disconnect on every single TCP error. |
Hallo Christoph,
wir haben festgestellt, dass im Falle eines Kontaktabbruchs (Strom aus, Stecker wird rausgezogen, Netzwerk wird gewechselt, etc.) zwischen dem Client und der SPS kein "disconnect" Event gefeuert wird. Scheinbar bekommt der client von node-snap7 das nicht mit und daher wird in Zeile 133 bei client.Connected() noch true zurückgegeben. Damit ist die Verbindung dauerhaft weg, auch wenn die SPS wieder online ist.
Wenn manuell disconnected wird, kann das Problem umgangen werden.
Das Problem kann z.B. reproduziert weden, indem der Server in einem anderen Prozess gestartet und dann gekillt wird.
Ich werde versuchen, unit tests dafür zu schreiben, wäre aber dankbar, wenn du Zeit findest dir das kurz anzuschauen.
Viele Grüße
Chris