plcpeople / nodeS7

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

Connection Management Test: Missing ETIMEDOUT under Linux #68

Closed sembaye closed 6 years ago

sembaye commented 6 years ago

Description: I tested the connection management of nodes7 under Windows as well as under Linux. For the test I use keepalive. (Note: Under Linux I use the modul net-keepalive).

Environment: 1) Windows 10 Pro, Node@v8.11.4 2) Linux (Own Distribution, Kernel Version 4.9.75-rt60-preempt-rt), Node@8.11.4

Tests (Under Linux as well as under Windows.) : Test case 1:

Test case 2:

Steps to Reproduce:

const NodeS7 = require('nodes7');
let NetKeepAlive = null;
try {
  NetKeepAlive = require('net-keepalive');  // net-keepalive depends on the OS
} catch (er) {
  console.log('Installation of Module net-keepalive failed. (OS=' + process.platform + ')');
  NetKeepAlive = null;
}

const plc = new NodeS7({ debug: 1, silent: false });
const param = { port: 102, host: '192.168.0.111', rack: 0, slot: 2 };

const intervalReading = false; // Set Flag to true/false

plc.initiateConnection(param, (err) => {
  if (typeof (err) !== 'undefined') {
    console.log(err);
    process.exit();
  }

  // Enable KeepAlive.
  plc.isoclient.setKeepAlive(true, 3000);
  if (NetKeepAlive) {
    console.log('Set keepalive parameter for linux.');
    NetKeepAlive.setKeepAliveInterval(plc.isoclient, 3000);
    NetKeepAlive.setKeepAliveProbes(plc.isoclient, 5);
  }

  if (intervalReading) {
    plc.addItems('MB0');
    setInterval(() => {
      console.log('Status: ' + plc.isoConnectionState);
      plc.readAllItems((anythingBad, values) => {
        if (anythingBad) {
          console.log('SOMETHING WENT WRONG READING VALUES!!!!');
        } else {
          console.log(values);
        }
      });
    }, 1000);
  }
});

Expected Behavior: Test case 1:

Test case 2:

Actual Behavior: Overview:

Testcase 1 2
Windows OK OK
Linux OK Not OK

Detailed: To Testcase 1 (windows): NodeS7 resets Program due to ECONNRESET To Testcase 2 (windows): NodeS7 resets Program due to ECONNRESET, restarts communication again.

To Testcase 1 (linux): NodeS7 resets Program due to ETIMEDOUT To Testcase 2 (linux): No reset of nodes7, state always at 4 due to missing ETIMEDOUT, but nodes7 restarts communication again. I think the state should also go to 0 here.

sembaye commented 6 years ago

Timeout is not missing. It comes after 16min. Close issue