Cant write to register in Modbus

#1

Hello,

I have a PLC which communicate by Modbus and I have integrated to that with Node Red. I am able to read registers with FC1 without problems but when I try to write a flag with the address 1544 with FC5 I am not able to do so

No error in debug but the flag in the PLC does not change state
My flow below, anyone that can help?

[{"id":"57ebc1d2.7b947","type":"tab","label":"Test Modbus Write","disabled":false,"info":""},{"id":"be40beef.d50fa8","type":"inject","z":"57ebc1d2.7b947","name":"Test","topic":"","payload":"[true]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":260,"wires":[["749c32c8.84b584","a1bc5cc8.77b8e8"]]},{"id":"749c32c8.84b584","type":"debug","z":"57ebc1d2.7b947","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":530,"y":260,"wires":[]},{"id":"949256a2.2367d","type":"modbus-response","z":"57ebc1d2.7b947","name":"","registerShowMax":20,"x":470,"y":360,"wires":[]},{"id":"cee8e243.d9d03","type":"modbus-flex-write","z":"57ebc1d2.7b947","name":"Test","showStatusActivities":false,"showErrors":false,"server":"7d4b4b33.a2e32c","x":270,"y":380,"wires":[["949256a2.2367d"],["2e326584.ad8b4a"]]},{"id":"a1bc5cc8.77b8e8","type":"function","z":"57ebc1d2.7b947","name":"Test","func":"msg.payload = { value: msg.payload, 'fc': 5, 'unitid': 1, 'address': 1544 , 'quantity': 1 } \nreturn msg;","outputs":1,"noerr":0,"x":130,"y":380,"wires":[["cee8e243.d9d03"]]},{"id":"2e326584.ad8b4a","type":"debug","z":"57ebc1d2.7b947","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":540,"y":520,"wires":[]},{"id":"7d4b4b33.a2e32c","type":"modbus-client","z":"","name":"Borkan","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"tcpHost":"192.168.110","tcpPort":"5001","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"10","clientTimeout":"1500","reconnectTimeout":"2000"}]
0 Likes

#2

A few suggestions

1.) You are sending an array as the payload, it is more likely this should be boolean (true or false) or even more likely to be a number 0 or 1
2.) Try to use a modbus write and not a flex write.
3.) On my PLC I could not write individual bits and needed to write a register each time

0 Likes

#3

Hello,

Thanks for your feedback

I managed to solve the issue but I needed to switch function code from 5 to 15 (multiple coils) which is really strange

So now I am writing a single bit with FC15 but it works

0 Likes