jisotalo/node-red-contrib-ads-client

Discussion of first versions

jisotalo opened this issue · 11 comments

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.

First of all, Thank you for doing this.

I tried the following test connecting to a local system:
afbeelding

[{"id":"6212431e.a41d64","type":"inject","z":"89b5ac23.d7af08","name":"","topic":"Drives.fbDriveCyl[1].xCylinder","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":100,"wires":[["9a298bb3.de0f4"]]},{"id":"87222730.0c9b","type":"debug","z":"89b5ac23.d7af08","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":970,"y":160,"wires":[]},{"id":"abb795ff.ad186","type":"catch","z":"89b5ac23.d7af08","name":"","scope":["dfeb82c6.20ce48","f668e8e3.d1cf78","f325de49.8f78d8"],"uncaught":false,"x":1190,"y":160,"wires":[["bbaf7fd5.4347e"]]},{"id":"6766bb6.3a67244","type":"complete","z":"89b5ac23.d7af08","name":"","scope":["dfeb82c6.20ce48","f668e8e3.d1cf78","f325de49.8f78d8"],"uncaught":false,"x":1170,"y":100,"wires":[["5d0069de.c89688"]]},{"id":"5d0069de.c89688","type":"debug","z":"89b5ac23.d7af08","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"topic","targetType":"msg","x":1360,"y":100,"wires":[]},{"id":"bbaf7fd5.4347e","type":"debug","z":"89b5ac23.d7af08","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"topic","targetType":"msg","x":1360,"y":160,"wires":[]},{"id":"dfeb82c6.20ce48","type":"ads-client-read-symbol","z":"89b5ac23.d7af08","connection":"1086b6ee.1f2791","variableName":"","x":670,"y":100,"wires":[["87222730.0c9b","c8d76dd2.66466","9f533d61.166d7","f8fcaf41.973b18"]]},{"id":"f668e8e3.d1cf78","type":"ads-client-write-symbol","z":"89b5ac23.d7af08","connection":"1086b6ee.1f2791","variableName":"","autoFill":false,"x":1110,"y":240,"wires":[[]]},{"id":"c8d76dd2.66466","type":"function","z":"89b5ac23.d7af08","name":"Flip","func":"msg.payload = !msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":910,"y":240,"wires":[["f668e8e3.d1cf78"]]},{"id":"9a298bb3.de0f4","type":"change","z":"89b5ac23.d7af08","name":"Add msg.test","rules":[{"t":"set","p":"test","pt":"msg","to":"Abcd","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":100,"wires":[["dfeb82c6.20ce48"]]},{"id":"9f533d61.166d7","type":"debug","z":"89b5ac23.d7af08","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"test","targetType":"msg","x":960,"y":100,"wires":[]},{"id":"f8fcaf41.973b18","type":"function","z":"89b5ac23.d7af08","name":"Flip","func":"msg.payload = !msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":912,"y":298,"wires":[["2d295060.2beec8"]]},{"id":"2d295060.2beec8","type":"change","z":"89b5ac23.d7af08","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Drives.fbDriveCyl[1].xCylinder","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1052,"y":298,"wires":[["f325de49.8f78d8"]]},{"id":"f325de49.8f78d8","type":"ads-client-write-symbol","z":"89b5ac23.d7af08","connection":"1086b6ee.1f2791","variableName":"","autoFill":false,"x":1272,"y":298,"wires":[["b80fb4f1.d3666"]]},{"id":"b80fb4f1.d3666","type":"debug","z":"89b5ac23.d7af08","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"topic","targetType":"msg","x":1480,"y":300,"wires":[]},{"id":"2f423273.b4d08e","type":"status","z":"89b5ac23.d7af08","name":"","scope":["dfeb82c6.20ce48","f668e8e3.d1cf78","f325de49.8f78d8"],"x":1180,"y":40,"wires":[["3137dd4.2419122"]]},{"id":"3137dd4.2419122","type":"debug","z":"89b5ac23.d7af08","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"status.text","targetType":"msg","x":1380,"y":40,"wires":[]},{"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}]

This are my current comments:

  • The read/write nodes clear the full message. As far as I know most nodes just copy the full message and modifies what they are interacting on. Example: if you set "msg.topic", it would be handy if you could reuse it in later nodes.
  • It can be useful if errors can be caught. See: https://nodered.org/docs/creating-nodes/node-js#handling-errors
  • This comment is more about aesthetics: Having the full error message in the status can be "annoying". I can't remember if any other node does it like this. Having a short status message and having the error in the console + catch node seems better to me. (But it's just my opinion, maybe other people thing differently.)
  • Being able to name the node for easy reading.

Hi there

Thanks for your very fast work!

wanted to test it too. I failed very early on .. :-(

i can't connect to the PLC, TC2.11 (10.1.121.1; 10.1.121.1.1.1)
Node-RED: 10.1.121.120

image
image

Where is my mistake?

Here, a config of another ADS Lib, which runs on the same device
image

I'm running node-red in a docker but don't think this is critical. In other Lib's this works without restrictions ..?

Thanks for your feedback @Hopperpop! It's very valuable as I haven't got much experience of Node-RED.

- The read/write nodes clear the full message. As far as I know most nodes just copy the full message and modifies what they are interacting on. Example: if you set "msg.topic", it would be handy if you could reuse it in later nodes.

Thanks, I didn't know that. So basically I just need to take the input msg, do the action, and then output the same msg with different payload & possible other new properties?

- It can be useful if errors can be caught. See: https://nodered.org/docs/creating-nodes/node-js#handling-errors

I actually tried to do that, but I proably did it wrongly. Did you try to catch the errors? I will check it.
EDIT: Seems that I used an old convention to throw errors, let's see if I get it right this time

- This comment is more about aesthetics: Having the full error message in the status can be "annoying". I can't remember if any other node does it like this. Having a short status message and having the error in the console + catch node seems better to me. (But it's just my opinion, maybe other people thing differently.)
That's true. At first it looked great to me, however when there are longer error messages it's not that good.

Do you think messages like "Subscribed", "Error: Failed to subscribe" etc. would be OK? And keep the error information in console and for catch node? I really have no idea how these are usually used..

- Being able to name the node for easy reading.

Do you have any link to show it's done? Thanks.
EDIT: Found it. "In this example, the node has a single editable property, name. Whilst not required, there is a widely used convention to this property to help distinguish between multiple instances of a node in a single flow." from https://nodered.org/docs/creating-nodes/first-node

Hi there

Thanks for your very fast work!

wanted to test it too. I failed very early on .. :-(

i can't connect to the PLC, TC2.11 (10.1.121.1; 10.1.121.1.1.1)
Node-RED: 10.1.121.120

Where is my mistake?

I'm running node-red in a docker but don't think this is critical. In other Lib's this works without restrictions ..?

@hbTecAG
Have you tested the connection with ads-client before? If not, please read the readme of the ads-client, especially the chapter about connection.

What is your setup? What operating system are you using?

I just released a new version. Looking forward for your feedback!

[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

Good job! All my points seems to be addressed.

The error catching works now. For the subscription i see the error catching as less important as it's more an input node. But the status would here be more valuable I think. Currently it stays green (subscribed) when the plc goes into configuration mode.
For reading/writing you want to know if the action is successful, the catch error is perfect for that. For the subscription you want to know if it has an active subscription.

Another useful thing would be if you could know the system status before reading/writing. This could be in the form of a system node where you can request/subscribe to the plc/connection status. You could use it for example with this node, to buffer data if you application needs it. (This is more as an example what the status could be used for.)

I tried to update the Subscribe node so that it will update status if target is disconnected etc. However not sure if it's 100% working yet.

I will add that system status node at some point!

Hi there
Thanks for your very fast work!
wanted to test it too. I failed very early on .. :-(
i can't connect to the PLC, TC2.11 (10.1.121.1; 10.1.121.1.1.1)
Node-RED: 10.1.121.120
Where is my mistake?
I'm running node-red in a docker but don't think this is critical. In other Lib's this works without restrictions ..?

@hbTecAG
Have you tested the connection with ads-client before? If not, please read the readme of the ads-client, especially the chapter about connection.

What is your setup? What operating system are you using?

No, i have never run ads-client bevor. I have study this chapter, but i still have problems..

My Setup: (i Think, thats the 3rd?)
Client: Raspberry pi with Node-RED running in a Docker Container. (10.1.121.120)
PLC: CX5120 Running with TC2.11 Runtime (10.1.121.1)

Configuration see above

Actually I have never tried to connect from non-Windows system to TwinCAT 2.

Have you added a route manually? Does the TC2 have similar XML file for routes?

@hbTecAG
I have it working on a raspberry pi and docker + remote p(l)c with Twincat 3.1.4024.12.
Steps to get it working:

  • Make sure to open port 48898 in the firewall of the remote pc.
  • Add a static route to your raspbery pi on the remote p(l)c with a chosen AmsNetId.
  • For the rest I used a similar configuration in the node. I only didn't fill in localAdress. If I fill it in, it gives me timeout errors.

Try also different localAdsPort's and don't mix both nodes as they block each others connection (don't forget to disable/delete the configuration nodes.)

Hi all!

Just updated to version 1.2.0. There is now a new node for connection status.

[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