# Newbie, having problem setting a coil with Modbus RTU

**URL:** <https://discourse.nodered.org/t/newbie-having-problem-setting-a-coil-with-modbus-rtu/24482>\
**Category:** General\
**Created:** [8 April 2020 19:46 UTC](https://discourse.nodered.org/t/newbie-having-problem-setting-a-coil-with-modbus-rtu/24482 "2020-04-08T19:46:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hyuggs](https://avatars.discourse-cdn.com/v4/letter/h/ebca7d/32.png) [@Hyuggs](https://discourse.nodered.org/u/Hyuggs)\
**Post date:** [8 April 2020 19:46 UTC](https://discourse.nodered.org/t/newbie-having-problem-setting-a-coil-with-modbus-rtu/24482/1 "2020-04-08T19:46:04Z")

</div>

Hello,  
I'm trying to write a single coil on a modbus RTU relay board (RS485).  
I'm using Modbus-contrib-serial Library.  
I'm able to read value from another board on the same bus using Modbus serial In  
I'm able to set the coil using another program. (  
[19:44:28,813] \<--:01 05 00 07 FF 00 3D FB  
[19:44:28,891] --\>:01 05 00 07 FF 00 3D FB  
[19:44:47,641] \<--:01 05 00 08 00 00 4C 08  
[19:44:47,703] --\>:01 05 00 08 00 00 4C 08 )  
For the case device address is 01 coil is #7.

Can someone help me with the parameters I need to pass to modbus serial out ?  
I tried to format a buffer using binary rpm without success  
[0,5,0,0,0,7,255,0]

```auto
[{"id":"bce5d2b8.b20d9","type":"debug","z":"f8edcdbe.3d29c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":910,"y":2720,"wires":[]},{"id":"63a52c55.0c9b64","type":"function","z":"f8edcdbe.3d29c","name":"Set Modbus Read Parameters for Serial Number","func":"//Fermer relais #8 \n//[19:44:28,891] -->:01 05 00 07 FF 00 3D FB \n//Ca marche, les adresses vont de 00 a 0F\nmsg.payload = { //'unitid': 0x01,\n 'fc': 0x05,\n 'address': 0x007, // read address\n 'type': 0xFF00\n //,'chc': 0x3DFB\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":860,"y":2860,"wires":[["bce5d2b8.b20d9","933c5f71.26dea"]]},{"id":"7d9598cd.2e6b78","type":"inject","z":"f8edcdbe.3d29c","name":"","topic":"/1","payload":"On","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"4","x":450,"y":2860,"wires":[["bce5d2b8.b20d9","63a52c55.0c9b64"]]},{"id":"592b7c3.7a94c84","type":"modbusSerial out","z":"f8edcdbe.3d29c","port":"773e9c89.131534","slave":"","start":"0","dtype":"coil","topic":"","name":"","x":1510,"y":2860,"wires":[]},{"id":"a10f743c.7bbb58","type":"inject","z":"f8edcdbe.3d29c","name":"","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"4","x":450,"y":2960,"wires":[["bce5d2b8.b20d9","61cafbf2.78d8d4"]]},{"id":"933c5f71.26dea","type":"binary","z":"f8edcdbe.3d29c","name":"","property":"payload","pattern":"b16 => fc, b32 => address ,b16 => type","x":1230,"y":2860,"wires":[["592b7c3.7a94c84","bce5d2b8.b20d9"]]},{"id":"61cafbf2.78d8d4","type":"function","z":"f8edcdbe.3d29c","name":"Set Modbus Read Parameters for Serial Number","func":"//Fermer relais #8 \n//[19:44:28,891] -->:01 05 00 07 FF 00 3D FB \n//Ca marche, les adresses vont de 00 a 0F\nmsg.payload = { // 'unitid': 0x01,\n 'fc': 0x05,\n 'address': 0x007, // read address\n 'type': 0x0000\n //'chc': 0x3DFB\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":860,"y":2960,"wires":[["933c5f71.26dea"]]},{"id":"773e9c89.131534","type":"modbusSerialConfig","z":"","port":"/dev/ttyUSB0","baud":"9600","data":"8","parity":"none","stop":"1","name":""}]

```

thanks for your help

---

<div class="post-metadata">

**Author:** ![rromele](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rromele/32/18431_2.png) [@rromele](https://discourse.nodered.org/u/rromele)\
**Post date:** [8 April 2020 22:40 UTC](https://discourse.nodered.org/t/newbie-having-problem-setting-a-coil-with-modbus-rtu/24482/2 "2020-04-08T22:40:52Z")

</div>

Hi,  
I can't import your code, check if you have formatted it correctly

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [9 April 2020 09:53 UTC](https://discourse.nodered.org/t/newbie-having-problem-setting-a-coil-with-modbus-rtu/24482/3 "2020-04-09T09:53:18Z")

</div>

I've edited your post and fixed the import,

---

<div class="post-metadata">

**Author:** ![Hyuggs](https://avatars.discourse-cdn.com/v4/letter/h/ebca7d/32.png) [@Hyuggs](https://discourse.nodered.org/u/Hyuggs)\
**Post date:** [9 April 2020 16:50 UTC](https://discourse.nodered.org/t/newbie-having-problem-setting-a-coil-with-modbus-rtu/24482/4 "2020-04-09T16:50:27Z")

</div>

Thanks for the format correction.

I've made several test today with monitoring of data on the bus:  
a) 'modbus serial out' node seems to be limited to multiple coil writing ( 0F code when coil is selected)  
I'm able to select type of action ; device address(01) ;start address (0A) through menu but still have no control on datas probably due to input (mis-) formatting.  
reading on the bus is like this --\>:01 0F 00 0A 00 08 01 04 67 57

b) I also tried modbus write (node-red-contrib-modbus) but I doesn't initialize (Always restarting). @9600baud 8bit +1stop also

On top of this my chinese board support single coil write but I'm not able for the moment of a multiple writing. I Don't expect that much support from supplier but it is on the way.

Any suggestion / direction is welcome.

Is it possible to pass a complete message and let the node just deal with CRC?

note: I noticed a unknown (at least to me) message just after a deploy: 01 _19_ 80 00 80 00 01 9F BA  
EE. Does someone knows what 19 stand for ?

---

<div class="post-metadata">

**Author:** ![rromele](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rromele/32/18431_2.png) [@rromele](https://discourse.nodered.org/u/rromele)\
**Post date:** [10 April 2020 21:02 UTC](https://discourse.nodered.org/t/newbie-having-problem-setting-a-coil-with-modbus-rtu/24482/5 "2020-04-10T21:02:44Z")

</div>

Hi,

**01 05 00 07**  
if it can help you it should be like this:  
01 tool id  
05 single coil write function  
0007 memory area to write to.

you should still get the protocol manual to see if any characters are needed at the end of the string (CR).

to write also try to use the node node-red-contrib-modubus -\> "ModbusWrite"

![mdb1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/d/5d63e36df346b9215fc07c779a689fd6fe9d41e5.jpeg) ![mdb2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/6/c627145e5afd4ec6da20686bc29d4874ff87cca8.jpeg)

---

<div class="post-metadata">

**Author:** ![Hyuggs](https://avatars.discourse-cdn.com/v4/letter/h/ebca7d/32.png) [@Hyuggs](https://discourse.nodered.org/u/Hyuggs)\
**Post date:** [13 April 2020 17:15 UTC](https://discourse.nodered.org/t/newbie-having-problem-setting-a-coil-with-modbus-rtu/24482/6 "2020-04-13T17:15:00Z")

</div>

Hello, I've made a fresh install with noobs and magic has worked!  
node-red-contrib-modubus -\> "ModbusWrite" is now working.

Thanks for your support.

---

<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:** [12 June 2020 17:15 UTC](https://discourse.nodered.org/t/newbie-having-problem-setting-a-coil-with-modbus-rtu/24482/7 "2020-06-12T17:15:02Z")

</div>

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