Skip to main content

Modbus Publisher

The Modbus publisher writes Mango data point values to registers and coils on external Modbus slave devices. While the Modbus data source reads data into Mango, the Modbus publisher sends data out -- allowing Mango to act as the central coordinator that pushes calculated values, setpoints, or aggregated data to PLCs, RTUs, HMI panels, and other Modbus-capable equipment.

This publisher supports both Modbus TCP/IP and Modbus Serial (RTU/ASCII) connections, and can write to holding registers, coils, and multiple register types in a single publish cycle.

Overview

The Modbus publisher monitors configured Mango data points and writes their values to specified Modbus register addresses on a target device whenever the point values change, update, or at scheduled snapshot intervals. Each published point maps to one or more Modbus registers, with automatic data type conversion between Mango's internal representation and the Modbus register format.

Key capabilities:

  • Write on change or on schedule -- publish values immediately when they change, on every update, or at regular snapshot intervals.
  • Multiple data types -- write 16-bit integers, 32-bit integers, 32-bit floats, 64-bit doubles, and boolean coil values.
  • Multiple slave support -- write to different slave IDs within a single publisher (useful for gateway devices).
  • Batch writes -- multiple registers to the same slave can be written in a single Modbus transaction using function code 16 (Write Multiple Registers).

Prerequisites

Before you begin, make sure you have:

  • A Modbus TCP/IP or Serial device accessible from the Mango host.
  • The device's register map documentation, specifying register addresses, data types, and byte order.
  • Network connectivity (for TCP) or a serial connection (for RTU/ASCII) to the target device.
  • Knowledge of the device's slave ID (unit ID).
  • The target registers must be writable (holding registers or coils, not input registers).

Step-by-step guide

Step 1: Create the publisher

  1. Navigate to Administration > Publishers.
  2. Click New and select Modbus Publisher from the publisher type dropdown.
  3. Enter a descriptive Name (e.g., "PLC Setpoint Writer").
  4. Configure the common publisher settings (update event, cache sizes).

Creating a new Modbus publisher

Step 2: Configure the connection

Switch to the Modbus configuration tab and select the transport type.

For Modbus TCP/IP:

SettingDescription
Transport typeSelect TCP/IP.
HostIP address or hostname of the Modbus slave device.
PortTCP port (default: 502).
Connection timeoutMaximum milliseconds to wait for a TCP connection (default: 3000).

For Modbus Serial (RTU/ASCII):

SettingDescription
Transport typeSelect Serial (RTU) or Serial (ASCII).
Comm portSerial port connected to the Modbus network (e.g., /dev/ttyUSB0, COM1).
Baud rateCommunication speed (common values: 9600, 19200, 38400, 115200).
Data bitsNumber of data bits per frame (typically 8).
Stop bitsNumber of stop bits (typically 1).
ParityParity checking (None, Even, or Odd). Must match the slave device.

Modbus publisher connection settings for TCP and serial

Step 3: Configure common publisher settings

SettingDescription
Update eventWhen to publish values: All (every update), Changes only (only when value changes), Logged only (when logged), or None (snapshots only).
Cache warning sizeRaises a warning alarm when the publish queue exceeds this number of entries.
Cache discard sizeDiscards the oldest entries when the queue reaches this size, preventing unbounded memory growth.
Send regular snapshotsWhen enabled, publishes all point values at a regular interval regardless of whether they have changed.
Snapshot periodThe interval between snapshot publishes (e.g., every 5 minutes).

Step 4: Add published points

For each Mango data point you want to write to the Modbus device:

  1. Click Add point in the published points section.
  2. Select the Mango data point to publish.
  3. Configure the Modbus register mapping:
SettingTypeDefaultDescription
Slave IDInteger1The Modbus unit ID (slave address) of the target device. Range: 1-247.
Register typeEnumHolding registerThe register type to write. Options: Holding register (function code 6/16) or Coil (function code 5/15).
Register offsetInteger0The starting register address (0-based). Consult the device register map. Some devices use 1-based addressing -- subtract 1 for the Mango configuration.
Data typeEnumTwo byte int (unsigned)How to encode the Mango value into Modbus registers.
Byte orderEnumBig-endianByte order within multi-byte registers. Most Modbus devices use big-endian, but some (especially Schneider, Wago) use little-endian.
Word orderEnumBig-endianWord order for 32-bit and 64-bit values that span multiple registers. Determines whether the high-order or low-order register comes first.
MultiplierNumeric1Scaling factor applied before writing: written = mango_value * multiplier + additive.
AdditiveNumeric0Offset applied after multiplication.

Modbus publisher point configuration showing register mapping

Step 5: Enable and verify

  1. Click Save to save the publisher configuration.
  2. Toggle Enabled to start publishing.
  3. Monitor the publisher status for successful writes. The queue size should remain near zero during normal operation.
  4. Verify on the Modbus slave device (or via a Modbus data source reading the same registers) that values are being received correctly.

Configuration reference

Supported data types

Data TypeRegistersRange / PrecisionDescription
Two byte int (signed)1-32,768 to 32,767Standard 16-bit signed integer.
Two byte int (unsigned)10 to 65,535Standard 16-bit unsigned integer.
Four byte int (signed)2-2,147,483,648 to 2,147,483,64732-bit signed integer across two registers.
Four byte int (unsigned)20 to 4,294,967,29532-bit unsigned integer across two registers.
Four byte float2IEEE 754 single precision32-bit floating point across two registers.
Eight byte float4IEEE 754 double precision64-bit floating point across four registers.
Coil (boolean)N/Atrue/falseSingle bit written via coil function codes.

Register addressing

Modbus register addresses in Mango use 0-based offsets. Many device manuals use 1-based addressing or include a register type prefix (e.g., 40001 for the first holding register). To convert:

Manual AddressMango OffsetRegister Type
400010Holding register
4010099Holding register
000010Coil
0005049Coil

When the manual uses 1-based addressing without a prefix, subtract 1 from the documented address to get the Mango offset.

Write modes

The publisher automatically selects the appropriate Modbus function code:

ScenarioFunction CodeDescription
Single holding registerFC 06 (Write Single Register)Writing one 16-bit register.
Multiple holding registersFC 16 (Write Multiple Registers)Writing 32-bit or 64-bit values that span multiple registers.
Single coilFC 05 (Write Single Coil)Writing a single boolean coil.
Multiple coilsFC 15 (Write Multiple Coils)Writing multiple coils in a batch.

Troubleshooting

SymptomCauseSolution
"Connection refused" on TCPWrong IP/port, device offline, firewallVerify the Modbus slave is reachable with telnet host 502. Check firewall rules.
"Timeout waiting for response"Slave not responding, wrong slave IDVerify the slave ID matches the device configuration. Check that the device supports the register type and address being written.
Values written but incorrect on deviceByte order or word order mismatchTry switching between big-endian and little-endian byte/word order. Consult the device documentation for the expected byte order.
Float values corruptedWrong word order for 32-bit floats32-bit floats span two registers. If the high and low words are swapped, change the word order setting.
"Illegal data address" error (exception code 2)Register offset out of range or register is read-onlyVerify the register address against the device register map. Ensure you are writing to holding registers or coils, not input registers.
"Illegal function" error (exception code 1)Device does not support the function codeSome devices only support FC 06 (single register), not FC 16 (multiple registers). Ensure the data type fits in a single register, or check device capabilities.
Queue growing indefinitelyWrite failures faster than the publish rateCheck the connection to the Modbus device. If the device is intermittently unavailable, increase the cache warning size and investigate the root cause of connectivity issues.
Scaling produces unexpected valuesMultiplier/additive applied in wrong directionRemember: written_value = (mango_value * multiplier) + additive. To write raw register values, set multiplier to 1 and additive to 0.