# Help with Modbus write

**URL:** https://discourse.nodered.org/t/help-with-modbus-write/95331
**Category:** General
**Tags:** modbus
**Created:** [11 February 2025 19:31 UTC](https://discourse.nodered.org/t/help-with-modbus-write/95331 "2025-02-11T19:31:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)
#### Post date: [11 February 2025 19:31 UTC](https://discourse.nodered.org/t/help-with-modbus-write/95331/1 "2025-02-11T19:31:13Z")

</div>

Greetings. I can retrieve via _ **FC 4: Read Input Registers** _ the Actual and Setpoint values from my Modbus RTU enabled temperature controller. Now I want to try to write the setpoint using FC 6.

Both flows are attached. I do not get any errors or output from the Write flow.

```auto
[{"id":"d6f6bf810ef3e905","type":"modbus-read","z":"f20b61e62e9f6292","name":"temperature","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"showWarnings":true,"unitid":"1","dataType":"InputRegister","adr":"123","quantity":"15","rate":"60","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"a1b3011ddb70921d","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":130,"y":100,"wires":[["065484719b48680c"],[]]},{"id":"065484719b48680c","type":"buffer-parser","z":"f20b61e62e9f6292","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int16be","name":"MB30123","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"MB30137","offset":28,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"fanOutMultipleResult":false,"setTopic":false,"outputs":1,"x":330,"y":100,"wires":[["5ef94a4ed46ae1ff"]]},{"id":"5ef94a4ed46ae1ff","type":"function","z":"f20b61e62e9f6292","name":"","func":"msg.payload = [\n [{\n temperature: msg.payload.MB30123\n },\n {\n MeasType:\"actual\",\n EquipNumber:\"217\"\n }],\n [{\n temperature: msg.payload.MB30137\n },\n {\n MeasType:\"setpoint\",\n EquipNumber:\"217\"\n }]\n];\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":100,"wires":[["efa94b00a95071e5"]]},{"id":"efa94b00a95071e5","type":"debug","z":"f20b61e62e9f6292","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":700,"y":40,"wires":[]},{"id":"392812d56cb9a378","type":"function","z":"f20b61e62e9f6292","name":"function 2","func":"msg.payload = {\n 'value': msg.payload,\n 'fc': 6,\n 'unitid': 20,\n 'address': 137,\n 'quantity': 1\n}\n\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":160,"wires":[["aceb431c7c9e1380"]]},{"id":"aceb431c7c9e1380","type":"modbus-flex-write","z":"f20b61e62e9f6292","name":"","showStatusActivities":false,"showErrors":false,"showWarnings":true,"server":"a1b3011ddb70921d","emptyMsgOnFail":false,"keepMsgProperties":false,"delayOnStart":false,"startDelayTime":"","x":510,"y":160,"wires":[["44b975de9deda924"],[]]},{"id":"b75a776cc0b033dc","type":"inject","z":"f20b61e62e9f6292","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"99","payloadType":"num","x":90,"y":160,"wires":[["392812d56cb9a378"]]},{"id":"44b975de9deda924","type":"debug","z":"f20b61e62e9f6292","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":760,"y":160,"wires":[]},{"id":"a1b3011ddb70921d","type":"modbus-client","name":"USB0","clienttype":"serial","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"failureLogEnabled":true,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB0","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"500","serialAsciiResponseStartDelimiter":"0x3A","unit_id":"","commandDelay":1,"clientTimeout":8000,"reconnectOnTimeout":true,"reconnectTimeout":5000,"parallelUnitIdsAllowed":false,"showErrors":true,"showWarnings":true,"showLogs":true}]

```

In my flow, I am attemping to write the value 99 via FC 6. The slave address of the device is 20 and the address for the setpoint is 137.

```auto
msg.payload = {
    'value': msg.payload,
    'fc': 6,
    'unitid': 20,
    'address': 137,
    'quantity': 1
}

return msg

```

The doc for this controller is [here](https://supersystems.com/wp-content/uploads/7EK_31080_Relay_Manual_Operation.pdf) (unfortunately little or no Modbus info) and a sister product (with much more Modbus info) is [here](https://supersystems.com/wp-content/uploads/AC20_Manual_Communications_Reference.pdf). Thanks in advance for any help here. I have done this successfully with Allen Bradley VFDs but that has not worked with this controller.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [11 February 2025 20:24 UTC](https://discourse.nodered.org/t/help-with-modbus-write/95331/2 "2025-02-11T20:24:27Z")

</div>

> [@grant1](#):
>
> I do not get any errors or output from the Write flow.

You should enable errors in the nodes config

> [@grant1](#):
>
> I am attemping to write the value 99

Looking at that manual, it seems to be linked to the prior register. Try setting both.

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

---

<div class="post-metadata">

### Author: ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)
#### Post date: [12 February 2025 01:25 UTC](https://discourse.nodered.org/t/help-with-modbus-write/95331/3 "2025-02-12T01:25:16Z")

</div>

Thank you @Steve-Mcl

I had overlooked this in the manual....

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

To get it working, I send this via one flow (note that I had to use FC 5):

```auto
msg.payload = {
    'value': msg.payload,
    'fc': 5,
    'unitid': 20,
    'address': 218,
    'quantity': 1
}

return msg

```

and then this within 3 seconds of enabling Modbus bit 218 (note FC 6 and also as @Steve-Mcl pointed out, I had to use address 138 instead of 137)

```auto
msg.payload = {
    'value': msg.payload,
    'fc': 6,
    'unitid': 20,
    'address': 138,
    'quantity': 1
}

return msg

```

---

<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: [26 February 2025 01:26 UTC](https://discourse.nodered.org/t/help-with-modbus-write/95331/4 "2025-02-26T01:26:14Z")

</div>

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