plcpeople / nodeS7

Node.JS library for communication to Siemens S7 PLCs
MIT License
358 stars 121 forks source link

connect error ECONNRESET #64

Closed psapoznik closed 6 years ago

psapoznik commented 6 years ago

Hello, after being about 10 minutes reading, it gives this error and I can not control it to continue the execution. (S7-1500 )

Does anyone know why this might happen?

Thank you.

[6802,958350399] Connection cleanup is happening [6802,958702800 192.168.0.2 S1] Attempting to connect to host... [6802,959635499 192.168.0.2 S1] TCP Connection Established to 192.168.0.2 on port 102 [6802,959848699 192.168.0.2 S1] Will attempt ISO-on-TCP connection [6802,960114000 192.168.0.2 S1] Using rack [0] and slot [1] [6802,961254600 192.168.0.2 S1] ISO-on-TCP Connection Confirm Packet Received [6802,962537699] We Caught a read/write error ECONNRESET - will DISCONNECT and attempt to reconnect. [6802,962793700] ConnectionReset is happening [6802,963064500] ConnectionReset is happening [6804,461757300] TIMED OUT waiting for PDU reply packet from PLC - Disconnecting [6804,462975099 192.168.0.2 S1] Wait for 2 seconds then try again. [6804,463273599] ConnectionReset is happening [6804,463524400 192.168.0.2 S1] Scheduling a reconnect from packetTimeout, connect type [6804,464642200] ResetNOW is happening [6804,464870400] Clearing an earlier scheduled reset [6806,463175399 192.168.0.2 S1] The scheduled reconnect from packetTimeout, PDU type, is happening now [6806,464447400] Connection cleanup is happening [6806,464894500 192.168.0.2 S1] Attempting to connect to host... [6806,466437600 192.168.0.2 S1] TCP Connection Established to 192.168.0.2 on port 102 [6806,466659799 192.168.0.2 S1] Will attempt ISO-on-TCP connection [6806,466880999 192.168.0.2 S1] Using rack [0] and slot [1] [6806,468413500 192.168.0.2 S1] We Caught a connect error ECONNRESET { Error: read ECONNRESET at _errnoException (util.js:992:11) at TCP.onread (net.js:618:25) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }

plcpeople commented 6 years ago

Is it possible to post a Wireshark trace of the exchange? From my experience ECONNRESET means the connection is being terminated elsewhere.

What version of nodeS7 are you using? Anything else you can tell us about the application that might be useful?

psapoznik commented 6 years ago

Last version de nodeS7 -> github.

Code:

function intervalFunc() { var nodes7 = require('nodes7'); // This is the package name, if the repository is cloned you may need to require 'nodeS7' with uppercase S var conn = new nodes7; var doneReading = false; var doneWriting = false;

var variables = { TEST1: 'DB4,S12.254', // Memory real at MD4 TEST2: 'DB4,REAL528', // Bit at M32.2
};

conn.initiateConnection({port: 102, host: '192.168.0.2', rack: 0, slot: 1}, connected); // slot 2 for 300/400, slot 1 for 1200/1500 //conn.initiateConnection({port: 102, host: '192.168.0.2', localTSAP: 0x0100, remoteTSAP: 0x0200, timeout: 8000}, connected); // local and remote TSAP can also be directly specified instead. The timeout option specifies the TCP timeout.

function connected(err) { if (typeof(err) !== "undefined") { // We have an error. Maybe the PLC is not reachable. console.log(err); process.exit(); } conn.setTranslationCB(function(tag) {return variables[tag];}); // This sets the "translation" to allow us to work with object names conn.addItems(['TEST1', 'TEST2']); //conn.addItems('TEST6'); // conn.removeItems(['TEST2', 'TEST3']); // We could do this. // conn.writeItems(['TEST5', 'TEST6'], [ 867.5309, 9 ], valuesWritten); // You can write an array of items as well. //conn.writeItems('TEST7', [ 666, 777 ], valuesWritten); // You can write a single array item too. conn.readAllItems(valuesReady); }

function valuesReady(anythingBad, values) { if (anythingBad) { console.log("SOMETHING WENT WRONG READING VALUES!!!!"); } console.log(values); doneReading = true; if (doneWriting) { process.exit(); } }

function valuesWritten(anythingBad) { if (anythingBad) { console.log("SOMETHING WENT WRONG WRITING VALUES!!!!"); } console.log("Done writing."); doneWriting = true; if (doneReading) { process.exit(); } } } setInterval(intervalFunc, 2000);

plcpeople commented 6 years ago

I think it is not working because you're slowly using up all the available connections of the PLC and after 10 minutes they're all used up. Try this example: (unused code was removed, and I don't have a PLC with me right now so can't test, but hopefully you can get the idea)

Note that by using setTimeout there will be slightly longer than 2s between requests, but I don't recomment setInterval here - if there is a communication error, you could end up making requests before getting a reply.

var nodes7 = require('nodes7'); // This is the package name, if the repository is cloned you may need to require 'nodeS7' with uppercase S
var conn = new nodes7;
var doneReading = false;
var doneWriting = false;

var variables = { TEST1: 'DB4,S12.254', // Memory real at MD4
TEST2: 'DB4,REAL528', // Bit at M32.2
};

conn.initiateConnection({port: 102, host: '192.168.0.2', rack: 0, slot: 1}, connected); // slot 2 for 300/400, slot 1 for 1200/1500

function connected(err) {
    if (typeof(err) !== "undefined") {
        // We have an error. Maybe the PLC is not reachable.
        console.log(err);
        process.exit();
    }

    conn.setTranslationCB(function(tag) {return variables[tag];}); // This sets the "translation" to allow us to work with object names
    conn.addItems(['TEST1', 'TEST2']);
    conn.readAllItems(valuesReady);
}

function valuesReady(anythingBad, values) {
    if (anythingBad) { console.log("SOMETHING WENT WRONG READING VALUES!!!!"); }
    console.log(values);
    doneReading = true;
    setTimeout(function() {
        conn.readAllItems(valuesReady);
    }, 2000);
}
psapoznik commented 6 years ago

Now it seems to be working! Perfect, thank you very much for your help.