-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
S7 Client returns invalid Connected status #51
Comments
Hi, |
Thank you @mathiask88 for the response. Not sure if I'm doing something wrong but with the code bellow, const snap7 = require('node-snap7');
const S7Client = new snap7.S7Client();
function readDb(readCnt) {
const res = S7Client.DBRead(2, 10, 2);
if (res === false) {
console.error(`Unable to read from DB [${readCnt}]`);
return;
}
console.log(`Result[${readCnt}]: ${res.readUInt16BE(0)}`);
}
S7Client.ConnectTo('192.168.1.40', 0, 1, function (err) {
if (err) {
console.error(' >> Connection failed. Code #' + err + ' - ' + S7Client.ErrorText(err));
return false;
}
console.log(`Connected[1]: ${S7Client.Connected()}`);
readDb(1);
console.log(`Connected[2]: ${S7Client.Connected()}`);
setTimeout(function () {
readDb(2);
console.log(`Connected[3]: ${S7Client.Connected()}`);
}, 10000);
});
process.on('SIGINT', function () {
S7Client.Disconnect();
}); and the output is: Connected[1]: true
Result[1]: 23
Connected[2]: true
Unable to read from DB [2]
Connected[3]: true If I manually call |
Sorry, I've currently no test setup ready. I'll search for my S7-1500 in the cellar and test it next week :) |
I think the same behavior is reported in python wrapper for snap7 - gijzelaerr/python-snap7#111 . Their conclusion is that this is a bug in the snap7 lib. |
Can you write out the |
Error code is |
Now we can discuss if a |
Yes, that's exactly what I have done, it was a minor design change. :) I can make another test day after tomorrow and check if the client is able to read after timeout error occurs and the connection is established again. If it fails to read, from my point of view, WSAETIMEDOUT should be considered as "disconnected". What do you think? Does that make sense to you? |
@leovujanic What was the result, can this be closed? |
Hi @mathiask88 , sorry for not replying, I was tight with time and didn't manage to test it in an isolated environment. I will do it through the weekend and reply. |
Hi @mathiask88 , I apologize for the late reply. I've made a few tests and the conclusion is that the client can recover from This is the code: const snap7 = require('node-snap7');
const S7Client = new snap7.S7Client();
let interval = null;
function readDb(readCnt) {
const res = S7Client.DBRead(2, 250.0, 2);
if (res === false) {
console.error(`Unable to read from DB [${readCnt}] ${S7Client.ErrorText(S7Client.LastError())} | ${S7Client.LastError()}`);
return;
}
console.log(`Result[${readCnt}]: ${res.readUInt16BE(0)}`);
}
S7Client.ConnectTo('192.168.1.40', 0, 1, function(err) {
if (err) {
console.error(' >> Connection failed. Code #' + err + ' - ' + S7Client.ErrorText(err));
console.log(`Connected[2]: ${S7Client.Connected()}`);
return false;
}
readDb(1);
console.log(`Connected[1]: ${S7Client.Connected()}`);
setTimeout(function() {
// take time to disconnect
let cnt = 2;
interval = setInterval(() => {
readDb(cnt);
console.log(`Connected[${cnt}]: ${S7Client.Connected()}`);
cnt++;
}, 1000);
}, 6000);
});
process.on('SIGINT', function() {
console.log("Caught interrupt signal");
clearInterval(interval);
S7Client.Disconnect();
}); and output example (connect -> timeout -> reconnect -> disconnect): Result[1]: 0
Connected[1]: true
Unable to read from DB [2] ISO : An error occurred during recv TCP : Connection timed out
Connected[2]: true
Unable to read from DB [3] ISO : An error occurred during recv TCP : Connection timed out
Connected[3]: true
Unable to read from DB [4] ISO : An error occurred during recv TCP : Connection timed out
Connected[4]: true
...
Result[9]: 0
Connected[9]: true
Result[10]: 0
Connected[10]: true
Unable to read from DB [11] ISO : An error occurred during recv TCP : Connection timed out
Connected[11]: true
...
Unable to read from DB [22] ISO : An error occurred during recv TCP : Connection timed out
Connected[22]: true
Unable to read from DB [23] ISO : An error occurred during recv TCP : Connection timed out
Connected[23]: true
Unable to read from DB [24] ISO : An error occurred during send TCP : Other Socket error (32)
Connected[24]: true
Unable to read from DB [25] ISO : An error occurred during send TCP : Other Socket error (32)
Connected[25]: true
Unable to read from DB [26] ISO : An error occurred during send TCP : Other Socket error (32)
... |
Hi, |
Hi, @unocelli ! I have implemented an error handler that filters socket related errors and in case of socket error, triggers reconnect mechanism. In reconnecting attempt I'm checking if |
I am closing this because it's more related to snap7 lib then this one. @mathiask88 thank you for your support! |
@leovujanic is you error handler the code above or how does it look like? Could you share it? |
Hi,
I'm running the latest version of node-snap7 and having trouble with
S7Client.Connected()
method which returnstrue
in a case when the client was connected to PLC and network broke in the meanwhile (eg. turn off WIFI).The text was updated successfully, but these errors were encountered: