IMD SolutionComputing LibraryShop main store

How-to

Publish Flexy tags as Modbus TCP holding registers

Edge computing and IIoT Published 7 min read By IMD Solution engineering team

Short answer

Three settings decide whether a Flexy tag reads correctly over Modbus TCP: Force Read-Only sets the register type (ticked gives a read-only input register, unticked a read-write holding register), a zero-based client needs the Flexy address minus one, and a float tag needs Use 32-bit format with little-endian word order. A constant zero almost always means the read function does not match the published register type.

On this page
  1. How do I enable the Flexy Modbus TCP server?
  2. Which register type does each Flexy tag publish as?
  3. Why does a Flexy tag read a constant zero over Modbus TCP?
  4. Why is the Flexy register address off by one?
  5. How do I publish a float tag over Modbus TCP?
  6. Can a Modbus TCP client write a value back to a Flexy tag?
  7. How do I verify a published tag before relying on it?
  8. Which setting do I change for which symptom?
  9. Questions asked

A Flexy publishes its tags over Modbus TCP correctly once three settings match the client reading them: the register type that the tag's Force Read-Only checkbox selects, the one-register offset between the Flexy's numbering and a zero-based client, and Use 32-bit format with little-endian word mapping on float tags. Get those three right and the tag reads; get one wrong and the usual symptom is a constant 0 on a tag the Flexy itself shows live. The sections below take the settings in the order you meet them: enable the server, fix each tag's register type, line up the addressing, publish floats, prove the write path, verify, and map the symptoms back to the setting that causes them.

How do I enable the Flexy Modbus TCP server? #

In the Flexy web interface, open Tags, then IO Servers, then IO Servers List, then Modbus, tick the Ewon Server checkbox under the MODBUS TCP Server heading, and set the Modbus Unit Address, the slave ID the Flexy answers to — the reference configuration uses 100.

The Modbus Unit Address is the value the client presents as its unit ID on every request, so whatever you enter here is what the client must carry. The tag list itself needs no extra step: every tag in the Flexy is publishable the moment the server is on, and each tag's own checkboxes decide how it is published. If a second client will poll the same server, the sharing behavior of one Modbus TCP server serving two clients is covered in When one Modbus TCP server can serve two clients.

Which register type does each Flexy tag publish as? #

A tag with Force Read-Only ticked publishes as an input register that clients can only read, and a tag with it unticked publishes as a holding register that clients can read and write — pick it per tag before the client is configured.

Force Read-Only is a checkbox on the tag itself, and the checkbox alone decides the register type. Ticked, the tag joins the input-register block: clients read it with function 04, and no write to it succeeds. Unticked, it joins the holding-register block: clients read it with function 03 and write it with the holding-register write functions, 06 for one register and 16 for a block. Choose by role: tick Force Read-Only on values the client must only observe, such as a measured temperature, and leave it unticked on values the client may set, such as a setpoint or a command word.

Why does a Flexy tag read a constant zero over Modbus TCP? #

A constant zero almost always means the client's read function does not match the published register type: a holding-register read against a tag published with Force Read-Only ticked, or an input-register read against an unticked tag, returns a constant 0.

The server answers the function you sent rather than the one you meant, and the mismatch comes back as a frozen reading instead of an error, which is why it hides on a tag that moves in the Flexy tag list. Work in order: check the tag's Force Read-Only state, then which register block the client is set to read, then the unit ID. If the value moves in the Flexy but sits frozen across the wire, the function against the register type is the first suspect, not the network, which would fail to connect rather than deliver one unchanging value.

Why is the Flexy register address off by one? #

The Flexy numbers its registers from 1 while many Modbus clients index from 0, so a zero-based client needs the Flexy tag address minus one — a tag numbered 232 in the Flexy appears at client address 231.

Clients split on the convention, and both are common: some treat the number you enter as a zero-based index into the register block, others as the one-based register number. The Flexy is one-based. For a zero-based client the arithmetic is one subtraction:

client address = Flexy tag address - 1

For example, a tag numbered 232 in the Flexy sits at client address 231 (232 - 1 = 231), and a tag numbered 220 sits at 219 (220 - 1 = 219). That is the shift the reference screenshot shows: its zero-based client displays input register 231 and holding register 219, one below the Flexy-side numbers 232 and 220.

If the client offers a one-based convention or understands 3xxxx and 4xxxx block notation, select that instead and enter the Flexy address unchanged — Modbus register addressing: how 3xxxx and 4xxxx notation maps to data words sets out how the two notations relate. Fix the convention once, in the client, and leave the Flexy tag numbers alone: shifting tag numbers by hand to suit one client breaks the next client that connects.

How do I publish a float tag over Modbus TCP? #

Tick Use 32-bit format on any tag that holds a float and set the client's 32-bit word mapping to little-endian, so the Flexy publishes the value as two consecutive 16-bit registers and the client reassembles them in the published order.

A 32-bit IEEE-754 float does not fit one 16-bit register, which is why the float is the one case that needs an extra flag on the tag. With Use 32-bit format ticked, the Flexy publishes the value as a register pair beginning at the tag's address, low word first — that is what its little-endian word mapping means — and the second half occupies the next register, with the same minus-one rule applied to both halves on a zero-based client. The client's 32-bit word order must be set to match, or the two halves reassemble the wrong way round. Verify the tag by reading the pair and comparing against the Flexy tag list.

Can a Modbus TCP client write a value back to a Flexy tag? #

Only tags published without Force Read-Only accept writes, because only a holding register is writable; a write aimed at a tag published as an input register is refused by the server, so untick Force Read-Only on any tag the client must be able to set.

Writes go through the holding-register write functions at the same address the client reads, and a read-back of that register confirms what the server now holds. A write aimed at an input-register tag is refused rather than ignored — the server treats that block as read-only, the same refusal covered in Why a Modbus TCP client cannot write M340 input bits. Because any client that can reach the Flexy's Modbus port can write an unticked tag, publish writeable tags only on a network segment you control and keep that port off office and internet routes.

How do I verify a published tag before relying on it? #

Read the tag once with the matching function, the unit ID and the address convention you settled above, compare the reading with the value in the Flexy tag list, and for a holding-register tag prove the write path with a read-back before you rely on it.

Run the chain once, in this order:

  1. Watch the tag move in the Flexy tag list while the process runs.
  2. Fix the register type on the tag: tick Force Read-Only for a value the client only reads, untick it for one it may write.
  3. Tick Use 32-bit format if the tag holds a float.
  4. Point the client at the Flexy's IP address and enter the Modbus Unit Address as the unit ID.
  5. Enter the register address in the client's own convention: the Flexy tag address, or that address minus 1 on a zero-based client.
  6. Read with the matching function and compare with the tag list; to prove a holding-register write, write a value on a tag the process ignores and read it back.

The matching rules are the same whatever tool sits on the client side; when the client is a Node-RED flow on an edge gateway speaking Modbus TCP, MQTT to Modbus TCP with Node-RED on an edge gateway covers that setup.

Which setting do I change for which symptom? #

Match the symptom to the setting: a frozen reading points to the read function against the register type, a large wrong number points to the 32-bit word order, a value that lands on the wrong register points to the address base, and a refused write points to Force Read-Only.

Symptom Setting behind it Change to make
Constant 0 on a tag that moves in the Flexy tag list Read function vs register type Match the function (03 holding, 04 input) to the tag's Force Read-Only state
Wrong but stable nonzero value on a float 32-bit word order Set the client to little-endian 32-bit word mapping
Reading lands on the wrong register Address base Subtract 1 from the Flexy address on a zero-based client
Write refused Register type Untick Force Read-Only if the client must write
Client cannot connect TCP port Point client and Flexy at the same port

Change one setting at a time and read back after each change, so the reading tells you which fix landed; when two settings are wrong at once, sort the register type first, because that frozen reading hides what the address base is doing.

Questions asked

Which port does the Flexy Modbus TCP server listen on?

Port 502 is the default, and the Flexy can be configured to use another port, 503 for example; the Modbus client must then target the same port. Both sides have to agree, because a client does not fall back to a second port on its own.

Why does a float tag read as a huge nonsense number instead of zero?

A wrong word order reassembles the two 16-bit halves of the float in the wrong sequence, so the registers read correctly but the reassembled number is wrong, usually huge or tiny rather than a frozen zero. The frozen zero on the same tag points somewhere else: the read function against the register type.

Does the Modbus client talk to the PLC behind the Flexy?

No. The client speaks only to the Flexy: the Flexy's own IO Server collects the tag values from the PLC, and the Flexy's Modbus TCP server serves those values to the client on request. The client never needs the PLC's protocol, address or unit ID.

Is slave ID 100 required for the Flexy?

No, 100 is only the example in the reference configuration. Choose the slave ID when you commission the unit: it must be unused by anything else answering on that link, and once chosen it stays fixed, because every client request names it. Changing it later means updating every client that polls the Flexy.

Keep reading

  • How-to

    MQTT to Modbus TCP with Node-RED on an edge gateway

    Yes: Node-RED with the node-red-contrib-modbus package can serve MQTT data to a SCADA client as Modbus TCP. Read the RTU device in Node-RED first, give the Modbus server node a port nothing else owns, and scale each MQTT payload to one integer per holding register before the first end-to-end test.

    Edge computing and IIoT

  • Explainer

    Why master-only Modbus TCP PLCs force the Flexy into the server role

    A Modbus TCP master-only port can initiate requests but never answer them, so nothing can poll those PLCs. Configure the Flexy as the Modbus TCP slave/server, enable its server on the Modbus IO server page, and let both X20 PLCs poll it as masters over port 502. The data still lands in Flexy tags; only the transaction direction changes.

    Edge computing and IIoT

  • Explainer

    Edge gateway Modbus TCP polling over the WAN port

    When a data gateway supports MQTT as a client only, drop the broker hop: configure the Modbus TCP poll to target the device's IP address in the same subnet as the gateway's WAN interface. The gateway opens the TCP connection itself, so polled values keep updating with the internet link down. Verify by pulling the uplink and watching one known register.

    Edge computing and IIoT

Polling 100 Modbus TCP slave IDs from Node-RED without 100% CPU