Skip to content

[Bug]: [Modbus TCP] Connection-level unit-identifier is not applied to read requests #2836

Open

Description

@Balaji-Sundar

What happened?

When using the Apache PLC4X Modbus TCP driver, configuring unit-identifier=19 in the connection URL does not appear to apply the configured Unit Identifier (Slave ID) to a read request.

The request works as expected when the Unit ID is explicitly specified in the tag address using {unit-id: 19}.

This behavior suggests that the connection-level Unit Identifier is not propagated to the generated Modbus tag or request, or that the configured default is not being applied as expected.

Environment

Driver: Apache PLC4X Modbus TCP Version 1.0.0

Protocol: Modbus TCP

Host: 10.10.121.55

Port: 502

Configured Unit Identifier: 19

Request timeout: 5000 ms

Default payload byte order: BIG_ENDIAN

Steps to Reproduce

  1. Configure the connection URL

String connectionUrl =
"modbus-tcp:tcp://10.10.121.55:502"
+ "?unit-identifier=19"
+ "&request-timeout=5000"
+ "&default-payload-byte-order=BIG_ENDIAN";

  1. Create a read request without an explicit Unit ID

PlcReadRequest request = connection.readRequestBuilder()
.addTagAddress("energy", "holding-register:29[0..1]:UINT")
.build();

  1. Observe the response and generated tag

The response contains:

response = [56741, 65535]

Tag: energy
Response code for energy: OK

response = ModbusTagHoldingRegister {
address=28,
quantity=2,
dataType=UINT,
unitId=null
}

The generated tag has unitId=null, despite the connection URL specifying unit-identifier=19.

The decoded energy value is:

Assembled Energy Value: 4294958501

  1. Specify the Unit ID explicitly in the tag address

Modify the request as follows:

PlcReadRequest request = connection.readRequestBuilder()
.addTagAddress(
"energy",
"holding-register:29[0..1]:UINT{unit-id: 19}"
)
.build();

Keep the same connection URL.

The response now contains:

response = [55121, 21]

Tag: energy
Response code for energy: OK

response = ModbusTagHoldingRegister {
address=28,
quantity=2,
dataType=UINT,
unitId=19
}

The assembled energy value is:

Assembled Energy Value: 1431377

The tag now correctly contains unitId=19, and the returned register values differ from those obtained when the tag's Unit ID is null.

Expected Behavior

When the connection URL contains:

unit-identifier=19

a read request created without an explicit unit-id in its tag address should use Unit Identifier 19, unless the documented API intentionally requires the Unit ID to be supplied per tag.

Actual Behavior

The connection URL contains unit-identifier=19, but the generated holding-register tag has:

unitId=null

The configured Unit Identifier appears to be ignored when creating the tag or preparing the request.

Adding the following explicitly to the tag address makes the tag use the expected Unit ID:

{unit-id: 19}

Impact

Applications communicating with Modbus TCP devices that require a specific Unit Identifier may read data from the wrong logical device or receive unexpected register values when relying on the connection-level configuration.

This also forces applications to specify the Unit ID repeatedly in tag addresses, even when it has already been configured in the connection URL.

Questions for the Maintainers

Is unit-identifier intended to act as the default Unit Identifier for all Modbus TCP requests created through a connection?

If so, why is the Unit ID not propagated to a tag when the tag address omits {unit-id: ...}?

Is this an implementation defect, or is the documented behavior that Unit ID must be specified per tag?

If this is a defect, could the connection-level Unit Identifier be applied as the default whenever a tag does not explicitly override it?

Version

v1.0.0

Programming Languages

  • plc4c
  • plc4go
  • plc4j
  • plc4net
  • plc4py

Protocols

  • AB-Ethernet
  • ADS /AMS
  • BACnet/IP
  • C-Bus
  • CANopen
  • EtherNet/IP
  • Firmata
  • IEC-69870
  • KNXnet/IP
  • Modbus
  • OPC-UA
  • PLC4X
  • Profinet
  • S7
  • Simulated
  • SLMP
  • UMAS

Activity

  1. added
    java
    Modbus
    on Nov 6, 2026
  2. added theissue type on Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Modbusjava

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions