Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#2,836 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
java
Área
backend

Línea de trabajo

Start by tracing how the Modbus TCP connection URL parses unit-identifier and how that value reaches plc4j read requests and generated holding-register tags. Compare the connection-level setting with the explicit {unit-id: 19} tag address shown in the report. Done means a tag without an explicit unit ID uses the configured default, or the documented behavior explains why it does not.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
Java
Estrellas
1.8k
Forks
512
Merge medio
2 d 2 h
PR fusionados (30 d)
34

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/plc4x

Todos los issues de apache/plc4x

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.