[Bug]: [Modbus TCP] Connection-level unit-identifier is not applied to read requests
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
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
- 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";
- Create a read request without an explicit Unit ID
PlcReadRequest request = connection.readRequestBuilder()
.addTagAddress("energy", "holding-register:29[0..1]:UINT")
.build();
- 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
- 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
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/plc4x のほかの issue
-
Ethernet/IP java
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
apache/plc4x#2733 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
メンテナーはふだん 1 日以内に返信
-
[Bug]: TagBatch reuses a cached PlcReadRequest bound to a closed connection, so fetches fail after the first and never recover after a PLC restart対応中かも @chrisdutz が 3 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
[Bug]: OPC-UA driver 1.0.0 fails against a certificate-less server even with security-policy=NONE (regression vs 0.13.1)対応中かも @splatch が 7 日前に担当しました。 オープン
メンテナーはふだん 1 日以内に返信
-
[Bug]: OPC UA UserNameIdentityToken sends length+password+nonce instead of the plain password when token security policy is None対応中かも @splatch が 27 日前に担当しました。 オープンOPC-UA
apache/plc4x#2791 · コメント 2 件 · 担当者 2 名 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
snowflakedb/snowflake-kafka-connector#1610 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
swagger-api/swagger-petstore#245 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
liquid-java/liquidjava#443 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
quarkiverse/quarkus-google-cloud-services#1188 ·
メンテナーはふだん 1 日以内に返信