I am very new to Node-Red, however I have been a controls engineer working with PLCs and other hardware for almost 10 years now. I am very familiar with the hardware and communication side of things, and less familiar with PC/Java programming.
Anyway, I have these 16 channel digital I/O devices that talk Modbus TCP and I have them working perfectly. I have some code set up so that I can connect, read, and generally see the stat of inputs changing. Now, the problem I have is getting them into a usable state so I can have them as led indicators on my dashboard (boolean).
The devices only support reading 16 bit holding registers (quantity 4 with 4 inputs in the lowest nibble of each). That comes back in the payload as a 4 element array. I want to take each of those elements and get the individual bits into a bool array or discrete variables somehow.
I'll try to post what I have so far below along with the error message I'm getting. I realize this is probably not the best way of going about this but I just don't know any better at this point.
[{"id":"f904094d.37cdb8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"93f34bf.9bb84b8","type":"debug","z":"f904094d.37cdb8","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","x":650,"y":340,"wires":[]},{"id":"79921421.d6ffbc","type":"debug","z":"f904094d.37cdb8","name":"3","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":650,"y":480,"wires":[]},{"id":"59a58f0c.cc643","type":"debug","z":"f904094d.37cdb8","name":"2","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":650,"y":420,"wires":[]},{"id":"b7a493ab.5e48f","type":"switch","z":"f904094d.37cdb8","name":"switch1","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"}],"checkall":"false","repair":true,"outputs":4,"x":420,"y":420,"wires":[["93f34bf.9bb84b8","8e0dedb2.6d23f"],["59a58f0c.cc643"],["79921421.d6ffbc"],["30bd0c85.16a694"]]},{"id":"eccea110.b2043","type":"split","z":"f904094d.37cdb8","name":"spliit1","splt":"\\n","spltType":"str","arraySplt":"1","arraySpltType":"len","stream":false,"addname":"key","x":170,"y":420,"wires":[["b7a493ab.5e48f"]]},{"id":"30bd0c85.16a694","type":"debug","z":"f904094d.37cdb8","name":"4","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":650,"y":540,"wires":[]},{"id":"672d253e.35422c","type":"modbus-flex-getter","z":"f904094d.37cdb8","name":"Modbus Flexible Read","showStatusActivities":false,"showErrors":false,"logIOActivities":false,"server":"9d8b2011.7823a","useIOFile":false,"ioFile":"","useIOForPayload":false,"x":480,"y":160,"wires":[["975dce4.abe253","94dd4fc.59d00b"],["4961a7cb.c89358","31ceeb70.931974"]]},{"id":"63a4709a.e831f","type":"inject","z":"f904094d.37cdb8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":110,"y":140,"wires":[["cf4d7b97.b90b58"]]},{"id":"cf4d7b97.b90b58","type":"function","z":"f904094d.37cdb8","name":"FC1","func":"msg.payload = { 'fc': 4, 'unitid': 1, 'address': 0, 'quantity': 4}\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":160,"wires":[["672d253e.35422c"]]},{"id":"4961a7cb.c89358","type":"debug","z":"f904094d.37cdb8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":730,"y":200,"wires":[]},{"id":"31ceeb70.931974","type":"modbus-response","z":"f904094d.37cdb8","name":"","registerShowMax":20,"x":750,"y":240,"wires":[]},{"id":"975dce4.abe253","type":"debug","z":"f904094d.37cdb8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","x":710,"y":120,"wires":[]},{"id":"7d89bc8a.e7a4f4","type":"comment","z":"f904094d.37cdb8","name":"Modbus works perfectly!","info":"","x":150,"y":80,"wires":[]},{"id":"94dd4fc.59d00b","type":"link out","z":"f904094d.37cdb8","name":"out1","links":["ad644526.6f53c8"],"x":695,"y":160,"wires":[]},{"id":"ad644526.6f53c8","type":"link in","z":"f904094d.37cdb8","name":"in1","links":["94dd4fc.59d00b"],"x":55,"y":420,"wires":[["eccea110.b2043"]]},{"id":"8e0dedb2.6d23f","type":"bitunloader","z":"f904094d.37cdb8","name":"bits","mode":"arrayBools","prop":"payload","padding":"16","x":650,"y":380,"wires":[["7fc07b82.574e14"]]},{"id":"90ea9201.a1022","type":"debug","z":"f904094d.37cdb8","name":"bools 0","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":1260,"y":300,"wires":[]},{"id":"19c688f5.5a6187","type":"switch","z":"f904094d.37cdb8","name":"switch 2","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"},{"t":"eq","v":"4","vt":"str"}],"checkall":"false","repair":true,"outputs":5,"x":1040,"y":380,"wires":[["90ea9201.a1022"],["212c41fb.577ace"],["413f0a7b.180064","e500b5d2.5c6e68"],["4995484c.6df8e8"],[]]},{"id":"7fc07b82.574e14","type":"split","z":"f904094d.37cdb8","name":"spliit","splt":"\\n","spltType":"str","arraySplt":"1","arraySpltType":"len","stream":false,"addname":"value","x":850,"y":380,"wires":[["19c688f5.5a6187"]]},{"id":"212c41fb.577ace","type":"debug","z":"f904094d.37cdb8","name":"bools 1","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":1260,"y":360,"wires":[]},{"id":"413f0a7b.180064","type":"debug","z":"f904094d.37cdb8","name":"bools 2","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":1260,"y":460,"wires":[]},{"id":"4995484c.6df8e8","type":"debug","z":"f904094d.37cdb8","name":"bools 3","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":1260,"y":520,"wires":[]},{"id":"e500b5d2.5c6e68","type":"ui_led","z":"f904094d.37cdb8","group":"e847eaa5.5b4cd8","order":0,"width":0,"height":0,"label":"led","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"false","valueType":"bool"},{"color":"green","value":"true","valueType":"bool"}],"allowColorForValueInMessage":false,"name":"","x":1250,"y":420,"wires":[]},{"id":"93bd578c.a4e648","type":"inject","z":"f904094d.37cdb8","name":"","topic":"","payload":"[4,0,0,2]","payloadType":"json","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":80,"y":360,"wires":[["eccea110.b2043"]]},{"id":"1e6355ed.7df09a","type":"comment","z":"f904094d.37cdb8","name":"Split array into 4 messages.","info":"","x":160,"y":320,"wires":[]},{"id":"d59f7ea1.c53c7","type":"comment","z":"f904094d.37cdb8","name":"Send each message out on a different line.","info":"","x":360,"y":480,"wires":[]},{"id":"cb94fe08.1bc21","type":"comment","z":"f904094d.37cdb8","name":"Create and array of bools","info":"","x":690,"y":300,"wires":[]},{"id":"599269e3.8b50e8","type":"comment","z":"f904094d.37cdb8","name":"split the array","info":"","x":810,"y":340,"wires":[]},{"id":"f617b415.ee0888","type":"comment","z":"f904094d.37cdb8","name":"send each bool out","info":"","x":1050,"y":320,"wires":[]},{"id":"9d8b2011.7823a","type":"modbus-client","z":"","name":"test","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"tcpHost":"192.168.1.100","tcpPort":"502","tcpType":"TPC-RTU-BUFFERED","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true},{"id":"e847eaa5.5b4cd8","type":"ui_group","z":"","name":"Default","tab":"6ebd2b21.aa83d4","disp":true,"width":"20","collapse":false},{"id":"6ebd2b21.aa83d4","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]