Skip to main content

Modbus

Modbus is a communication protocol utilized in PLC networks. Originally developed for serial interfaces like RS232, RS422, and RS485, it was later expanded to include TCP mode. OIBus uses the jsmodbus library in TCP mode only.

Specific Settings

Connection Configuration

SettingDescriptionExample Value
HostIP address or hostname of the Modbus server machine.192.168.1.100
PortPort to use for connection (502 by default).502
Connection timeoutMaximum time to wait for a connection (in milliseconds).10000
Retry intervalTime to wait (in milliseconds) between reconnections after a connection failure.5000
Network timeoutDelay (in milliseconds) before TCP keepalive probes start being sent on an idle connection. Keeps the connection alive through firewalls and NAT devices that close idle sockets.15000
Slave IDIdentifies the Modbus source machine (default is 1).1
Address offsetFor most PLCs, there is no offset (Modbus option). Some PLCs may start the address range at 1 instead of 0 (JBus option)Modbus

Data Format Options

SettingDescriptionExample Value
EndiannessType of bit encoding.Big Endian
Swap BytesWhether bytes within a 16-bit word should be swapped.Enabled/Disabled
Swap WordsWhether 16-bit words should be swapped within a 32-bit group.Enabled/Disabled

Use the tester below to see how these three settings affect the decoded value for a given set of register values.

Register 1
0x
Register 2
0x
Byte pipeline
From registers (Big Endian)
4120
R1
0000
R2
Float10

Presets

Query Optimisation

SettingDescriptionExample Value
Grouping gapMaximum address gap (in registers) allowed when merging non-consecutive items of the same type into a single Modbus request. Set to 0 to batch only strictly consecutive addresses (default).0100

OIBus always groups items of the same Modbus type (coil, discrete input, input register, holding register) whose addresses are consecutive into a single request, reducing round-trips to the device.

With a grouping gap > 0, items that are almost—but not quite—consecutive are also merged. For example, three holding registers at addresses 1, 3, and 5 would normally require three separate requests. With a grouping gap of 2, all three are read in one request (the two intermediate filler registers are fetched and discarded).

When to increase the grouping gap

A larger gap trades a small amount of extra data on the wire (filler registers) for fewer TCP round-trips. This is usually beneficial when the device is slow to respond or when the network latency is high. Keep it at 0 if minimising traffic is more important than minimising round-trips.

Protocol limits

Regardless of the grouping gap, OIBus never exceeds the Modbus specification limits per request:

  • Coils / Discrete inputs (FC01 / FC02): 2 000 bits maximum.
  • Input registers / Holding registers (FC03 / FC04): 125 words maximum.

Ranges that exceed these limits are automatically split into multiple requests.

Item Settings

SettingDescriptionExample Value
AddressAddress of the register within the device, without the leading data type digit. Accepts a plain decimal number (e.g. 1) or a hexadecimal number prefixed with 0x (e.g. 0x0001).0x0001
Modbus typeSpecifies whether it's a coil, discrete input, input register, or holding register (default).Holding Register
Data typeRelevant for holding registers or input registers. Defines the type of data fetched from the register (Bit, UInt16, Int16, UInt32, Int32, UInt64, Int64, Float, Double).UInt16
Bit index(Bit data type only) The index of the bit to retrieve from the read value (0 to 15).0 to 15
Multiplier CoefficientMultiplies the retrieved value (default is 1).1
About Modbus Addresses

PLC documentation typically uses the Modicon Convention Notation (MCN): a decimal number whose leading digit encodes the data type and whose remaining digits are the register number.

Leading digitData type
0Coil
1Discrete Input
3Input Register
4Holding Register

OIBus expects the address without the leading type digit, entered as a plain decimal number or as a hexadecimal number prefixed with 0x. The data type is declared separately via the Modbus type field.

Converting an MCN address to an OIBus address:

  1. Strip the leading type digit from the MCN address.
  2. Enter the remaining number directly. Both decimal and 0x-prefixed hexadecimal are accepted.

Examples:

MCN addressStrip type digitOIBus addressModbus type
4000100011 or 0x0001Holding Register
401000100100 or 0x0064Holding Register
3000500055 or 0x0005Input Register
001570157157 or 0x009DCoil

MCN address ranges:

TypeStandard (5 digits)Extended (6 digits)
Coil00001 – 09999000001 – 065535
Discrete Input10001 – 19999100001 – 165535
Input Register30001 – 39999300001 – 365535
Holding Register40001 – 49999400001 – 465535

Address offset: The Address offset setting controls whether register numbering starts at 0 (Modbus) or 1 (JBus). Most PLCs use the Modbus convention (no offset). Check your device documentation if values seem shifted by one.

For more details, see the Modicon Convention Notation (MCN).