The PLC has two EtherCAT master devices. If I have the NetIds I can scan the devices from the EtherCAT master and set them in OP state if needed (some maschine or whatever were disconnected).
I can get the devices from a master NetId using the library Tc2_EtherCAT and FBs like ST_EcSlaveState, FB_EcGetAllSlaveAddr, FB_EcGetAllSlaveStates...
Its possible to get the local NetId thanks to the FB FB_GetLocalAmsNetId. However I have two. Any Ideas?
At the moment I write it somewhere and it will be read it. I would like to skip this step. In case that the PLC is replaced or for new ones.



You can find the master AmsNetId under EtherCAT master -> InfoData -> AmsNetId. That is the address as a byte array.
To get it as string do the following:
Create two variables
Build project and then link
MasterAmsNetIdto EtherCAT master -> InfoData -> AmsNetIdIn code, convert
MasterAmsNetIdto string using function F_CreateAmsNetId from Tc2_System libraryNow
MasterAmsNetIdStrcontains the address in format similar to192.168.10.5.1.1as string and you can use it in communication function blocks.