Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

node-red-contrib-ads-client

jisotalo206MIT1.4.0

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

node-red, ADS, twincat, beckhoff, plc, iec-61131-3, 61131-3, twincat 2, twincat 2.11, twincat 3, twincat 3.1, twincat ADS, codesys, client

readme

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 <j.isotalo91@gmail.com>

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.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[1.4.0] - 31.10.2022

Added

  • New new nodes
    • Read Raw
    • Write Raw
    • Convert To Raw
    • Convert From Raw
    • Get Symbol Info
  • Updated README
  • Updated ADS connection to have new client setting bareclient

[1.3.2] - 08.08.2021

Changed

[1.3.1] - 01.08.2021

Changed

  • Minor fixes related to ads-client-connection to prevent connection loop and other problems during connection losses and special cases.
  • Hopefully fixing issue #12

[1.3.0] - 07.07.2021

Added

  • New setting for ads-client-connection: Debugging level
    • Possible to set ads-client debugging level from Node-RED
    • Easier to debug connection problems & library bugs

      Changed

  • Thank you Hopperpop for contribution, awesome work!
    • Better support for nodes that operate at the same time
      • No more errors when all nodes try to connect to the PLC (Already connecting to the target)
      • Other nodes will wait for the result of the connection that the first node is creating
    • If first connection to the PLC fails at startup, warning is shown instead of error
  • Old ads-client-connection is always disconnected (if possible) in handled manner when (re)connecting

[1.2.0] - 30.06.2021

Added

  • New node Connection Status that reports ADS connection status changes
    • Automatically outputs latest connection status when changes detected
    • Can also be read manually using input trigger
    • Outputs true/false (ok/not ok) and connection info
  • New node Read Runtime State that implements ads-client library readPlcRuntimeState()
    • Possible to read PLC status (run, stop) from Node-RED
  • New node Read System Manager State that implements ads-client library readSystemManagerState()
    • Possible to read system manager status (run, config) from Node-RED
  • Updated ADS connection node
    • Automatically tries to connect to the target PLC in the background
    • Before the connection was retried only when reading/writing/subscribing
    • Now automatically connects when possible -> supports the new Connection Status node
  • Updated Subscribe node
    • Listens on connection state changes in a better way than before

[1.1.1] - 30.05.2021

Changed

  • Improved error handling (see pull request #8)
  • Updated README
    • Example how to configure and read value

[1.1.0] - 20.05.2021

Added

  • New node Invoke RPC Method that implements ads-client library invokeRpcMethod()
    • Possible to call function block methods from Node-RED
    • Thank you Hopperpop for contribution!

Changed

  • Subscribe node
    • If connection is lost, status is updated
    • If no notifications received in configured time after reconnection, the node will try resubscribe (new setting Resubscribe timeout [ms])
    • ads-client should automatically resubscribe everything, but this is just in case
  • All nodes now have similar status shapes

[1.0.4] - 18.05.2021

Added

  • Name properties to all nodes (also connection config -> PLCs can be named)

Changed

  • Read Symbol and Write Symbol nodes no longer clear the input message. Instead it's passed onwards.
  • Added better support for error catching (Subscribe is still probably not working 100% with Catch nodes)
  • Node status messages are now shorter and more compact
  • Minor fixes and corrections

Bug fix: Subscribe node failed to subscribe when using it without input. Thank you Hopperpop for contributing (See issue #2)

[1.0.3] - 18.05.2021

Changed

  • Bug fix: Subscribe node failed to subscribe when using it without input. Thank you Hopperpop for contributing (See issue #2)

[1.0.2] - 17.05.2021

Changed

  • package.json fix

[1.0.1] - 17.05.2021

Changed

  • Accidentally started npm versioning from 1.0.0 so here we are...

[0.1.0] - 17.05.2021

Added

  • First release for testing
  • Commands available
    • Read Symbol
    • Write Symbol
    • Subscribe