# Writing negative value in Modbus Write Node

**URL:** https://discourse.nodered.org/t/writing-negative-value-in-modbus-write-node/74579
**Category:** Industrial
**Tags:** modbus
**Created:** [2 February 2023 03:30 UTC](https://discourse.nodered.org/t/writing-negative-value-in-modbus-write-node/74579 "2023-02-02T03:30:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mahmudul101](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@mahmudul101](https://discourse.nodered.org/u/mahmudul101)
#### Post date: [2 February 2023 03:30 UTC](https://discourse.nodered.org/t/writing-negative-value-in-modbus-write-node/74579/1 "2023-02-02T03:30:13Z")

</div>

Hello, Currently I'm doing a project where I need to write a Modbus-write node at the address 5801 with function code 6. The Modbus-write node's description says that the msg.payload must be a single value between 0- 65535. But I need to write a negative value here as an input. How can I write a negative value in the specific address with function code 6? Is there any alternative way of writing a  
negative value as input in node-red Modbus write node?

 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/5/25a0fdc24f3751c7078259a948c9fb42b3b9dab9.jpeg)  
 ![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/672784bd4e49c1eeed6ff9707398157e001eb7f1.jpeg)

---

<div class="post-metadata">

### Author: ![MountainKing91](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mountainking91/32/59516_2.png) [@MountainKing91](https://discourse.nodered.org/u/MountainKing91)
#### Post date: [26 February 2023 16:15 UTC](https://discourse.nodered.org/t/writing-negative-value-in-modbus-write-node/74579/2 "2023-02-26T16:15:51Z")

</div>

> [@mahmudul101](#):
>
> The Modbus-write node's description says that the msg.payload must be a single value between 0- 65535

This is because modbus registers are of WORD datatype (16-bit registers), which in IT world may be described as "unsigned 16 bit integer". The only way to write everything else in a modbus register is to "encode it".  
You can try using [node-red-contrib-buffer-parser](https://flows.nodered.org/node/node-red-contrib-buffer-parser) or writing a little bit of code in a function node using [this](https://nodejs.org/api/buffer.html). Let me encourage you in using the first way if you're not familiar with all the modbus encoding nuances :).

---

<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: [27 April 2023 16:15 UTC](https://discourse.nodered.org/t/writing-negative-value-in-modbus-write-node/74579/3 "2023-04-27T16:15:52Z")

</div>

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