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

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:

Now I'm having two problems:

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

image

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

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.

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

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

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

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

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?

Yes, I will do. Thank you

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

Correct.

Maybe these will help:

I recommend watching this playlist: Node-RED Essentials. 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.

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?

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.

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.

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.

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

Thanks to @UnborN too for the flow suggested

1 Like

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