# Convert a floating data variable to holding register on a Modbus Server (Slave) TCP

**URL:** <https://discourse.nodered.org/t/convert-a-floating-data-variable-to-holding-register-on-a-modbus-server-slave-tcp/87507>\
**Category:** Industrial\
**Tags:** modbus\
**Created:** [26 April 2024 06:48 UTC](https://discourse.nodered.org/t/convert-a-floating-data-variable-to-holding-register-on-a-modbus-server-slave-tcp/87507 "2024-04-26T06:48:07Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alphagamma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alphagamma/32/90472_2.png) [@Alphagamma](https://discourse.nodered.org/u/Alphagamma)\
**Post date:** [26 April 2024 06:48 UTC](https://discourse.nodered.org/t/convert-a-floating-data-variable-to-holding-register-on-a-modbus-server-slave-tcp/87507/1 "2024-04-26T06:48:07Z")

</div>

Dear all,  
I'm using Node-RED version: v3.1.9 Node.js version: v20.12.2.  
I need to pass two variables (now i'm trying with just one, for the sake of simplicity) to a PLC and to do this I created a Modbus Server node like this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/e/be411593f5f9464f41cbe3a194870ddba59bd203.png)

Now I'm having two problems:

- The first one is, how can I send negative integer values without having an error?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/c/acb4b6562524c81c535534fd27270709392dd9b5.png)

- The second is, how I can send floating unsigned value?  
Thanks in advance if someone can help me address the solution,  
Marco

---

<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:** [26 April 2024 08:06 UTC](https://discourse.nodered.org/t/convert-a-floating-data-variable-to-holding-register-on-a-modbus-server-slave-tcp/87507/2 "2024-04-26T08:06:08Z")

</div>

> [@Alphagamma](#):
>
> I need to pass two variables (now i'm trying with just one, for the sake of simplicity) to a PLC

What is the make and model of the PLC.

Why are you creating a server? Surely if the PLC supports Modbus it has a server that you simply connect to and set values using the read and write functions provided by the modbus package

* * *

As for your question around floats: Modbus is all about integers. 16 bit unsigned to be specific. that means you can write 0 ~ 65535 to a register. That does not mean you cannot send floating point or negative values, but it is better if you can work with integers. for example, often if I needed a number between 0.0 and 100.0, I simply upscale by 100 so that `12` = `0.12` and `12345` = `123.45`.

However, if you REALLY need to use float or signed integers, you need to convert them to UINT16 value(s). That sometimes means you need to write multiple WORDs (in the case of an IEEE754 float, that is 64bit value).

If you need further help, please provide specifics like the PLC make, model. the PLC register size and type etc.

---

<div class="post-metadata">

**Author:** ![Alphagamma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alphagamma/32/90472_2.png) [@Alphagamma](https://discourse.nodered.org/u/Alphagamma)\
**Post date:** [26 April 2024 10:28 UTC](https://discourse.nodered.org/t/convert-a-floating-data-variable-to-holding-register-on-a-modbus-server-slave-tcp/87507/3 "2024-04-26T10:28:03Z")

</div>

Hi Steve,  
thanks for pointing me out the trick about the upscaling.  
Now, for the make and model, it's a BMS controller, in particular a Schneider Electric SmartX Controller AS-P.

However, I wanted to create a Modbus TCP Server because i would like that the flow and the device where the flow is running, would be like a "vendor neutral" device slave, with its own register. Is this feasible with this configuration?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/47b69399a9c3d5dc3f72dc1eb6a7b130789955ef.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/f/cfc1d70a6e05eddc52b25ff6feb3e4e42fe18307.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/3/033e30f9b67ed4bc7e3f3c5824ba3fd4dae2c523.png)

I see in the output of the Modbus node an array of values, I've tried to inject the maximum value like you suggested and I see that it fills only the first two elements of the array, so I suppose each one has a value of UINT8, is it right? Why so many elements for one chunk of memory in holdings?  
An what about the negative sign (-)? How can be read and interpreted from the node?  
Thank you for taking the time to answer me!  
Marco

---

<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:** [26 April 2024 10:34 UTC](https://discourse.nodered.org/t/convert-a-floating-data-variable-to-holding-register-on-a-modbus-server-slave-tcp/87507/4 "2024-04-26T10:34:13Z")

</div>

Dont try to populate values of the server via its input.

Treat it like any other external modbus device & use the Modbus Read/Write/getter/setter nodes.

As for formatting data, i recommend you spend some time getting to grips with data types and how they are represented within PLCs and their real byte counterparts.

To aid you in formatting and extracting data types from arrays of UINT16, i recommend you use the `buffer-parser` and `buffer-maker` nodes from [`node-red-contrib-buffer-parser`](https://flows.nodered.org/node/node-red-contrib-buffer-parser)

Make sure you check out the built in example CTRL-I → `Examples` →

---

<div class="post-metadata">

**Author:** ![Alphagamma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alphagamma/32/90472_2.png) [@Alphagamma](https://discourse.nodered.org/u/Alphagamma)\
**Post date:** [26 April 2024 14:37 UTC](https://discourse.nodered.org/t/convert-a-floating-data-variable-to-holding-register-on-a-modbus-server-slave-tcp/87507/5 "2024-04-26T14:37:01Z")

</div>

> [@Steve-Mcl](#):
>
> Treat it like any other external modbus device & use the Modbus Read/Write/getter/setter nodes.

So, are you saying that: i have to write the value coming from my procedures to the server (the same Node-RED), after that this value stored into the holding register can be read from the PLC. I have interpreted it right?

> [@](#):
>
> As for formatting data, i recommend you spend some time getting to grips with data types and how they are represented within PLCs and their real byte counterparts.

Yes, I will do. Thank you

> [@](#):
>
> To aid you in formatting and extracting data types from arrays of UINT16, i recommend you use the `buffer-parser` and `buffer-maker` nodes from [`node-red-contrib-buffer-parser`](https://flows.nodered.org/node/node-red-contrib-buffer-parser)

Yep, I already used this nodes (thanks for developing them) but I'm very beginner with Node-RED, so it's a steep curve for me yet.  
Marco

---

<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:** [26 April 2024 14:51 UTC](https://discourse.nodered.org/t/convert-a-floating-data-variable-to-holding-register-on-a-modbus-server-slave-tcp/87507/6 "2024-04-26T14:51:16Z")

</div>

> [@Alphagamma](#):
>
> , are you saying that: i have to write the value coming from my procedures to the server (the same Node-RED), after that this value stored into the holding register can be read from the PLC. I have interpreted it right?

Correct.

> [@Alphagamma](#):
>
> but I'm very beginner with Node-RED

Maybe these will help:

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 April 2024 15:39 UTC](https://discourse.nodered.org/t/convert-a-floating-data-variable-to-holding-register-on-a-modbus-server-slave-tcp/87507/7 "2024-04-26T15:39:31Z")

</div>

> [@Steve-Mcl](#):
>
> > [@Alphagamma](#):
> >
> > , are you saying that: i have to write the value coming from my procedures to the server (the same Node-RED), after that this value stored into the holding register can be read from the PLC. I have interpreted it right?
> 
> Correct.

In that case I don't understand. If values are written to a modbus server provided by the modbus-server node, how does that make them available in the PLC?

---

<div class="post-metadata">

**Author:** ![Alphagamma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alphagamma/32/90472_2.png) [@Alphagamma](https://discourse.nodered.org/u/Alphagamma)\
**Post date:** [26 April 2024 16:57 UTC](https://discourse.nodered.org/t/convert-a-floating-data-variable-to-holding-register-on-a-modbus-server-slave-tcp/87507/8 "2024-04-26T16:57:51Z")

</div>

I try to reply, just to to understand if my guessing is right: the same value written to a variable(s) will be available to the PLC by reading it indexed by its register created on the Modbus-Server node.

---

<div class="post-metadata">

**Author:** ![Alphagamma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alphagamma/32/90472_2.png) [@Alphagamma](https://discourse.nodered.org/u/Alphagamma)\
**Post date:** [26 April 2024 17:08 UTC](https://discourse.nodered.org/t/convert-a-floating-data-variable-to-holding-register-on-a-modbus-server-slave-tcp/87507/9 "2024-04-26T17:08:13Z")

</div>

> [@Steve-Mcl](#):
>
> I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Thanks Steve, I had already seen them (although I would certainly need to watch them again).  
I need to get my hands dirty with some projects.

---

<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:** [26 April 2024 19:18 UTC](https://discourse.nodered.org/t/convert-a-floating-data-variable-to-holding-register-on-a-modbus-server-slave-tcp/87507/10 "2024-04-26T19:18:03Z")

</div>

A modbus server typically has a memory bank/file where registers exist. A client connects and requests values.

If the OP doesn't set values in the server they will be zero.

Of course the client (in this case a PLC) can read and write values in a server, but that's not really useful by itself. Typically a server has internal processes that populated it's own registers that clients can access/read.

I'm certain non of that is news to you but, I've seen first hand (and in a thread recently) where inputting values into the server via it's input is a bit odd / not sane. So the suggestion was simply set them using a write/setter node as I know that definitely works.

---

<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:** [26 April 2024 19:56 UTC](https://discourse.nodered.org/t/convert-a-floating-data-variable-to-holding-register-on-a-modbus-server-slave-tcp/87507/11 "2024-04-26T19:56:42Z")

</div>

> [@Steve-Mcl](#):
>
> I'm certain non of that is news to you but, I've seen first hand (and in a thread recently) where inputting values into the server via it's input is a bit odd

> [@Modbus Server not working](https://discourse.nodered.org/t/modbus-server-not-working/86502/6):
>
> Steve's method works +1 Updated the Test Flow to include a Modbus Write node instead [{"id":"a58ce8e2.9210d8","type":"debug","z":"937cb040.d8e16","name":"coils Buffer","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":100,"wires":[]},{"id":"c45f9a38fafeea33","type":"debug","z":"937cb040.d8e16","name":"holding Buffer","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":…

---

<div class="post-metadata">

**Author:** ![Alphagamma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alphagamma/32/90472_2.png) [@Alphagamma](https://discourse.nodered.org/u/Alphagamma)\
**Post date:** [26 April 2024 20:10 UTC](https://discourse.nodered.org/t/convert-a-floating-data-variable-to-holding-register-on-a-modbus-server-slave-tcp/87507/12 "2024-04-26T20:10:29Z")

</div>

Thanks Steve, just found some minutes ago your reply in that thread.

---

<div class="post-metadata">

**Author:** ![Alphagamma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alphagamma/32/90472_2.png) [@Alphagamma](https://discourse.nodered.org/u/Alphagamma)\
**Post date:** [26 April 2024 20:15 UTC](https://discourse.nodered.org/t/convert-a-floating-data-variable-to-holding-register-on-a-modbus-server-slave-tcp/87507/13 "2024-04-26T20:15:07Z")

</div>

Thanks to @UnborN too for the flow suggested

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 April 2024 20:55 UTC](https://discourse.nodered.org/t/convert-a-floating-data-variable-to-holding-register-on-a-modbus-server-slave-tcp/87507/14 "2024-04-26T20:55:03Z")

</div>

> [@Steve-Mcl](#):
>
> the client (in this case a PLC)

That is what I was missing, I had not realised that the PLC will be running as a modbus client.

---

<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:** [10 May 2024 20:55 UTC](https://discourse.nodered.org/t/convert-a-floating-data-variable-to-holding-register-on-a-modbus-server-slave-tcp/87507/15 "2024-05-10T20:55:59Z")

</div>

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