You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@plc4x.apache.org by "soldom (via GitHub)" <gi...@apache.org> on 2026/07/07 13:31:39 UTC
[I] [Bug]: ADS connect handshake ignores the configured target/source AMS port
soldom opened a new issue, #2629:
URL: https://github.com/apache/plc4x/issues/2629
### What happened?
### Description
The ADS driver's connection handshake sends its probe requests to a **hardcoded** AMS port
`DefaultAmsPorts.RUNTIME_SYSTEM_01` (851), with a hardcoded source AMS port `800`, instead of the
`target-ams-port` / `source-ams-port` from the connection string. Only the handshake is affected -
the actual read/write path correctly uses `getConfiguration().getTargetAmsPort()`.
As a result, **any TwinCAT system who has no PLC runtime on AMS port 851 cannot be connected to**,
even when `target-ams-port` is set correctly. This includes a second PLC project (852), a project
that was assigned a non-default port, and any multi-runtime setup where several PLC apps run in
parallel (852, 853, ...) where we do not want to handshake on 851. The connection fails during the
handshake - before any user read/write - with ADS error `0x6` ("target port not found"), because
the `ReadDeviceInfo` is delivered to port 851 where no runtime is listening.
I am unaware of the intention hardcoding 851 and assume it is unintended to not cover the uscase
of supporting parallel PLC runitmes that do not include 851 among their used ports.
### Affected code
`plc4j/drivers/ads/.../AdsTcpConnection.java`:
- `doConnectHandshake()` - three requests: `AdsReadDeviceInfoRequest`, the online-version
`AdsReadWriteRequest`, and the symbol-version `AdsReadRequest`.
- `onPing()` - the `AdsReadDeviceInfoRequest`.
All four are built with:
```java
getConfiguration().getTargetAmsNetId(), DefaultAmsPorts.RUNTIME_SYSTEM_01.getValue(), // 851, hardcoded
getConfiguration().getSourceAmsNetId(), 800, ReturnCode.OK, getInvokeId()); // 800, hardcoded
```
whereas the symbol/datatype-table reads and all read/write requests in the same class use
`getConfiguration().getTargetAmsPort()` / `getSourceAmsPort()`.
The released `0.12.0` (and `0.13.x`) `AdsProtocolLogic.onConnect()`
hardcodes the same `RUNTIME_SYSTEM_01` / `800`, and the SPI-3 rewrite (`AdsTcpConnection`) carried it over.
### Steps to reproduce
1. A TwinCAT target with a PLC runtime on AMS port **852** (e.g. a second PLC project, or move the
first project to 852), with **nothing** on 851.
2. Connect with `ads:tcp://<ip>?source-ams-net-id=...&source-ams-port=...&target-ams-net-id=...&target-ams-port=852`.
3. `getConnection(...)` fails during the handshake:
`PlcConnectionException: Error during ADS connect handshake`
-> `PlcRuntimeException: Unexpected response type: AdsErrorResponse (expected AdsReadDeviceInfoResponse)`.
A packet capture (Wireshark AMS dissector) confirms the on-connect `ReadDeviceInfo` is addressed to
AMS port **851** (source **800**) - not the configured 852 - and TwinCAT replies with AMS error
`0x00000006`. Sending the same `ReadDeviceInfo` to port 852 by hand (raw plain-ADS socket) succeeds and
returns the device info, so the target itself is fine.
### Expected behavior
The handshake should target `getConfiguration().getTargetAmsPort()` / `getSourceAmsPort()`, exactly
like the data path - so any runtime port works.
### Environment
- PLC4X: `0.14.0-SNAPSHOT` (develop); also present in released `0.12.0` / `0.13.x`.
- Driver: `plc4j-driver-ads` (Java).
- Target: Beckhoff TwinCAT `3.1.4026`.
### Proposed fix
Replace the four hardcoded `RUNTIME_SYSTEM_01.getValue()` / `800` with the configured
`getTargetAmsPort()` / `getSourceAmsPort()`. I have this fix on a branch and will open a PR referencing
this issue.
### Version
v0.14.0-SNAPSHOT
### Programming Languages
- [ ] plc4c
- [ ] plc4go
- [x] plc4j
- [ ] plc4net
- [ ] plc4py
### Protocols
- [ ] AB-Ethernet
- [x] ADS /AMS
- [ ] BACnet/IP
- [ ] C-Bus
- [ ] CANopen
- [ ] EtherNet/IP
- [ ] Firmata
- [ ] IEC-69870
- [ ] KNXnet/IP
- [ ] Modbus
- [ ] OPC-UA
- [ ] Profinet
- [ ] S7
- [ ] S7-light
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@plc4x.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug]: ADS connect handshake ignores the configured target/source AMS port
Posted by "sruehl (via GitHub)" <gi...@apache.org>.
sruehl commented on issue #2629:
URL: https://github.com/apache/plc4x/issues/2629#issuecomment-4904415205
seems odd, @chrisdutz any idea why that may be?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@plc4x.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug]: ADS connect handshake ignores the configured target/source AMS port
Posted by "chrisdutz (via GitHub)" <gi...@apache.org>.
chrisdutz closed issue #2629: [Bug]: ADS connect handshake ignores the configured target/source AMS port
URL: https://github.com/apache/plc4x/issues/2629
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@plc4x.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org