No, FINS reads and writes in WORD values
Yes, use function node or JSONata in change node or the buffer-maker node to generate a WORD and write that.
BUT: Be mindful if you set a BIT in a WORD, all BITS will be written.
There are several options...
- it is safer to use 1 WORD per BIT
- Use status numbers (e.g. 1 = RUN, 2=STOP, 3=MANUAL MODE) etc
- Read WORD → set/reset BIT → WRITE WORD (see example below)
Demo Flow (use CTRL+I to import)
[{"id":"ca252362.2b25d","type":"inject","z":"d8bcc25e815f0bc3","name":"....... SET BIT 7 (0000 0000 1000 0000)","props":[{"p":"topic","vt":"str"},{"p":"bit","v":"7","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"SET","x":210,"y":840,"wires":[["5c3706dc0fedcf96"]]},{"id":"5c3706dc0fedcf96","type":"function","z":"d8bcc25e815f0bc3","name":"(FAKE) Read PLC D100","func":"msg.payload = flow.get(\"D100\") || 0\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":840,"wires":[["ab3d83e36d37d5af"]]},{"id":"ab3d83e36d37d5af","type":"function","z":"d8bcc25e815f0bc3","name":"Bit Operations","func":"\nconst ops = {\n GET(num, bit) {\n return ((num >> bit) % 2 != 0)\n },\n SET(num, bit) {\n return num | 1 << bit;\n },\n RESET(num, bit) {\n return num & ~(1 << bit);\n },\n TOGGLE(num, bit) {\n return ops.GET(num, bit) ? ops.RESET(num, bit) : ops.SET(num, bit);\n }\n}\n\nconst op = ops[msg.topic];\nif(!op) {\n node.error(`Bad topic '${msg.topic}'. Expected one of \"GET\",\"SET\",\"RESET\" or \"TOGGLE\" `, msg);\n}\nmsg.payload = op(msg.payload, msg.bit)\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":740,"y":840,"wires":[["91eb7a105be43c2d"]]},{"id":"02cd37dadd749199","type":"inject","z":"d8bcc25e815f0bc3","name":".. RESET BIT 7 (0000 0000 1000 0000)","props":[{"p":"topic","vt":"str"},{"p":"bit","v":"7","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"RESET","x":210,"y":880,"wires":[["5c3706dc0fedcf96"]]},{"id":"e8b5505c20f9e30e","type":"inject","z":"d8bcc25e815f0bc3","name":"TOGGLE BIT 2 (0000 0000 0000 0100)","props":[{"p":"topic","vt":"str"},{"p":"bit","v":"2","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"TOGGLE","x":210,"y":800,"wires":[["5c3706dc0fedcf96"]]},{"id":"91eb7a105be43c2d","type":"function","z":"d8bcc25e815f0bc3","name":"(FAKE) Write PLC D100","func":"flow.set(\"D100\", msg.payload) \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":900,"wires":[["321cb40e7f7bfed4"]]},{"id":"321cb40e7f7bfed4","type":"debug","z":"d8bcc25e815f0bc3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":770,"y":900,"wires":[]}]