# Node-red-contrib-serial-modbus serial out - writing to a coil

**URL:** https://discourse.nodered.org/t/node-red-contrib-serial-modbus-serial-out-writing-to-a-coil/69450
**Category:** General
**Created:** [23 October 2022 06:40 UTC](https://discourse.nodered.org/t/node-red-contrib-serial-modbus-serial-out-writing-to-a-coil/69450 "2022-10-23T06:40:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![JohnMurfett](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@JohnMurfett](https://discourse.nodered.org/u/JohnMurfett)
#### Post date: [23 October 2022 06:40 UTC](https://discourse.nodered.org/t/node-red-contrib-serial-modbus-serial-out-writing-to-a-coil/69450/1 "2022-10-23T06:40:04Z")

</div>

I am trying to use the node-red-contrib-serial-modbus package to write to a modbus coil which has register value 1.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/4/8421ffa056748323dec07e836e061fbbf90bfaa9.png)  
I have not found any documentation around what the payload should look like for the messages sent to the serial-out node, but what ever I try I just get "ERR\_INVALID\_OPT\_VALUE" error.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/9/d98a5789233b88fac10d016099fb377da54328e1.png)  
Here is the doco from EPEVER (the modbus device is a solar controller):  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/8/b84647ededeaea6616cdef8fb3fddb0bf7d201fe.png)

Does anyone know what the payload shape should be to send an on or off command to a modbus coil?

---

<div class="post-metadata">

### Author: ![JohnMurfett](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@JohnMurfett](https://discourse.nodered.org/u/JohnMurfett)
#### Post date: [23 October 2022 14:24 UTC](https://discourse.nodered.org/t/node-red-contrib-serial-modbus-serial-out-writing-to-a-coil/69450/2 "2022-10-23T14:24:39Z")

</div>

I worked this out! The Modbus-Serial Out expects a javascript Buffer created from an array of two integers. This is because the modbus registers in the EPEVER Solar Controller are 16bit, so need two bytes to represent them.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/4/d4ae152ad01def4d8f7ff90428a6f4eea6fa88eb.png)  
I was not familar with the nodejs "Buffer" before today.

---

<div class="post-metadata">

### Author: ![madhouse](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@madhouse](https://discourse.nodered.org/u/madhouse)
#### Post date: [23 October 2022 20:10 UTC](https://discourse.nodered.org/t/node-red-contrib-serial-modbus-serial-out-writing-to-a-coil/69450/3 "2022-10-23T20:10:01Z")

</div>

Glad you got it working!

As another option, you could install node-red-contrib-modbus and try that out. I don't know about the nodes you're using, but I haven't found anything yet contrib-modbus can't handle. Not saying there isn't something. I just haven't found it. It may save the need to use a buffer object though which may make using your MODBUS setup easier. You're call.

---

<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: [6 November 2022 20:10 UTC](https://discourse.nodered.org/t/node-red-contrib-serial-modbus-serial-out-writing-to-a-coil/69450/4 "2022-11-06T20:10:25Z")

</div>

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