TwinCAT ADS client for Node-RED (unofficial). Basically a Node-RED wrapper on battle-tested ads-client Node.js library.
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.
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)
cd ~/.node-red
npm i node-red-contrib-ads-client
Please make sure you also read ads-client README as it has lots of valuable information.
Please see help of the each node in Node-RED help window for instructions and more info.
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 |
After you have installed the package and restarted Node-RED, you should see the available ADS nodes in your nodes list.
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.
- Drag a
ADS - Read Symbol
node to the flow - Double click the node
- Under ADS connection it should state
Add new ads-client-connection...
, -> click the edit icon next to it. - (Optional) Give a name to the connection
- NOTE: See ads-client readme for different connection setups (like Windows, Raspberry etc.)
- Setup target settings
Target AmsNetId
- Target PLC AmsNetId (likelocalhost
,192.168.1.5.1.1
and so on)Target ADS port
- Target runtime ADS port (like851
for TwinCAT 3 runtime 1)
- Setup optional settings
- Press Add
- In Read Symbol node, enter variable name you want to read
- Example:
GVL_Test.MyStringVariable
- Example:
- Press done
- Drag an
inject
node to the flow - Connect its output to the input of the Read Symbol node
- Drag a
debug
node to the flow - Connect output of the Read Symbol node to the debug node input
- 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.
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}]
-
I'm having connection problems
- See ads-client FAQ and ads-client issues
-
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)
- Set
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.