roccomuso / node-ads

NodeJS Twincat ADS protocol implementation
58 stars 21 forks source link

ECONNRESET or timeout when trying to access remote TwinCAT #31

Closed ttichy closed 4 years ago

ttichy commented 4 years ago

I have my laptop(192.168.0.120) connected over local network to a Win10 PC (192.168.0.208) running TwinCAT 3.

I am trying to do a readDeviceInfo as described in the documentation ("Hello Machine") with options set like this:

 var options = {
    host: "192.168.0.208",
    amsNetIdTarget: "192.168.0.208.1.1",
    amsNetIdSource: "10.0.75.1.1.1",
    amsPortTarget: 801,
    timeout: 10000
}

I tried to add the route on the target PC via the Router UI, but it would silently fail (TwinCAT beginner here). So I ended up adding a static route to the StaticRoutes.xml file and it looks like this:

<Route>
    <Name>RemoteClient</Name>
    <Address>192.168.0.120</Address>
    <NetId>10.0.75.1.1.1</NetId>
    <Type>TCP_IP</Type>
    <Flags>32</Flags>
</Route>

When I run the simple js to execute read the device info, I get { Error: read ECONNRESET at TCP.onread (net.js:622:25) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' } or timeout

Wireshark shows that the laptop (RemoteClient) sends the DeviceInfoRequest, but the target PC promptly closes the connection. image

From what I understand, add the route on the target PC essentially authorizes the client to connect. I am guessing that's where my problem lies, but I am unable to solve it.

Any ideas? Thanks!

ttichy commented 4 years ago

Turns out that the NetId and the Address have to match? I configured the route on the target to

<Route>
    <Name>RemoteClient</Name>
    <Address>192.168.0.120</Address>
    <NetId>192.168.0.120.1.1</NetId>
    <Type>TCP_IP</Type>
    <Flags>32</Flags>
</Route>

changed the options accordingly and voilà, it works!

ttichy commented 4 years ago

Turns out that the NetId and the Address have to match? I configured the route on the target to

<Route>
  <Name>RemoteClient</Name>
  <Address>192.168.0.120</Address>
  <NetId>192.168.0.120.1.1</NetId>
  <Type>TCP_IP</Type>
  <Flags>32</Flags>
</Route>

changed the options accordingly and voilà, it works!

Correction - they don't have to match. Out of ignorance, I have used the same NetId as my local AMS Router. That was apparently confusing the target router. Now I am connecting to the target TwinCAT with AMSNetIdSourc: 10.0.75.1.1.1