How-to
List EtherCAT master NetIds on a remote runtime via ADS
Short answer
Yes: an ADS client can list every EtherCAT master NetId on a remote runtime without opening the project. The reference implementation is ListECatMasters in ECatAccess.cpp of the ADS C++ library, driven from the runtime AmsNetId you already have. Each discovered master is a separate ADS endpoint at the EtherCAT master ADS port.
On this page
Yes, you can get the NetId of every EtherCAT master device on a remote runtime over ADS, without knowing anything else about the running project and without changing it. Beckhoff's ADS C++ library shows the method in AdsLib/ECatAccess.cpp, in the function ListECatMasters: it asks the runtime, over the ADS route you already have, for the list of EtherCAT masters it hosts, and each returned AmsNetId is a usable ADS endpoint. The runtime AmsNetId you configured in your local router is not a master address, so the first decision is to stop treating it as one and enumerate instead.
Separate the runtime NetId from the master NetIds #
The AmsNetId in your local router identifies the remote TwinCAT runtime. Each EtherCAT master device in its I/O image carries its own NetId, which the vendor documentation shows in the NetId edit field on the EtherCAT tab of the master device, and the EtherCAT master listens on ADS port 0xFFFF, documented as always 65535. So one runtime can expose several independent ADS endpoints: the runtime itself, plus one per EtherCAT master. An ADS connection to the runtime proves nothing about the master NetIds, and the master NetIds cannot be guessed from the runtime address.
Why the project-based routes do not apply here #
Two documented ways to read the master NetIds both need the project. The first is the NetId field on the EtherCAT tab of the master device, which only exists in an open configuration. The second is the function block FB_EcGetAllMasters, which returns the device ID, AMS NetId and name of every EtherCAT master, but it executes as PLC code, so it only works when you are allowed to modify the application. When the running project is off limits, ADS-side enumeration replaces both.
Enumerate the masters over ADS #
- Set up the AMS route from your client to the remote runtime AmsNetId. If the route must be added by hand rather than discovered, the steps match the procedure for manually adding ADS routes and configuring the AmsNetId on the remote system.
- Take
ListECatMastersfromECatAccess.cppin the ADS C++ repository as your reference. The published code shows the complete request-and-response exchange against the runtime; derive your structures and calls from that file rather than reconstructing index groups from memory. - Call the enumeration against the runtime AmsNetId. Retain every returned master AmsNetId, because a runtime can host more than one EtherCAT master image and the list is unordered with respect to your wiring.
- Pair each returned NetId with the EtherCAT master ADS port, 0xFFFF in hexadecimal. Do not substitute a PLC runtime port number; the master device answers on its own port.
- Verify each endpoint as described below before you build production traffic on it.
A worked example #
Say your client reaches a remote runtime at the example AmsNetId 172.16.10.5.1.1. Calling the enumeration returns one master with the example AmsNetId 172.16.10.5.1.2. The endpoint for fieldbus work on that master is therefore NetId 172.16.10.5.1.2 at ADS port 0xFFFF. To confirm the port value from the documentation's hexadecimal form: 15 x 4096 + 15 x 256 + 15 x 16 + 15 = 61440 + 3840 + 240 + 15 = 65535, so 0xFFFF is decimal 65535. These addresses are illustrative; the ones your enumeration returns are the values your runtime actually exposes. You already talk CoE to fieldbus devices once a controller NetId is known, so the enumeration drops directly into that existing path.
Verify each discovered master NetId #
Substitute each enumerated NetId, at the EtherCAT master ADS port, into your existing CoE access path and read one known object from the intended controller. A successful response confirms both things at once: the AMS route to the runtime works and the returned address really is the master you meant to select. If enumeration succeeds but fieldbus access fails, split the checks instead of re-running the enumeration. Confirm the route to the runtime first, since the same routing questions appear when reaching a safety PLC over EtherCAT EoE from a Windows PC, and only then confirm that the substituted endpoint is the intended master rather than a second master image on the same host.
What the method does not give you #
ListECatMasters is reference code in a vendor repository, not a stable public API: the ADS library revision it ships in defines the exact structures and calls, so keep your integration aligned with the revision you link against rather than hard-coding wire details copied from another version. Treat it as a discovery step, and keep the one safety consequence in view: ADS carries no authentication or encryption, and any host holding a valid AMS route to TCP port 48898 can read symbols and memory on the target, so restrict those routes to engineering hosts on the controls network. With the route locked down and the endpoints verified, the enumeration is the complete answer: one call from the runtime AmsNetId you already had, returning every EtherCAT master NetId, none of which required opening the running project.
Questions asked
Can ADS list the EtherCAT master NetIds without touching the project?
Yes. The ADS-side enumeration shown in ListECatMasters in ECatAccess.cpp lists the EtherCAT masters on the system using only an ADS route to the runtime. The documented function block FB_EcGetAllMasters returns the device ID, AMS NetId and name of all masters too, but it runs as PLC code, so it requires editing the project.
Where is the NetId shown when I can open the project?
In the TwinCAT configuration, the NetId of the EtherCAT master device appears in the NetId edit field on the EtherCAT tab of that master device. That field is the same value the ADS enumeration returns, but reading it requires project access, which is exactly what enumeration avoids.
Why does CoE access fail after I substitute the discovered NetId?
Separate the checks. First confirm the AMS route to the runtime itself, because enumeration succeeding proves only that route. Then confirm the endpoint you built pairs the enumerated master NetId with the EtherCAT master ADS port rather than a PLC runtime port. A failure in one of the two does not implicate the other.