Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#2,836 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
java
領域
backend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
Java
スター
1.8k
フォーク
512
平均マージ
2日 2時間
マージ済み PR(30日)
34

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/plc4x のほかの issue

apache/plc4x の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。