Skip to content

fix(plc4j/ads): connect handshake honors configured AMS ports instead of hardcoded RUNTIME_SYSTEM_01#2630

Open
soldom wants to merge 1 commit into
apache:developfrom
soldom:fix/ads-connect-handshake-configured-ams-port
Open

fix(plc4j/ads): connect handshake honors configured AMS ports instead of hardcoded RUNTIME_SYSTEM_01#2630
soldom wants to merge 1 commit into
apache:developfrom
soldom:fix/ads-connect-handshake-configured-ams-port

Conversation

@soldom

@soldom soldom commented Jul 7, 2026

Copy link
Copy Markdown

Closes #2629.

Problem

The ADS connect handshake (AdsTcpConnection.doConnectHandshake() and onPing()) sent its probe
requests — ReadDeviceInfo, online-version, symbol-version — to a hardcoded AMS port
DefaultAmsPorts.RUNTIME_SYSTEM_01 (851) with a hardcoded source port 800, ignoring the configured
target-ams-port / source-ams-port. Only the handshake was affected; the symbol/datatype-table
reads and the read/write path already use getConfiguration().getTargetAmsPort().

Consequence: any PLC runtime not on 851 — a second PLC project (852), a non-default port, or parallel
runtimes — failed to connect during the handshake with ADS error 0x6 ("target port not found"),
even with target-ams-port set correctly. Full analysis and a packet capture are in #2629.

It may be intended to have the handshake port hardcoded to "System_01" (851), but the reason escapes me
and it does break the above mentioned PLC setup use cases.

Change

In plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/AdsTcpConnection.java, the four
handshake/ping request builders now use the configured ports, matching the data path:

-    getConfiguration().getTargetAmsNetId(), DefaultAmsPorts.RUNTIME_SYSTEM_01.getValue(),
-    getConfiguration().getSourceAmsNetId(), 800, ReturnCode.OK, getInvokeId());
+    getConfiguration().getTargetAmsNetId(), getConfiguration().getTargetAmsPort(),
+    getConfiguration().getSourceAmsNetId(), getConfiguration().getSourceAmsPort(), ReturnCode.OK, getInvokeId());

No behavior change for the common case: target-ams-port already defaults to 851.

Testing

Verified against a real Beckhoff TwinCAT 3.1.4026 IPC:

  • PLC runtime on AMS port 852, nothing on 851 — before: connect fails (AdsErrorResponse,
    AMS error 0x6); after: connects and reads a live symbol successfully.
  • A packet capture (Wireshark AMS dissector) confirms the handshake ReadDeviceInfo is now sent to
    the configured target-ams-port (852) instead of 851.
  • Regression check: with the PLC on 851 the connection still works as before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ADS connect handshake ignores the configured target/source AMS port

1 participant