1

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.


EtherCAT Master

enter image description here

2 Answers2

3

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:

  1. Create two variables

    MasterAmsNetId AT%I*    : T_AmsNetIdArr; //alias to ARRAY [0..5] OF BYTE
    MasterAmsNetIdStr       : T_AmsNetID; //alias to STRING(23)
    
  2. Build project and then link MasterAmsNetId to EtherCAT master -> InfoData -> AmsNetId

    image

  3. In code, convert MasterAmsNetId to string using function F_CreateAmsNetId from Tc2_System library

    MasterAmsNetIdStr := Tc2_System.F_CreateAmsNetId(MasterAmsNetId);
    
  4. Now MasterAmsNetIdStr contains the address in format similar to 192.168.10.5.1.1 as string and you can use it in communication function blocks.

Quirzo
  • 1,183
  • 8
  • 10
2

An alternative to Quirzo's solution. Rather than performing a search you can determine the NetIDs implicitly using Relative NetIds

Relative NetId Checkbox location

By using a relative ID, as long as you know the ID of the controller, and how the ECat chain was configured in the project, you should be able to determine the target NetId.

Steve
  • 963
  • 5
  • 16