# Writing coil outputs with modbus-contrib and limited device modbus documentation

**URL:** <https://discourse.nodered.org/t/writing-coil-outputs-with-modbus-contrib-and-limited-device-modbus-documentation/39268>\
**Category:** General\
**Created:** [17 January 2021 15:20 UTC](https://discourse.nodered.org/t/writing-coil-outputs-with-modbus-contrib-and-limited-device-modbus-documentation/39268 "2021-01-17T15:20:10Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![wpeeters](https://avatars.discourse-cdn.com/v4/letter/w/f6c823/32.png) [@wpeeters](https://discourse.nodered.org/u/wpeeters)\
**Post date:** [17 January 2021 15:20 UTC](https://discourse.nodered.org/t/writing-coil-outputs-with-modbus-contrib-and-limited-device-modbus-documentation/39268/1 "2021-01-17T15:20:10Z")

</div>

HI all,

I'm trying to write single coil of my pool heater. The documentation is rather limited and doesn't even mention if the coil information can be read (as the first project, I prefer to start reading first).

I already tried everything within the knowledge I already have. Nothing is working.  
Since I use rs485 modbus tcp convertor It is very difficult to determine if the flow in node-red is incorrect or something else.

I would like to know that at least my parameters are correct in my flow.

I started my project with reading and writing through a Modbus simulator connected to the rs485 modbus convertor via serial. That is working. So at least I know I can read and write already.

See trials in the flow.

This is which is mentioned in the documentation (that' all).

The default factory settings are: Baud =19200 Address = 16 (decimal) Parity = Even

For example a Modbus message to turn ON might be:

User Adjustable Controller Address : 0x10  
Write to Single Coil : 0x05  
Single Coil Address : 0x00 0x01  
Command turn on : 0xFF 0x00  
error check : 0xDE 0xBB

I'm most confused about the 2 hex value.

```auto
[{"id":"d969ee73.0f745","type":"function","z":"df9895fc.1d9bc8","name":"Convert byte array to UNSIGNED 32-bit integer","func":"// Create new Buffer based on array bytes\nconst buf = Buffer.from(msg.payload.buffer);\n\n// Represent these bytes as 32-bit unsigned int\nconst value = buf.readUInt32BE();\n\n// save the value\nmsg.payload = value;\n\nreturn msg;","outputs":1,"noerr":0,"x":1440,"y":380,"wires":[["9b9bb898.fdfe08"]]}]

```

---

<div class="post-metadata">

**Author:** ![wpeeters](https://avatars.discourse-cdn.com/v4/letter/w/f6c823/32.png) [@wpeeters](https://discourse.nodered.org/u/wpeeters)\
**Post date:** [30 January 2021 16:49 UTC](https://discourse.nodered.org/t/writing-coil-outputs-with-modbus-contrib-and-limited-device-modbus-documentation/39268/2 "2021-01-30T16:49:01Z")

</div>

Nobody that can help me this?

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [31 January 2021 21:43 UTC](https://discourse.nodered.org/t/writing-coil-outputs-with-modbus-contrib-and-limited-device-modbus-documentation/39268/3 "2021-01-31T21:43:45Z")

</div>

Hi Werner,

I doubt that you need to make any hex conversions to do a single or multiple register write.  
Not with the **node-red-contrib-modbus** set of nodes at least.

I'm attaching an example flow that demonstrates how to use the **modbus-flex-write** for Digital outputs.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/5/25237525837336cca155abf549137367b057a201.png)

```auto
[{"id":"98768ef8.f28b18","type":"modbus-flex-write","z":"94ab22aa.035ba","name":"","showStatusActivities":false,"showErrors":false,"server":"bf37180a.2d18e","emptyMsgOnFail":false,"keepMsgProperties":false,"x":650,"y":260,"wires":[["9fe4405d.23be3"],[]]},{"id":"72f1dc0a.8b2614","type":"function","z":"94ab22aa.035ba","name":"","func":"msg.payload = { \n\n value: msg.payload, \n 'fc': 15,\n 'unitid': 1,\n 'address': 0, \n 'quantity': 10 \n} \n\nreturn msg\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":440,"y":200,"wires":[["98768ef8.f28b18"]]},{"id":"9fe4405d.23be3","type":"debug","z":"94ab22aa.035ba","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":910,"y":240,"wires":[]},{"id":"9750c3c3.1886c","type":"inject","z":"94ab22aa.035ba","name":"FC15 - Multiple write","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[true,true,false,false,false,false,false,false,true,false]","payloadType":"json","x":230,"y":200,"wires":[["72f1dc0a.8b2614"]]},{"id":"5b852b30.34c794","type":"function","z":"94ab22aa.035ba","name":"","func":"msg.payload = { \n \n value: msg.payload, \n 'fc': 5, \n 'unitid': 1, \n 'address': 0,\n 'quantity': 1 \n} \n\nreturn msg\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":440,"y":320,"wires":[["98768ef8.f28b18"]]},{"id":"3e11d462.4de51c","type":"inject","z":"94ab22aa.035ba","name":"FC5 - Sigle write - true","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":220,"y":300,"wires":[["5b852b30.34c794"]]},{"id":"5ed0789.ff1fa88","type":"inject","z":"94ab22aa.035ba","name":"FC5 - Sigle write - false","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":220,"y":360,"wires":[["5b852b30.34c794"]]},{"id":"bf37180a.2d18e","type":"modbus-client","name":"","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.168.1.66","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":1,"commandDelay":20,"clientTimeout":1000,"reconnectOnTimeout":true,"reconnectTimeout":2000,"parallelUnitIdsAllowed":true}]

```

ps1. change the node's config to apply to your ip and settings  
ps2. regarding the rs485 modbus tcp convertor we really cant help without any links to its documentation.  
I hope you can see the values being sent to it by node-red to figure out whether the any issue  
is with the device or the converter.

---

<div class="post-metadata">

**Author:** ![wpeeters](https://avatars.discourse-cdn.com/v4/letter/w/f6c823/32.png) [@wpeeters](https://discourse.nodered.org/u/wpeeters)\
**Post date:** [1 February 2021 17:47 UTC](https://discourse.nodered.org/t/writing-coil-outputs-with-modbus-contrib-and-limited-device-modbus-documentation/39268/4 "2021-02-01T17:47:37Z")

</div>

Hi @UnborN , thanks for your feedback. I imported your flow. There is nothing new to me in there. So it means, at least I hope, that I'm on the right track. Today I received a usb to rs458. Even with a direct connection from PC to heater device, I can't make it to work.Modbus scanner is not detecting anything. So I think I better insist to have support of the heater. Something is wrong in there.  
Anyway, I still don't understand the 2 hex values in the documentation. Why did they document as such?

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [1 February 2021 19:04 UTC](https://discourse.nodered.org/t/writing-coil-outputs-with-modbus-contrib-and-limited-device-modbus-documentation/39268/5 "2021-02-01T19:04:54Z")

</div>

> [@wpeeters](#):
>
> I still don't understand the 2 hex values in the documentation.

I believe that's the actual raw hex representation of the modbus data.  
Here's an example from this [article](https://www.modbustools.com/modbus.html)

**Function 05 (05hex) Write Single Coil**

Writes a single coil to either ON or OFF.

**Request**  
The request message specifies the coil reference to be written. Coils are addressed starting at zero-coil 1 is addressed as 0.

The requested ON / OFF state is specified by a constant in the request data field. A value of FF 00 hex requests the coil to be ON. A value of 00 00 requests it to be OFF. All other values are illegal and will not affect the coil.

Here is an example of a request to write coil 173 ON in slave device 17:

| **Field Name** | **RTU (hex)** | **ASCII Characters** |
| --- | --- | --- |
| Header | None | : (Colon) |
| Slave Address | 11 | 1 1 |
| Function | 05 | 0 5 |
| Coil Address Hi | 00 | 0 0 |
| Coil Address Lo | AC | A C |
| Write Data Hi | FF | 0 0 |
| Write Data Lo | 00 | F F |
| Error Check Lo | 4E | LRC (3 F) |
| Error Check Hi | 8B | |
| Trailer | None | CR LF |
| Total Bytes | 8 | 17 |

But there's no need to worry about the actual data format being sent because the modbus node handles all that.

Its good that you have aquired a USB to RS485 at least now you know it not due to the Ethernet to Serial converter.

Can you post a screenshot of the modbus config node ? What did you set in there ? the factory defaults ? Baud =19200 Address = 16 (decimal) Parity = Even

Do you know the brand / model / any links for the documentation you mentioned for the heater ?

---

<div class="post-metadata">

**Author:** ![wpeeters](https://avatars.discourse-cdn.com/v4/letter/w/f6c823/32.png) [@wpeeters](https://discourse.nodered.org/u/wpeeters)\
**Post date:** [8 February 2021 18:35 UTC](https://discourse.nodered.org/t/writing-coil-outputs-with-modbus-contrib-and-limited-device-modbus-documentation/39268/6 "2021-02-08T18:35:34Z")

</div>

Hi @UnborN , I somehow got a little bit closer to a solution. With a direct rs485 connection from PC to the device, I'm able to make a connection now. Connection wiring required was not according to installer his input. Manufacturer input was required to solve.  
I'm also able now to turn on and off the heater (the only modbus commands possible) through node-red but I have strange behavior:

1. only working with modbus flex write node. But I receive 'Error: Data length error, expected 8 got 7'.  
So, yes, the heater is responding to this command but error in node-red received.  
I tried tcp type 'NORMAL' as well as 'RTU BUFFERED'.
2. no errors with modbus write node but heater is not responding.

See flows in attach. I don't see differences between the different nodes.  
Also see modbus documentation in attach.

debug partial output:

- datalenght error  
buffer: \<Buffer 18 b0 70 03 e6 a2 63\>,  
action: 'receive tcp port strings',  
modbus-serial data: \<Buffer 00 02 00 00 00 05 18 b0 70 03 e6\>
- value NAN (heater not responding to command)  
\<Buffer 18 b0 70 03 e6 a2 63\>,  
action: 'receive tcp port strings',  
modbus-serial data: \<Buffer 00 04 00 00 00 05 18 b0 70 03 e6\>

```auto
[{"id":"df9895fc.1d9bc8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"d24d8843.423868","type":"modbus-write","z":"df9895fc.1d9bc8","name":"","showStatusActivities":true,"showErrors":true,"unitid":"","dataType":"Coil","adr":"1","quantity":"1","server":"de3861d.00db0a","emptyMsgOnFail":true,"keepMsgProperties":false,"x":300,"y":80,"wires":[[],["5047a561.5e5c8c","18e34049.0c15a"]]},{"id":"e9173015.a459c","type":"inject","z":"df9895fc.1d9bc8","name":"","topic":"","payload":"255","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":80,"wires":[["d24d8843.423868"]]},{"id":"5047a561.5e5c8c","type":"debug","z":"df9895fc.1d9bc8","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":510,"y":120,"wires":[]},{"id":"f31a8a60.0cd698","type":"inject","z":"df9895fc.1d9bc8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":720,"wires":[["afeb507.502b3b"]]},{"id":"afeb507.502b3b","type":"function","z":"df9895fc.1d9bc8","name":"","func":"var buf=Buffer.alloc(2);\nbuf.writeUInt16BE(65280);\nmsg.payload = buf;\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":720,"wires":[["2b11e80d.2600f8"]]},{"id":"3e8225b2.b84ffa","type":"inject","z":"df9895fc.1d9bc8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":286,"wires":[["8347a1e8.d9fd6"]]},{"id":"8347a1e8.d9fd6","type":"function","z":"df9895fc.1d9bc8","name":"On","func":"msg.payload = {\n 'value' : 255,\n 'fc' : 5,\n 'unitid' : 16,\n 'address' : 1,\n 'quantity' : 1\n};\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":266,"wires":[["6291c251.38a57c"]]},{"id":"57b303d5.95ff8c","type":"function","z":"df9895fc.1d9bc8","name":"Off","func":"msg.payload = {\n 'value' : 0,\n 'fc' : 5,\n 'unitid' : 16,\n 'address' : 1,\n 'quantity' : 1\n};\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":326,"wires":[["6291c251.38a57c"]]},{"id":"41a2472b.6b7ca8","type":"inject","z":"df9895fc.1d9bc8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":326,"wires":[["57b303d5.95ff8c"]]},{"id":"1424f412.d586ac","type":"debug","z":"df9895fc.1d9bc8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":610,"y":306,"wires":[]},{"id":"a50e47a7.e69ee8","type":"comment","z":"df9895fc.1d9bc8","name":"Write Digital I/O","info":"","x":120,"y":246,"wires":[]},{"id":"8277ee51.c2843","type":"debug","z":"df9895fc.1d9bc8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":590,"y":720,"wires":[]},{"id":"3ede045d.6c5e4c","type":"comment","z":"df9895fc.1d9bc8","name":"modbus flex write","info":"","x":440,"y":266,"wires":[]},{"id":"f43a9634.8f0a88","type":"modbus-response","z":"df9895fc.1d9bc8","name":"","registerShowMax":20,"x":750,"y":346,"wires":[]},{"id":"2b11e80d.2600f8","type":"modbus-write","z":"df9895fc.1d9bc8","name":"","showStatusActivities":true,"showErrors":true,"unitid":"16","dataType":"Coil","adr":"1","quantity":"1","server":"de3861d.00db0a","emptyMsgOnFail":false,"keepMsgProperties":false,"x":420,"y":720,"wires":[[],["8277ee51.c2843","60c3d6f3.8daa48"]]},{"id":"6291c251.38a57c","type":"modbus-flex-write","z":"df9895fc.1d9bc8","name":"","showStatusActivities":true,"showErrors":true,"server":"de3861d.00db0a","emptyMsgOnFail":false,"keepMsgProperties":false,"x":440,"y":326,"wires":[["f43a9634.8f0a88"],["1424f412.d586ac"]]},{"id":"cc5ec9a7.4eecf8","type":"function","z":"df9895fc.1d9bc8","name":"read all Digital Outputs","func":"msg.payload = { 'value': msg.payload,\n 'fc': 1,\n 'unitid': 1,\n 'address': 0x0010 ,\n 'quantity': 8 } \n\nreturn msg;","outputs":1,"noerr":0,"x":1320,"y":160,"wires":[[]]},{"id":"a838ead2.34c1b8","type":"debug","z":"df9895fc.1d9bc8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","x":610,"y":500,"wires":[]},{"id":"bb468183.ef7db","type":"modbus-response","z":"df9895fc.1d9bc8","name":"","registerShowMax":20,"x":630,"y":560,"wires":[]},{"id":"bf971d5a.13681","type":"inject","z":"df9895fc.1d9bc8","name":"on dec","topic":"","payload":"255","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":520,"wires":[["96bbe6dc.427a18"]]},{"id":"f45007e1.0ee2e8","type":"inject","z":"df9895fc.1d9bc8","name":"off","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":600,"wires":[["96bbe6dc.427a18"]]},{"id":"f87df865.2cb628","type":"inject","z":"df9895fc.1d9bc8","name":"on hex","topic":"","payload":"[\"00FF\"]","payloadType":"bin","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":480,"wires":[["96bbe6dc.427a18"]]},{"id":"a8f16024.4c565","type":"function","z":"df9895fc.1d9bc8","name":"Startup Values","func":"msg.payload = { value:[false, false, false, false], \n'fc': 15, \n'unitid': 1, \n'address': 0, \n'quantity': 4 } \nreturn msg","outputs":1,"noerr":0,"x":1300,"y":120,"wires":[[]]},{"id":"c12f92c3.ea375","type":"inject","z":"df9895fc.1d9bc8","name":"Test off","topic":"","payload":"[0]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":900,"wires":[["326d6039.b4ed7"]]},{"id":"326d6039.b4ed7","type":"function","z":"df9895fc.1d9bc8","name":"Test","func":"msg.payload = { value: msg.payload, 'fc': 5, 'unitid': 16, 'address': 1 , 'quantity': 1 } \nreturn msg;","outputs":1,"noerr":0,"x":250,"y":900,"wires":[["338dac8e.023244"]]},{"id":"86465dab.2bb73","type":"comment","z":"df9895fc.1d9bc8","name":"The problem was that I had put 0010 as the address in the modbus write node instead of","info":"","x":1360,"y":280,"wires":[]},{"id":"3a69747c.da8e6c","type":"function","z":"df9895fc.1d9bc8","name":"","func":"msg.payload = new Buffer([0x01,0x03,0x0C,0x82,0x00,0x01,0x27,0x72]);","outputs":1,"noerr":0,"x":1110,"y":160,"wires":[[]]},{"id":"862551b4.62feb","type":"comment","z":"df9895fc.1d9bc8","name":"volgens filmpje is unit id slave device and address is register","info":"https://www.youtube.com/watch?v=47Lq2WLkfyE&ab_channel=FreeWaveTechnologies","x":1280,"y":200,"wires":[]},{"id":"b2f20e6d.4d51","type":"comment","z":"df9895fc.1d9bc8","name":"aangezien modbus tcp, is unit id overbodig omdat devices identificeren als ip address","info":"https://control.com/forums/threads/modbus-tcp-what-is-the-correct-usage-of-unit-id.38871/","x":1350,"y":240,"wires":[]},{"id":"18e34049.0c15a","type":"modbus-response","z":"df9895fc.1d9bc8","name":"","registerShowMax":20,"x":550,"y":80,"wires":[]},{"id":"60c3d6f3.8daa48","type":"modbus-response","z":"df9895fc.1d9bc8","name":"","registerShowMax":20,"x":500,"y":780,"wires":[]},{"id":"338dac8e.023244","type":"modbus-write","z":"df9895fc.1d9bc8","name":"","showStatusActivities":false,"showErrors":false,"unitid":"16","dataType":"Coil","adr":"1","quantity":"1","server":"de3861d.00db0a","emptyMsgOnFail":false,"keepMsgProperties":false,"x":300,"y":960,"wires":[["ac93bc1a.3d57e","f4cafceb.f4ca1"],["f4cafceb.f4ca1"]]},{"id":"ac93bc1a.3d57e","type":"modbus-response","z":"df9895fc.1d9bc8","name":"","registerShowMax":20,"x":460,"y":880,"wires":[]},{"id":"f4cafceb.f4ca1","type":"debug","z":"df9895fc.1d9bc8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","x":510,"y":960,"wires":[]},{"id":"ce0d7cb4.888c2","type":"inject","z":"df9895fc.1d9bc8","name":"Test On","topic":"","payload":"[255]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":960,"wires":[["326d6039.b4ed7"]]},{"id":"3f4e02cc.66682e","type":"modbus-flex-write","z":"df9895fc.1d9bc8","name":"","showStatusActivities":true,"showErrors":true,"server":"de3861d.00db0a","emptyMsgOnFail":false,"keepMsgProperties":false,"x":390,"y":480,"wires":[["a838ead2.34c1b8","bb468183.ef7db"],[]]},{"id":"96bbe6dc.427a18","type":"function","z":"df9895fc.1d9bc8","name":"Test","func":"msg.payload = { \n value: msg.payload, \n 'fc': 5, \n 'unitid': 16, \n 'address': 1, \n 'quantity': 1\n};\nreturn msg;","outputs":1,"noerr":0,"x":250,"y":540,"wires":[["3f4e02cc.66682e"]]},{"id":"dafe5b9b.3f9598","type":"comment","z":"df9895fc.1d9bc8","name":"This one is working but give data lenght error","info":"","x":210,"y":206,"wires":[]},{"id":"9f98505.1209cb","type":"comment","z":"df9895fc.1d9bc8","name":"Not working","info":"","x":110,"y":40,"wires":[]},{"id":"93d268e9.d29fa8","type":"comment","z":"df9895fc.1d9bc8","name":"This one with write node does not work. Neither with flex write node (I think)","info":"","x":300,"y":440,"wires":[]},{"id":"65e0dea9.1715","type":"comment","z":"df9895fc.1d9bc8","name":"Not working","info":"","x":110,"y":680,"wires":[]},{"id":"4690c901.df8578","type":"comment","z":"df9895fc.1d9bc8","name":"some comments and trials to keep","info":"","x":1200,"y":60,"wires":[]},{"id":"e28dde3d.056e6","type":"comment","z":"df9895fc.1d9bc8","name":"Not working","info":"","x":110,"y":860,"wires":[]},{"id":"de3861d.00db0a","type":"modbus-client","z":"","name":"MyRealMobusHeating","clienttype":"tcp","bufferCommands":false,"stateLogEnabled":true,"queueLogEnabled":false,"tcpHost":"192.168.0.50","tcpPort":"502","tcpType":"TPC-RTU-BUFFERED","serialPort":"USB\\ROOT_HUB30\\4&2a1bd118&0&0","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"","commandDelay":200,"clientTimeout":3000,"reconnectOnTimeout":true,"reconnectTimeout":2000,"parallelUnitIdsAllowed":false}]

```

[Building Management System.pdf](https://discourse.nodered.org/uploads/short-url/bZXZmSxQGa2QRBiiRCocv1rAGBV.pdf) (91.0 KB)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [8 February 2021 20:31 UTC](https://discourse.nodered.org/t/writing-coil-outputs-with-modbus-contrib-and-limited-device-modbus-documentation/39268/7 "2021-02-08T20:31:32Z")

</div>

Hi, thats good news .. i was wondering if you got it working.

man it shouldnt be so difficult .. Modbus Flex Write with Function Code (FC5) which is a single Coil write accepts as a `value` passed in with `msg.payload` either Boolean True or False or Number 1 or 0.

**Example that works with a modbus slave [simulator](https://sourceforge.net/projects/pymodslave/) :**

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/39a224d1a9d61da13c19f2df45a9339b050d3628.png)

```auto
[{"id":"c12f92c3.ea375","type":"inject","z":"df9895fc.1d9bc8","name":"Off - 0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":190,"y":120,"wires":[["326d6039.b4ed7"]]},{"id":"326d6039.b4ed7","type":"function","z":"df9895fc.1d9bc8","name":"FC5","func":"msg.payload = { \n \n 'value': msg.payload,\n 'fc': 5,\n 'unitid': 16,\n 'address': 1 ,\n 'quantity': 1\n \n} \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":390,"y":240,"wires":[["eb5b5c47.d1e6f8"]]},{"id":"f4cafceb.f4ca1","type":"debug","z":"df9895fc.1d9bc8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":240,"wires":[]},{"id":"ce0d7cb4.888c2","type":"inject","z":"df9895fc.1d9bc8","name":"On - 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":190,"y":180,"wires":[["326d6039.b4ed7"]]},{"id":"eb5b5c47.d1e6f8","type":"modbus-flex-write","z":"df9895fc.1d9bc8","name":"","showStatusActivities":true,"showErrors":true,"server":"de3861d.00db0a","emptyMsgOnFail":false,"keepMsgProperties":false,"x":570,"y":240,"wires":[["f4cafceb.f4ca1"],[]]},{"id":"888c403f.43b438","type":"comment","z":"df9895fc.1d9bc8","name":"Or","info":"","x":190,"y":240,"wires":[]},{"id":"2506bc42.435384","type":"inject","z":"df9895fc.1d9bc8","name":"Off - false","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":180,"y":300,"wires":[["326d6039.b4ed7"]]},{"id":"8885782a.d08d6","type":"inject","z":"df9895fc.1d9bc8","name":"On - true","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":180,"y":360,"wires":[["326d6039.b4ed7"]]},{"id":"de3861d.00db0a","type":"modbus-client","name":"MyRealMobusHeating","clienttype":"tcp","bufferCommands":false,"stateLogEnabled":true,"queueLogEnabled":false,"tcpHost":"192.168.0.50","tcpPort":"502","tcpType":"TPC-RTU-BUFFERED","serialPort":"USB\\ROOT_HUB30\\4&2a1bd118&0&0","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"","commandDelay":200,"clientTimeout":3000,"reconnectOnTimeout":true,"reconnectTimeout":2000,"parallelUnitIdsAllowed":false}]

```

---

<div class="post-metadata">

**Author:** ![wpeeters](https://avatars.discourse-cdn.com/v4/letter/w/f6c823/32.png) [@wpeeters](https://discourse.nodered.org/u/wpeeters)\
**Post date:** [8 February 2021 21:09 UTC](https://discourse.nodered.org/t/writing-coil-outputs-with-modbus-contrib-and-limited-device-modbus-documentation/39268/8 "2021-02-08T21:09:36Z")

</div>

Hi @UnborN ,  
You probably missed it but also tried that one. See attached picture.

 ![flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/d/7d4de8a0bb918ff127c8805171a2fe4176979b0b.jpeg)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [8 February 2021 21:23 UTC](https://discourse.nodered.org/t/writing-coil-outputs-with-modbus-contrib-and-limited-device-modbus-documentation/39268/9 "2021-02-08T21:23:46Z")

</div>

I saw it .. so this part of the flow that you show in the screenshot .. fails ?

Does it work when you use Serial with the USB to serial connection but fails when using the TCP to Serial converter ?

Do you have any screenshots of the setup in that TCP to serial converter ? or docs ?

---

<div class="post-metadata">

**Author:** ![wpeeters](https://avatars.discourse-cdn.com/v4/letter/w/f6c823/32.png) [@wpeeters](https://discourse.nodered.org/u/wpeeters)\
**Post date:** [10 February 2021 19:14 UTC](https://discourse.nodered.org/t/writing-coil-outputs-with-modbus-contrib-and-limited-device-modbus-documentation/39268/10 "2021-02-10T19:14:32Z")

</div>

@UnborN , well it gives error in node-red but device is responding with flex write node. But the error is a such that I can't do anything with it. I can send the command but I will never be sure if it is working or not because I can't get the coil status because it does not exist in the device.  
I can't say it will work with serial directly from node-red to device. Therefor I need to disconnect my raspberry with Lan connection and bring it poolhouse which does not have a lan connection. Much work to do this. But with serial directly from laptop with other software, yes it was working.

The modbus RTU to modbus TCP converter is a USR-W610. See [https://www.pusr.com/products/rs232/rs485-to-wifi-converters-usr-w610.html](https://www.pusr.com/products/rs232/rs485-to-wifi-converters-usr-w610.html).

Configuration, see attach:  
[settings wsr610.pdf](https://discourse.nodered.org/uploads/short-url/eDmvCkI3f89BlnehVghLmaAZ13g.pdf) (81.4 KB)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [10 February 2021 23:27 UTC](https://discourse.nodered.org/t/writing-coil-outputs-with-modbus-contrib-and-limited-device-modbus-documentation/39268/11 "2021-02-10T23:27:01Z")

</div>

> [@wpeeters](#):
>
> well it gives error in node-red but device is responding with flex write node

Can you share a screeshot of this error ?

> [@wpeeters](#):
>
> I can send the command but I will never be sure if it is working or not because I can't get the coil status

Indeed 😉 that can be a problem if your device doesnt support reading Coils also  
What have you tried for this ? I believe reading a single Coil is **Function code 1** with Modbus Flex Getter node ?!

---

<div class="post-metadata">

**Author:** ![wpeeters](https://avatars.discourse-cdn.com/v4/letter/w/f6c823/32.png) [@wpeeters](https://discourse.nodered.org/u/wpeeters)\
**Post date:** [11 February 2021 07:14 UTC](https://discourse.nodered.org/t/writing-coil-outputs-with-modbus-contrib-and-limited-device-modbus-documentation/39268/12 "2021-02-11T07:14:02Z")

</div>

> [@UnborN](#):
>
> Can you share a screeshot of this error ?

Well, that's the error you could see in one of the previous posts:

- datalenght error  
buffer: \<Buffer 18 b0 70 03 e6 a2 63\>,  
action: 'receive tcp port strings',  
modbus-serial data: \<Buffer 00 02 00 00 00 05 18 b0 70 03 e6\>

> [@UnborN](#):
>
> What have you tried for this ? I believe reading a single Coil is **Function code 1** with Modbus Flex Getter node ?!

Yes, I tried but no response. It is also clearly mentioned in the documentation that on and off write coils are the only commands. This was also repeated in the mailing with manufacturer.

I'm out of idea's. That error need to mean something but I can't find any solution. The only reference I could find on the net was to use rtu buffered but that is not working neither.

I'm still wondering if it has anything to do with those two hex values mentioned in the documentation.

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [14 February 2021 04:36 UTC](https://discourse.nodered.org/t/writing-coil-outputs-with-modbus-contrib-and-limited-device-modbus-documentation/39268/13 "2021-02-14T04:36:56Z")

</div>

In your first post you mentioned that the default settings of your modbus heater are

> [@wpeeters](#):
>
> The default factory settings are: Baud =19200 Address = 16 (decimal) Parity = Even

Are these correct ?  
Shouldnt those match with the settings of the USR-W610 ?  
from the pdf you sent they are not the same  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/5/c52d43b3db77402699aecf64c31b8838aa5f9296.png)

Also play around with the settings _UART Autoframe_ or _Registered Package Type_ .. the manual doesnt even mention what those are all about.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [15 April 2021 04:37 UTC](https://discourse.nodered.org/t/writing-coil-outputs-with-modbus-contrib-and-limited-device-modbus-documentation/39268/14 "2021-04-15T04:37:52Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
