Store PLCnext CommunityPLCnext on LinkedInPLCnext on Instagram  PLCnext on YouTube Github PLCnext CommunityStore PLCnext Community

  1. ndusak
  2. PLCnext Technology & PLCnext Controls
  3. Monday, 03 May 2021
Hello,
I am using OPC UA in Node Red trying to send some arrays (Array of String, Array of Int, Array of Bool) to my PLC AXCF 1152, but I have some problems with Integer and Boolean. While it works fine with String, when I try to send Array of Int or Bool to the PLC, nothing happens. I can read the variables from the PLC but I can not write to them. I would appreciate any help.
Attachments (2)
Accepted Answer
Stefan Brinkmann Accepted Answer Pending Moderation
0
Votes
Undo
Hi,

I posted my code using the </> symbol in the response window. This formats text as code.

Here is my updated flow using a variable to send via OPC UA. You have to define all elements of the array in the variable.


[{"id":"69973b99.598814","type":"tab","label":"OPC Events","disabled":false,"info":""},{"id":"64f02bfb.d8bdf4","type":"inject","z":"69973b99.598814","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"","payloadType":"date","x":110,"y":80,"wires":[["df1a321.957bdd"]]},{"id":"2d6d1541.b51b9a","type":"debug","z":"69973b99.598814","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":890,"y":80,"wires":[]},{"id":"6e2750d4.111a1","type":"function","z":"69973b99.598814","name":"","func":"var text = msg.payload.Message;\nvar tim = msg.payload.Time;\nmsg.text = text;\nmsg.time = tim;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":720,"y":80,"wires":[["2d6d1541.b51b9a","27f83d03.ec1932","c4817126.cb29a"]]},{"id":"88e59793.c22d48","type":"OpcUa-Client","z":"69973b99.598814","endpoint":"14afceca.6386f1","action":"events","deadbandtype":"a","deadbandvalue":1,"time":"2","timeUnit":"s","certificate":"n","localfile":"","localkeyfile":"","securitymode":"None","securitypolicy":"None","name":"","x":520,"y":80,"wires":[["6e2750d4.111a1"]]},{"id":"df1a321.957bdd","type":"OpcUa-Event","z":"69973b99.598814","root":"i=2253","eventtype":"i=2041","name":"","x":280,"y":80,"wires":[["88e59793.c22d48"]]},{"id":"27f83d03.ec1932","type":"ui_text","z":"69973b99.598814","group":"69af2557.a85b2c","order":0,"width":0,"height":0,"name":"","label":"Meldung","format":"{{msg.text}}","layout":"row-spread","x":900,"y":120,"wires":[]},{"id":"c4817126.cb29a","type":"ui_text","z":"69973b99.598814","group":"69af2557.a85b2c","order":1,"width":0,"height":0,"name":"","label":"Zeit","format":"{{msg.time}}","layout":"row-spread","x":890,"y":160,"wires":[]},{"id":"18b92d00.e3d413","type":"OpcUa-Client","z":"69973b99.598814","endpoint":"14afceca.6386f1","action":"read","deadbandtype":"a","deadbandvalue":1,"time":10,"timeUnit":"s","certificate":"n","localfile":"","localkeyfile":"","securitymode":"None","securitypolicy":"None","name":"READ Variable","x":480,"y":320,"wires":[["749da4e7.bf264c"]]},{"id":"749da4e7.bf264c","type":"debug","z":"69973b99.598814","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":320,"wires":[]},{"id":"730ee83e.e19d68","type":"debug","z":"69973b99.598814","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":560,"wires":[]},{"id":"691666dd.a13d38","type":"comment","z":"69973b99.598814","name":"READ","info":"","x":90,"y":260,"wires":[]},{"id":"da438d80.dbd95","type":"comment","z":"69973b99.598814","name":"WRITE","info":"","x":110,"y":520,"wires":[]},{"id":"e76f54a8.8e5d78","type":"OpcUa-Item","z":"69973b99.598814","item":"ns=5;s=http://Arp.Plc.Eclr/ArrayInt","datatype":"Int16 Array","value":"","name":"OPC Array","x":290,"y":320,"wires":[["18b92d00.e3d413"]]},{"id":"5558e4d1.92edbc","type":"inject","z":"69973b99.598814","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":320,"wires":[["e76f54a8.8e5d78"]]},{"id":"1cce2d5e.d6ba23","type":"OpcUa-Item","z":"69973b99.598814","item":"ns=5;s=http://Arp.Plc.Eclr/ArrayInt","datatype":"Int16 Array","value":"","name":"OPC Array","x":430,"y":560,"wires":[["59273bda.a07fc4"]]},{"id":"a9159fc1.5dcf6","type":"inject","z":"69973b99.598814","name":"new value","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"11,12,13,14,55,66,77,88,99,0,0","payloadType":"str","x":120,"y":560,"wires":[["d97a4062.02d43"]]},{"id":"59273bda.a07fc4","type":"OpcUa-Client","z":"69973b99.598814","endpoint":"14afceca.6386f1","action":"write","deadbandtype":"a","deadbandvalue":1,"time":10,"timeUnit":"s","certificate":"n","localfile":"","localkeyfile":"","securitymode":"None","securitypolicy":"None","name":"WRITE Variable","x":600,"y":560,"wires":[["730ee83e.e19d68"]]},{"id":"3c231f98.e763f","type":"comment","z":"69973b99.598814","name":"Alarme","info":"","x":90,"y":40,"wires":[]},{"id":"d97a4062.02d43","type":"function","z":"69973b99.598814","name":"","func":"var val1 = Math.random(100) * 100;\nvar val2 = Math.random(100) * 100;\n\n//prepare sample data\nvar dat = [];\ndat.push(Math.round(val1));\ndat.push(Math.round(val2));\ndat.push(Math.round(val1));\ndat.push(Math.round(val2));\ndat.push(Math.round(val1));\ndat.push(Math.round(val2));\ndat.push(Math.round(val1));\ndat.push(Math.round(val2));\ndat.push(Math.round(val1));\ndat.push(Math.round(val2));\ndat.push(Math.round(val1));\n\nmsg.payload = dat.toString();\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":560,"wires":[["7fec9f8e.f1199","1cce2d5e.d6ba23"]]},{"id":"7fec9f8e.f1199","type":"debug","z":"69973b99.598814","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":430,"y":520,"wires":[]},{"id":"14afceca.6386f1","type":"OpcUa-Endpoint","endpoint":"opc.tcp://192.168.178.10:4840","secpol":"None","secmode":"None","login":false},{"id":"69af2557.a85b2c","type":"ui_group","name":"Events","tab":"50b18d54.3dd8a4","order":2,"disp":true,"width":"6","collapse":false},{"id":"50b18d54.3dd8a4","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]
Stefan Brinkmann Accepted Answer Pending Moderation
0
Votes
Undo
I could make it work. So here is my flow. The values of the array must be separated by a ,.


[{"id":"42701aa0.5fe354","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"752303d1.d6d02c","type":"OpcUa-Client","z":"42701aa0.5fe354","endpoint":"14afceca.6386f1","action":"read","deadbandtype":"a","deadbandvalue":1,"time":10,"timeUnit":"s","certificate":"n","localfile":"","localkeyfile":"","securitymode":"None","securitypolicy":"None","name":"READ Variable","x":500,"y":80,"wires":[["66ea48cf.d73b28"]]},{"id":"66ea48cf.d73b28","type":"debug","z":"42701aa0.5fe354","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":80,"wires":[]},{"id":"5ebe6d7d.2f9154","type":"debug","z":"42701aa0.5fe354","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":320,"wires":[]},{"id":"19aacea6.53f1f1","type":"comment","z":"42701aa0.5fe354","name":"READ","info":"","x":110,"y":20,"wires":[]},{"id":"fc77e576.ca5258","type":"comment","z":"42701aa0.5fe354","name":"WRITE","info":"","x":130,"y":280,"wires":[]},{"id":"d26fce6f.92bf","type":"OpcUa-Item","z":"42701aa0.5fe354","item":"ns=5;s=http://Arp.Plc.Eclr/ArrayInt","datatype":"UInt32 Array","value":"","name":"OPC Array","x":310,"y":80,"wires":[["752303d1.d6d02c"]]},{"id":"db85ffeb.60019","type":"inject","z":"42701aa0.5fe354","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":80,"wires":[["d26fce6f.92bf"]]},{"id":"f394cff5.0a609","type":"OpcUa-Item","z":"42701aa0.5fe354","item":"ns=5;s=http://Arp.Plc.Eclr/ArrayInt","datatype":"Int16 Array","value":"","name":"OPC Array","x":390,"y":320,"wires":[["f3ceed68.fa522"]]},{"id":"80e4e41.36c6818","type":"inject","z":"42701aa0.5fe354","name":"new value","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"110,12,13,14,55,66,77,88,99,0,0","payloadType":"str","x":140,"y":320,"wires":[["f394cff5.0a609"]]},{"id":"f3ceed68.fa522","type":"OpcUa-Client","z":"42701aa0.5fe354","endpoint":"14afceca.6386f1","action":"write","deadbandtype":"a","deadbandvalue":1,"time":10,"timeUnit":"s","certificate":"n","localfile":"","localkeyfile":"","securitymode":"None","securitypolicy":"None","name":"WRITE Variable","x":580,"y":320,"wires":[["5ebe6d7d.2f9154"]]},{"id":"14afceca.6386f1","type":"OpcUa-Endpoint","endpoint":"opc.tcp://192.168.178.10:4840","secpol":"None","secmode":"None","login":false}]
ndusak Accepted Answer Pending Moderation
0
Votes
Undo
Hi,
I have tried it your way. While it works when I write the string 1,2,3 directly to the inject Node, I can not find a way for it to work with global variables. I have found a workaround for my project. I just write everything to string and then decode it on the PLC. It is not pretty, especially for RGB sequences, but it works. How did you post your flow? When I try to post it, nothing shows.
ndusak Accepted Answer Pending Moderation
0
Votes
Undo
Hi,
I have tried it and it is finally working. The key was converting global variable with type array of string to just normal string (.toString();). Only then was the string converted by OPC UA item to an array of Integer. Thank you very much for your support.
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.