roccomuso / node-ads

NodeJS Twincat ADS protocol implementation
58 stars 21 forks source link

Socket closes after 10 seconds - Error: This socket has been ended by the other party #30

Open JonFranklin301 opened 4 years ago

JonFranklin301 commented 4 years ago

Hi there,

I am using the notify method this to read position feedback from axes, however i am finding that the socket connection closes after approx 10 seconds.

 const options = {
    host: '10.4.4.1',
    amsNetIdTarget: '10.4.4.1.1.1',
    amsNetIdSource: '10.4.4.2.1.1',
  };

// Reading this...
  var myHandle = {
    symname: 'GVL.fbRevolve.rPosition',
    bytelength: ads.LREAL,
  };

    var client = ads.connect(options, function() {
      this.notify(myHandle);
    });

  client.on('notification', function(handle) {
    console.log(handle.value);
  });

  client.on('close', function(data) {
    console.log('CLOSE', data);
  });

 client.on('error', function(err) {
    console.log('Error: ', err);
  });

This works correctly for about 10 seconds before the socket is closed.

I thought it may have been a timeout somewhere, maybe the client not sending data frequently enough(?), so have added the following:

var client = ads.connect(options, function() {
      this.notify(myHandle);

setInterval(() => {
        this.readDeviceInfo(function(err, result) {
          if (err) console.log('Error: ', err);
          console.log('\nreadDeviceInfo: ', result);
          // this.end();
        });
      }, 1000);
    });

however after about 10 seconds the following gets thrown:

Error: Error: This socket has been ended by the other party at Socket.writeAfterFIN [as write] (net.js:407) at Object.runCommand (ads.js:1014) at Object.readDeviceInfo (ads.js:295) at EventEmitter.ads.adsClient.readDeviceInfo (ads.js:60) at renderer.js:153

Any Ideas how to keep the connect open?

Thanks, Jon

PLCHome commented 4 years ago

Configuration

Enable ADS on your PLC project. To do this click on your task and then enable the checkbox before Create symbols (if he is not disabled). In addition, you can still, under I/O Devices

Attention

Setting Up an ADS Remote Connection

JonFranklin301 commented 4 years ago

Hi @PLCHome I can confirm the ADS is enabled, Create symbols is checked and there is a route setup. We have another client running on a different machine that uses the ADS .NET dll to read data from the project without any issues.

Using node-ads I am able to connect and read data correctly for about 10 seconds before the connection is disconnected.

Thanks, Jon