Giter VIP home page Giter VIP logo

jisotalo / node-red-contrib-ads-client Goto Github PK

View Code? Open in Web Editor NEW
15.0 2.0 4.0 55 KB

Beckhoff TwinCAT ADS client library for Node-RED (unofficial). Connects to Beckhoff TwinCAT automation systems using ADS protocol.

Home Page: https://flows.nodered.org/node/node-red-contrib-ads-client

License: MIT License

HTML 59.97% JavaScript 40.03%
client ads plc twincat beckhoff twincat3 twincat-ads codesys twincat2 iec-61131-3 61131-3 node-red

node-red-contrib-ads-client's Introduction

node-red-contrib-ads-client (TwinCAT ADS client for Node-RED)

npm version GitHub License

TwinCAT ADS client for Node-RED (unofficial). Basically a Node-RED wrapper on battle-tested ads-client Node.js library.

Project status

The ads-client library used under the hood is battle-tested and reliable.

Not all features are yet in this Node-RED port version work is in progress.

Features

Target is to have all same features as the ads-client has.

  • TwinCAT 2 and TwinCAT 3 support
  • Supports connecting to the local TwinCAT 3 runtime (see enabling localhost support)
  • Supports multiple connections from the same host
  • Reading and writing all any PLC variable
  • Subscribing to PLC variables (ADS notifications)
  • Automatic conversion between PLC<->Javascript objects
  • PLC symbol and data type handling and caching
  • Automatic 32/64 bit variable support (PVOID, XINT, etc.)
  • Automatic cache and subscription refreshing when PLC program changes or system starts
  • Automatic byte alignment support (all pack-modes automatically supported)

Installing

cd ~/.node-red
npm i node-red-contrib-ads-client

Important

Please make sure you also read ads-client README as it has lots of valuable information.

Available nodes

Please see help of the each node in Node-RED help window for instructions and more info.

image

The following nodes are available at this point:

Node Description Equivalent in ads-client More info
ADS - Connection Status Reports status changes of the selected ADS connection. connect, disconnect and reconnect events
ADS - Read Symbol Reads any kind of variable by given variable name. readSymbol() README
ADS - Write Symbol Writes given value to any kind of variable by given variable name. writeSymbol() README
ADS - Subscribe Subscribes to given variable to receive notifications. subscribe() README
ADS - Invoke RPC Method Calls a function block method with parameters using RPC (remote procedure call). invokeRpcMethod() README
ADS - Read Runtime State Reads TwinCAT PLC runtime state (run, stop) from given ADS port. readPlcRuntimeState() README
ADS - Read System Manager State Reads TwinCAT System Manager state from target (using ADS port 10000). readSystemManagerState() README
ADS - Get Symbol Info Returns symbol information for given variable/symbol. getSymbolInfo() README
ADS - Read Raw Reads (raw byte) data from PLC by given index group, index offset and size. readRaw() README
ADS - Write Raw Writes (raw byte) buffer data to PLC by given index group and index offset. writeRaw() README
ADS - Convert To Raw Converts given Javascript object/variable to raw Buffer data by given data type (like REAL, ST_Struct). convertToRaw() README
ADS - Convert From Raw Converts given raw data (byte Buffer) to Javascript object by given data type (like REAL, ST_Struct). convertFromRaw() README

Getting started

After you have installed the package and restarted Node-RED, you should see the available ADS nodes in your nodes list.

image

Creating a connection (and reading a value)

You need to create a configuration (ads-client instance) to every target PLC you will use. To do this, you need to add one node to the flow first.

In this example we have GVL_Test.MyStringVariable in the PLC. image

  1. Drag a ADS - Read Symbol node to the flow
  2. Double click the node
  3. Under ADS connection it should state Add new ads-client-connection..., -> click the edit icon next to it.
  4. (Optional) Give a name to the connection
  5. NOTE: See ads-client readme for different connection setups (like Windows, Raspberry etc.)
  6. Setup target settings
    • Target AmsNetId - Target PLC AmsNetId (like localhost, 192.168.1.5.1.1 and so on)
    • Target ADS port - Target runtime ADS port (like 851 for TwinCAT 3 runtime 1)
  7. Setup optional settings
  8. Press Add
  9. In Read Symbol node, enter variable name you want to read
    • Example: GVL_Test.MyStringVariable
  10. Press done
  11. Drag an inject node to the flow
  12. Connect its output to the input of the Read Symbol node
  13. Drag a debug node to the flow
  14. Connect output of the Read Symbol node to the debug node input
  15. Deploy the flow

Now pressing the button in inject node will command the Read Symbol node to read value from PLC. The value (or error) will be shown in debug window.

AX0qYcBOCp

Example to import

[{"id":"290b97f1.b47728","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"3f5e8355.09cafc","type":"ads-client-read-symbol","z":"290b97f1.b47728","name":"","connection":"bbd41d0d.87aac","variableName":"GVL_Test.MyStringVariable","x":230,"y":120,"wires":[["48a7c812.ab1db8"]]},{"id":"8b366e5a.37926","type":"inject","z":"290b97f1.b47728","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":40,"wires":[["3f5e8355.09cafc"]]},{"id":"48a7c812.ab1db8","type":"debug","z":"290b97f1.b47728","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":200,"y":220,"wires":[]},{"id":"bbd41d0d.87aac","type":"ads-client-connection","name":"Local PLC","targetAmsNetId":"localhost","targetAdsPort":"851","objectifyEnumerations":true,"convertDatesToJavascript":true,"readAndCacheSymbols":false,"readAndCacheDataTypes":false,"disableSymbolVersionMonitoring":false,"routerTcpPort":"","routerAddress":"","localAddress":"","localTcpPort":"","localAmsNetId":"","localAdsPort":"","timeoutDelay":"","hideConsoleWarnings":false,"autoReconnect":true,"reconnectInterval":"","checkStateInterval":"","connectionDownDelay":"","allowHalfOpen":false,"disableBigInt":false}]

FAQ

  • I'm having connection problems

  • How to get debugging information?

    • Set Debugging level of ADS connection to 3 under connection settings.
    • Output can be found from node-red console/terminal (see this issue comment)

License

Licensed under MIT License so commercial use is possible. Please respect the license, linking to this page is also much appreciated.

Copyright (c) Jussi Isotalo <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

node-red-contrib-ads-client's People

Contributors

hopperpop avatar jisotalo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

node-red-contrib-ads-client's Issues

problem with reconnection after redeployment

Hi,

I have a problem, that the Node-Red ads-client does not reconnect after a redeployment of Node-Red or after restart of the hardware. I use following Lib versions:

+-- [email protected] +-- [email protected] -> ./../../opt/nodered/lib/node_modules/node-red +-- [email protected] -> ./../../opt/npm/lib/node_modules/npm

and following Hardware: Advantech ICR3231 LTE-Router

Very strange behaviour:

I use a ADS - Connection Status node and several Subscribe nodes from the ads-client lib. After Deployment of the node-red flow, the ads nodes lose the connection to the Beckhoff PLC (TwinCAT 3).

Bevor deploy
image

After deploy
image

After I apply the ethernet settings in the advantech router, the ads node reconnect to the Beckhoff PLC.
image
image

Here is the Log of the process: (unfortuneatly with debug level 3 I get not more information)
`# tail -f module-nodered
{
fill: 'green',
shape: 'dot',
text: 'Subscribed',
source: {
id: '9f12b574bd018a50',
type: 'ads-client-subscribe',
name: 'FRONT_TIME_TOOL_CHANGE'
}
}
2023-06-29 16:22:36 [debug] saved flow revision: e392abca8ceadeb6cf067642057898cd
2023-06-29 16:22:36 [info] Stopping flows
2023-06-29 16:22:36 [debug] red/nodes/flows.stop : stopping flow : adbad0c8def14ca1
2023-06-29 16:22:36 [debug] red/nodes/flows.stop : stopping flow : 8ea35e728cd8dbf3
2023-06-29 16:22:36 [debug] red/nodes/flows.stop : stopping flow : 656dcc8b191c5056
2023-06-29 16:22:36 [debug] red/nodes/flows.stop : stopping flow : global
2023-06-29 16:22:36 [info] [ads-client-connection:41398cdf55542ea0] Disconnecting from 192.168.2.3.1.1:851 and unsubscribing from all...
2023-06-29 16:22:36 [info] [ads-client-connection:41398cdf55542ea0] Disconnected from 192.168.2.3.1.1:851
2023-06-29 16:22:36 [info] Stopped flows
2023-06-29 16:22:36 [info] Updated flows
2023-06-29 16:22:36 [info] Starting flows
2023-06-29 16:22:36 [debug] red/nodes/flows.start : starting flow : global
2023-06-29 16:22:36 [debug] red/nodes/flows.start : starting flow : adbad0c8def14ca1
2023-06-29 16:22:36 [debug] red/nodes/flows.start : starting flow : 8ea35e728cd8dbf3
2023-06-29 16:22:36 [debug] red/nodes/flows.start : starting flow : 656dcc8b191c5056
2023-06-29 16:22:36 [info] [ads-client-connection:41398cdf55542ea0] Connecting to 192.168.2.3.1.1:851...
2023-06-29 16:22:36 [info] Started flows
2023-06-29 16:22:37 [info] [mqtt-broker:hivemq] Connected to broker: mqtts://mqtt-broker.t-matix.io:8883
2023-06-29 16:22:37 [error] [file in:buffer_read] Error: ENOENT: no such file or directory, open '/var/data/node-red/mqtt_buffer'
2023-06-29 16:22:37 [debug] [exec:3c5f993fbf211703] rm /var/data/node-red/mqtt_buffer
2023-06-29 16:22:37 [debug] [exec:3c5f993fbf211703] error:Error: Command failed: rm /var/data/node-red/mqtt_buffer
rm: can't remove '/var/data/node-red/mqtt_buffer': No such file or directory

2023-06-29 16:22:38 [info] [ads-client-connection:41398cdf55542ea0] Connecting to 192.168.2.3.1.1:851 failed, keeping trying..
2023-06-29 16:22:38 [warn] [ads-client-connection:41398cdf55542ea0] Failed to connect 192.168.2.3.1.1:851 at startup: ClientException: Connection to 192.168.2.3:48898 failed (timeout) - No response from router in 2000 ms
2023-06-29 16:22:38 [error] [ads-client-subscribe:FRONT_TIME_TOOL_CHANGE] Error: Not connected to the target, retrying in the background.
2023-06-29 16:22:38 [info] [debug:debug 6]
{
fill: 'red',
shape: 'dot',
text: 'Not connected',
source: {
id: 'd7afa6af1768a7a1',
type: 'ads-client-connection-status',
name: ''
}
}
2023-06-29 16:22:38 [info] [debug:debug 6]
{
fill: 'red',
shape: 'dot',
text: 'Error: Not connected',
source: {
id: '9f12b574bd018a50',
type: 'ads-client-subscribe',
name: 'FRONT_TIME_TOOL_CHANGE'
}
}
2023-06-29 16:22:38 [info] [debug:debug 6]
{
fill: 'red',
shape: 'dot',
text: 'Error: Not connected',
source: {
id: '2e4f302a8e8dd521',
type: 'ads-client-read-symbol',
name: 'FRONT_TIME_TOOL_CHANGE'
}
}
2023-06-29 16:22:38 [info] [debug:debug 5] ClientException: Connection to 192.168.2.3:48898 failed (timeout) - No response from router in 2000 ms
2023-06-29 16:22:38 [info] [debug:debug 6]
{
fill: 'red',
shape: 'dot',
text: 'Error: Not connected, retrying...',
source: {
id: '9f12b574bd018a50',
type: 'ads-client-subscribe',
name: 'FRONT_TIME_TOOL_CHANGE'
}
}
2023-06-29 16:22:38 [info] [debug:debug 6]
{
fill: 'red',
shape: 'dot',
text: 'Error: Not connected',
source: {
id: '6e48ed40dd6ff62c',
type: 'ads-client-read-symbol',
name: 'FRONT_SPINDLE_TOOL_CLAMPING'
}
}
2023-06-29 16:22:38 [info] [debug:debug 5] ClientException: Connection to 192.168.2.3:48898 failed (timeout) - No response from router in 2000 ms
2023-06-29 16:22:38 [info] [debug:debug 6]
{
fill: 'red',
shape: 'dot',
text: 'Error: Not connected',
source: {
id: '4c31795556267fe2',
type: 'ads-client-read-symbol',
name: 'FRONT_SPINDLE_TOOL_RELEASE'
}
}
2023-06-29 16:22:38 [info] [debug:debug 5] ClientException: Connection to 192.168.2.3:48898 failed (timeout) - No response from router in 2000 ms
2023-06-29 16:22:38 [info] [debug:debug 6]
{
fill: 'red',
shape: 'dot',
text: 'Error: Not connected',
source: {
id: '174fbeb06d4d43d4',
type: 'ads-client-read-symbol',
name: 'REAR_TIME_TOOL_CHANGE'
}
}
2023-06-29 16:22:38 [info] [debug:debug 5] ClientException: Connection to 192.168.2.3:48898 failed (timeout) - No response from router in 2000 ms
2023-06-29 16:22:38 [info] [debug:debug 6]
{
fill: 'red',
shape: 'dot',
text: 'Error: Not connected',
source: {
id: 'e442289492c5f76b',
type: 'ads-client-read-symbol',
name: 'REAR_SPINDLE_TOOL_CLAMPING'
}
}
2023-06-29 16:22:38 [info] [debug:debug 5] ClientException: Connection to 192.168.2.3:48898 failed (timeout) - No response from router in 2000 ms
2023-06-29 16:22:38 [info] [debug:debug 6]
{
fill: 'red',
shape: 'dot',
text: 'Error: Not connected',
source: {
id: '15ff5277958bb6d2',
type: 'ads-client-read-symbol',
name: 'REAR_SPINDLE_TOOL_RELEASE'
}
}
2023-06-29 16:22:38 [info] [debug:debug 5] ClientException: Connection to 192.168.2.3:48898 failed (timeout) - No response from router in 2000 ms
2023-06-29 16:22:42 [info] [debug:debug 6]
{
fill: 'red',
shape: 'dot',
text: 'Error: Not connected, retrying...',
source: {
id: '9f12b574bd018a50',
type: 'ads-client-subscribe',
name: 'FRONT_TIME_TOOL_CHANGE'
}
}
2023-06-29 16:22:46 [info] [debug:debug 6]
{
fill: 'red',
shape: 'dot',
text: 'Error: Not connected, retrying...',
source: {
id: '9f12b574bd018a50',
type: 'ads-client-subscribe',
name: 'FRONT_TIME_TOOL_CHANGE'
}
}
2023-06-29 16:22:46 [error] [snmp:INFO] RequestTimedOutError: Request timed out
2023-06-29 16:22:49 [info] [debug:debug 6]
{
fill: 'green',
shape: 'dot',
text: 'Connected',
source: {
id: 'd7afa6af1768a7a1',
type: 'ads-client-connection-status',
name: ''
}
}
2023-06-29 16:22:49 [info] [debug:debug 6]
{
fill: 'green',
shape: 'dot',
text: 'Subscribed',
source: {
id: '9f12b574bd018a50',
type: 'ads-client-subscribe',
name: 'FRONT_TIME_TOOL_CHANGE'
}
}`

Thank you in advance!

Control subscribe node parameters with msg.subscribe

Hi, i have a feature request which would be an improvement and simplification for my use case, since i subscribe to many different variables and i would like to have a central way to control the cycle time instead of changing it in every node. Up to now it is only possible to control the subscribe node in a binary way (subscribe or don´t subscribe). It would be cool if you could inject a message with the parameters subscribtion mode, cycle time, initial delay and so on.

Connection issues to CX8090 (Twincat2)

PLC: 192.168.11.3
AMSnetID PLC: 5.50.37.33.1.1
Twincat 2

Raspberry Pi : 192.168.11.2

Route has been created on PLC. Settings should be according tot tutorials

Error : "Failed to connect 5.50.37.33.1.1:801 at startup: ClientException: Connection failed: Device system manager state read failed - ADS error -1 (Timeout - no response in 6000 ms)"

image
image
image

Subscribe not working without input

When using the subscribe node without an input, it won't connect (local connection).

afbeelding

[{"id":"90f489bd.33574","type":"ads-client-subscribe","z":"89b5ac23.d7af08","connection":"1086b6ee.1f2791","variableName":"","cycleTime":"2000","mode":"cyclic","initialDelay":0,"retryInterval":"100","controlSubscription":true,"inputs":1,"x":220,"y":520,"wires":[["d23952a6.a80a"]]},{"id":"d23952a6.a80a","type":"debug","z":"89b5ac23.d7af08","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":620,"y":520,"wires":[]},{"id":"923427e4.2e241","type":"ads-client-subscribe","z":"89b5ac23.d7af08","connection":"1086b6ee.1f2791","variableName":"Drives.fbDriveCyl[1].xCylinder","cycleTime":"2000","mode":"cyclic","initialDelay":"2","retryInterval":"100","controlSubscription":false,"inputs":0,"x":280,"y":580,"wires":[["ad851bd7.2a57e"]]},{"id":"ad851bd7.2a57e","type":"debug","z":"89b5ac23.d7af08","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":620,"y":580,"wires":[]},{"id":"eaddaad6.14037","type":"inject","z":"89b5ac23.d7af08","name":"","topic":"Drives.fbDriveCyl[1].xCylinder","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":250,"y":460,"wires":[["43a2bf4a.bef43"]]},{"id":"43a2bf4a.bef43","type":"change","z":"89b5ac23.d7af08","name":"","rules":[{"t":"set","p":"subscribe","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":460,"wires":[["90f489bd.33574"]]},{"id":"1086b6ee.1f2791","type":"ads-client-connection","z":"","targetAmsNetId":"localhost","targetAdsPort":"851","objectifyEnumerations":true,"convertDatesToJavascript":true,"readAndCacheSymbols":false,"readAndCacheDataTypes":false,"disableSymbolVersionMonitoring":false,"routerTcpPort":"","routerAddress":"","localAddress":"","localTcpPort":"","localAmsNetId":"","localAdsPort":"","timeoutDelay":"","hideConsoleWarnings":false,"autoReconnect":true,"reconnectInterval":"","checkStateInterval":"","connectionDownDelay":"","allowHalfOpen":false,"disableBigInt":false}]

Connection loop

Setup

  • Node-red on rpi with node-red-contrib-ads-client v1.2.0
  • TwinCat v4020.12 on win10 pc with static route pointing to 192.168.1.22

Config
image
image

Bug
As seen above the localAddress (who is a valid ethernet interface on the rpi) is set wrongly and doesn't match the static route on the win10 pc.

Node-red becomes unresponsive and eventually crashes. In the console following lines are spammed without delay:
ads-client: WARNING: Connection was lost. Trying to reconnect...,
ads-client: WARNING: Connection was lost. Trying to reconnect...,
ads-client: WARNING: Connection was lost. Trying to reconnect...,
ads-client: WARNING: Reconnecting failed. Keeping trying in the background every 5000 ms...,
ads-client: WARNING: Reconnecting failed. Keeping trying in the background every 5000 ms...,
ads-client: WARNING: Reconnecting failed. Keeping trying in the background every 5000 ms...,
ads-client: WARNING: Reconnecting failed. Keeping trying in the background every 5000 ms...,

Problem connecting to Beckhoff PLC

First of all I would like to thank you for this library! The examples and documentation is amazing!

Unfortunately I was not able to connect to my Beckhoff PLC. My task is to connect and take data from the PLC - I did not install it nor program it - so I don't know all the internal configuration etc. but I will try to explain our system as best as I can.

What am I using?

  1. Beckhoff PLC
  • type: CP-4D57D0
  • IP address: 172.21.9.60
  • AmsNetID: 5.77.87.208.1.1 OR 158.196.119.70.3.1 (see why I say OR down below)
  • ADS port: 851 OR 27907 (see why I say OR down below)
  1. Linux PC with Node-RED
  • IP address: 172.21.9.50
  • NodeRED verison: 3.0.2
  • contrib-ads-client version: 1.4.0

I enabled ADS and create symbols on the Beckhoff PLC as follow:
image

Why did I say AmsNET ID is 5.77.87.208.1.1 or 158.196.119.70.3.1?

  • I can see the AmsNET ID in two different places showing two different addresses.
  • And I don't know which one is correct
  • But I have tried both and both don't work.

One I can find here:
Screenshot_14

And second one I can see here:
Screenshot_8

The same applies for the PORTS 851 OR 27907

  • again I can see two diffrent ports in two diffrent places.
    Here:
    Screenshot_11

And here:
Screenshot_12

This is the error I am getting:
Screenshot_9

I do not understand why is it trying to connect to the local IP 127.0.0.1?
Shall I also configure something on my Linux PC?

I have tried every combination of AmsNetID and PORTS and none of the worked resulting in same error message (expect for the IP and PORT).

I will appreciate any help!
With regards,
Jakub Szlaur

Discussion of first versions

If you have any comments please add them here. I'm not sure if everything is done correctly (how things usually are done with Node-RED).

If you find bugs and other problems, please submit a new issue.

The library now has three nodes: Read Symbol, Write Symbol and Subscribe. Each one has it's own help inside the Node-RED so check it out.

subscribe multiple

Question:

What if I have >200 individual variables and I want to subscribe to each one of them (preferably with individual settings for cycling time)? Do I need to create 200 individual subscription nodes? Or is there a possibility to use 1 node and subscribe to multiple variables (configured by the input msg for instance)
Does anyone have the same scenario? Suggestions on how to handle this efficiently?

no connection to Beckhoff PLC Simulation

Hi,

I have following problem with the ads-client in node-red (v3.0.2). I use an Advantech IoT Router ICR3231W with Node-Red installed. I have also installed the node-red-contrib-ads and the node-red-contrib-ads-client. My Beckhoff TwinCAT 3.1.0.0 (EventLoggerVersion: 4024.47) is installed on a Windows 10x64 Lenovo Notebook. Router and Notebook is connected via a Netgear unmanaged switch. Firewall is disabled on both sides. At the TwinCAT ADS Router I have configured a route to my Node-Red

With the node-red-contrib-ads lib it was possible to get a connection to the PLC via the ADS System node. I was also able to read global variables from the PLC Simulation. I have configured the node as followed:
image

With the node-red-contrib-ads-client I am not able to get a connection to the PLC SIM. I use the ADS - Connection Status node.

image

image

Why is it working with the node-red-contrib-ads but not with the node-red-contrib-ads-client. When I started testing with the node-red-contrib-ads-client I have restarted the PLC Sim, restarted the Router where Node-Red is running on and deleted the configuration from the node-red-contrib-ads in Node-Red.

Thank you in advance!
Kind Regards,
Patrick

Real number in PLC but INT in node-red

I declared the subscribed variable as a REAL output variable in TwinCAT 3. When i read it with the subscribe node i only get an INT value (without the decimal places) when i use the debug node.

Uncaught error

Getting uncaught errors (node-red-contrib-ads-client v1.2.0), which stops node-red. I'm not sure if it's a problem with the node or the ads-client lib. It always happens after "IO out--->". The TcSystem isn't running. Somehow it tries to subscribe to a variable, while it just made a disconnect call. Could be a race condition, but I still need to investigate further.

  ads-client setDebugging(): Debug level set to 3 +2s
  ads-client connect(): Starting to connect localhost:48898 +1ms
  ads-client connect(): Socket connection established to localhost:48898 +8ms
  ads-client:details _registerAdsPort(): Registering an ADS port from ADS router localhost:48898 +2s
  ads-client:details IO out ------> 8 bytes +1ms
  ads-client:details IO in  <------ 14 bytes +0ms
  ads-client:details _parseAmsTcpHeader(): Starting to parse AMS/TCP header +1ms
  ads-client:details _parseAmsTcpHeader(): AMS/TCP header parsed: { command: 4096, commandStr: 'AMS_TCP_PORT_CONNECT', dataLength: 8, data: <Buffer c0 a8 00 c2 01 01 61 a4> } +0ms
  ads-client:details _parseAmsHeader(): Starting to parse AMS header +1ms
  ads-client:details _parseAmsHeader(): No AMS header found +1ms
  ads-client:details _parseAdsData(): Starting to parse ADS data +2ms
  ads-client:details _parseAdsData(): No ADS data found +3ms
  ads-client:details _onAmsTcpPacketReceived(): A parsed AMS packet received with command 4096 +1ms
  ads-client:details _registerAdsPort(): ADS port registered, assigned AMS address is 192.168.0.194.1.1:42081 +6ms
  ads-client connect(): ADS port registered from router. We are 192.168.0.194.1.1:42081 +21ms
  ads-client:details readSystemManagerState(): Reading device system manager state +9ms
  ads-client:details _sendAdsCommand(): Sending an ads command ReadState (0 bytes): { amsTcp: { command: 0, commandStr: 'AMS_TCP_PORT_AMS_CMD' }, ams: { targetAmsNetId: '127.0.0.1.1.1', targetAdsPort: 10000, sourceAmsNetId: '192.168.0.194.1.1', sourceAdsPort: 42081, adsCommand: 4, adsCommandStr: 'ReadState', stateFlags: 4, stateFlagsStr: 'AdsCommand, Tcp, Request', dataLength: 0, errorCode: 0, invokeId: 0 }, ads: { rawData: <Buffer > } } +7ms
  ads-client:details _createAmsHeader(): AMS header created (32 bytes) +12ms
  ads-client:details _createAmsTcpHeader(): AMS/TCP header created (6 bytes) +6ms
  ads-client:details _createAmsTcpRequest(): AMS/TCP request created (38 bytes) +0ms
  ads-client:details IO out ------> 38 bytes +6ms
  ads-client:details IO in  <------ 38 bytes +1ms
  ads-client:details _parseAmsTcpHeader(): Starting to parse AMS/TCP header +2ms
  ads-client:details _parseAmsTcpHeader(): AMS/TCP header parsed: { command: 0, commandStr: 'AMS_TCP_PORT_AMS_CMD', dataLength: 32 } +2ms
  ads-client:details _parseAmsHeader(): Starting to parse AMS header +0ms
  ads-client:details _parseAmsHeader(): AMS header parsed: { targetAmsNetId: '192.168.0.194.1.1', targetAdsPort: 42081, sourceAmsNetId: '127.0.0.1.1.1', sourceAdsPort: 10000, adsCommand: 4, adsCommandStr: 'ReadState', stateFlags: 5, stateFlagsStr: 'Response, AdsCommand, Tcp', dataLength: 0, errorCode: 18, invokeId: 0, error: true, errorStr: 'Port disabled' } +4ms
  ads-client:details _onAmsTcpPacketReceived(): A parsed AMS packet received with command 0 +1ms
  ads-client:details _onAdsCommandReceived(): A parsed ADS command received with command 4 +1ms
  ads-client:details _sendAdsCommand(): Response received for command ReadState with invokeId 0 +2ms
  ads-client readSystemManagerState(): Device system manager state read failed +50ms
  ads-client disconnect(): Starting to close connection (force: false) +3ms
  ads-client unsubscribeAll(): Unsubscribing from all notifications +3ms
  ads-client unsubscribeAll(): Unsubscribed from 0 notifications +0ms
  ads-client _unsubscribeAllInternals(): Unsubscribing from all notifications +3ms
  ads-client _unsubscribeAllInternals(): Unsubscribed from 0 notifications +2ms
  ads-client:details _unregisterAdsPort(): Unregister ads port 42081 from localhost:48898 +12ms
  ads-client:details IO out ------> 8 bytes +1ms
  ads-client subscribe(): Subscribing to MAIN.lrDt +3ms
  ads-client:details _subscribe(): Subscribing to 'MAIN.lrDt' with settings { transmissionMode: 4, cycleTime: 200, maximumDelay: 0 } +4ms
  ads-client getSymbolInfo(): Symbol info requested for MAIN.lrDt +3ms
  ads-client:details _readSymbolInfo(): Reading symbol info for MAIN.lrDt +1ms
  ads-client:details _sendAdsCommand(): Sending an ads command ReadWrite (26 bytes): { amsTcp: { command: 0, commandStr: 'AMS_TCP_PORT_AMS_CMD' }, ams: { targetAmsNetId: '127.0.0.1.1.1', targetAdsPort: '851', sourceAmsNetId: '192.168.0.194.1.1', sourceAdsPort: 42081, adsCommand: 9, adsCommandStr: 'ReadWrite', stateFlags: 4, stateFlagsStr: 'AdsCommand, Tcp, Request', dataLength: 26, errorCode: 0, invokeId: 1 }, ads: { rawData: <Buffer 09 f0 00 00 00 00 00 00 ff ff ff ff 0a 00 00 00 4d 41 49 4e 2e 6c 72 44 74 00> } } +11ms
  ads-client:details _createAmsHeader(): AMS header created (32 bytes) +0ms
  ads-client:details _createAmsTcpHeader(): AMS/TCP header created (6 bytes) +1ms
  ads-client:details _createAmsTcpRequest(): AMS/TCP request created (64 bytes) +1ms
  ads-client:details IO out ------> 64 bytes +1ms
1 Jul 17:21:56 - [red] Uncaught Exception:
1 Jul 17:21:56 - Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:209:20)

ClientException: Connection to localhost:48898 failed (socket error -4077) (read ECONNRESET)

Setup:

  • Node-red with node-red-contrib-ads-client v1.2.0
  • TwinCAT 3 4022.22 running on 64bit Windows 10 (remote PC & PLC)

I am getting a ClientExpection (see log below) when trying to set up notifications/subscriptions for a bunch of PLC variables:

Welcome to Node-RED
===================

5 Apr 12:39:56 - [info] Node-RED version: v2.2.2
5 Apr 12:39:56 - [info] Node.js  version: v16.14.0
5 Apr 12:39:56 - [info] Windows_NT 10.0.14393 x64 LE
5 Apr 12:39:57 - [info] Loading palette nodes
5 Apr 12:40:00 - [info] Dashboard version 3.1.6 started at /ui
5 Apr 12:40:00 - [info] Settings file  : C:\Users\User\.node-red\settings.js
5 Apr 12:40:00 - [info] Context store  : 'default' [module=memory]
5 Apr 12:40:00 - [info] User directory : \Users\User\.node-red
5 Apr 12:40:00 - [warn] Projects disabled : editorTheme.projects.enabled=false
5 Apr 12:40:00 - [info] Flows file     : \Users\User\.node-red\flows.json
5 Apr 12:40:01 - [info] Server now running at http://127.0.0.1:1880/
5 Apr 12:40:01 - [info] Starting flows
5 Apr 12:40:01 - [info] [ads-client-connection:MyPlcConn] Connecting to 172.17.3.23.1.1:851...
  ads-client _connect(): Starting to connect localhost:48898 +0ms
5 Apr 12:40:01 - [info] Started flows
  ads-client _connect(): Socket connection established to localhost:48898 +12ms
  ads-client _connect(): Socket connect failed: Error: read ECONNRESET
  ads-client     at TCP.onStreamRead (node:internal/stream_base_commons:217:20) {
  ads-client   errno: -4077,
  ads-client   code: 'ECONNRESET',
  ads-client   syscall: 'read'
  ads-client } +2ms
5 Apr 12:40:01 - [info] [ads-client-connection:MyPlcConn] Connecting to 172.17.3.23.1.1:851 failed, keeping trying..
5 Apr 12:40:01 - [warn] [ads-client-connection:MyPlcConn] Failed to connect 172.17.3.23.1.1:851 at startup: ClientException: Connection to localhost:48898 failed (socket error -4077) (read ECONNRESET)
  ads-client _disconnect(): Starting to close connection (force: false) +2s
  ads-client _unsubscribeAllInternals(): Unsubscribing from all notifications +1ms
  ads-client _unsubscribeAllInternals(): Unsubscribed from 0 notifications +1ms
  ads-client _registerAdsPort(): Failed to unregister ADS port - Timeout - no response in 2000 ms +2s
  ads-client _disconnect(): Connection closed successfully +2s
  ads-client setDebugging(): Debug level set to 2 +15ms
  ads-client _connect(): Starting to connect localhost:48898 +0ms
  ads-client _connect(): Socket connection established to localhost:48898 +6ms
  ads-client _connect(): Socket connect failed: Error: read ECONNRESET
  ads-client     at TCP.onStreamRead (node:internal/stream_base_commons:217:20) {
  ads-client   errno: -4077,
  ads-client   code: 'ECONNRESET',
  ads-client   syscall: 'read'
  ads-client } +8ms
5 Apr 12:40:07 - [info] [ads-client-connection:MyPlcConn] Connecting to 172.17.3.23.1.1:851...
  ads-client _disconnect(): Starting to close connection (force: false) +6ms
  ads-client _unsubscribeAllInternals(): Unsubscribing from all notifications +0ms
  ads-client _unsubscribeAllInternals(): Unsubscribed from 0 notifications +0ms
  ads-client _disconnect(): Connection closed successfully +2ms
  ads-client setDebugging(): Debug level set to 2 +1ms
  ads-client _connect(): Starting to connect localhost:48898 +0ms
  ads-client _connect(): Socket connection established to localhost:48898 +1ms
  ads-client _connect(): Socket connect failed: Error: read ECONNRESET
  ads-client     at TCP.onStreamRead (node:internal/stream_base_commons:217:20) {
  ads-client   errno: -4077,
  ads-client   code: 'ECONNRESET',
  ads-client   syscall: 'read'
  ads-client } +1ms
5 Apr 12:40:07 - [info] [ads-client-connection:MyPlcConn] Connecting to 172.17.3.23.1.1:851 failed, keeping trying..
5 Apr 12:40:07 - [error] [ads-client-subscribe:MyPlc] Error: Not connected to the target, retrying in the background.
  ads-client _disconnect(): Starting to close connection (force: false) +2s
  ads-client _unsubscribeAllInternals(): Unsubscribing from all notifications +1ms
  ads-client _unsubscribeAllInternals(): Unsubscribed from 0 notifications +0ms
  ads-client _registerAdsPort(): Failed to unregister ADS port - Timeout - no response in 2000 ms +2s
  ads-client _disconnect(): Connection closed successfully +0ms
  ads-client setDebugging(): Debug level set to 2 +0ms
  ads-client _connect(): Starting to connect localhost:48898 +0ms
  ads-client _connect(): Socket connection established to localhost:48898 +1ms
  ads-client _connect(): Socket connect failed: Error: read ECONNRESET
  ads-client     at TCP.onStreamRead (node:internal/stream_base_commons:217:20) {
  ads-client   errno: -4077,
  ads-client   code: 'ECONNRESET',
  ads-client   syscall: 'read'
  ads-client } +1ms

The route to the PLC is enabled and Ads Communication is already running successfully using .NET Software.
I experience this error trying to connect to a remote PLC (setup 1) as well as running Node-RED locally on the desired PLC (setup 4).
I also tried adding EnableAmsTcpLoopback = 1 as registry key on the remote PC as well the PLC without any success.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.