Hi @Filip_K , I don't see that Dias has replied here, so I will answer in case you still need help. The variable you are questioning is initialized to 1001 because that is the address of the first device on the ECAT bus. The address of the other devices increments from there. What this program is doing is constantly checking the EtherCAT Master state. If it is in error, specifically for a topology problem, it then proceeds to read the number of slaves which are configured on the bus. Next, it runs a loop to cycle through each slave and check whether the slave is detected on the bus or not. If any slave is not detected in Operational state, it sends a command to the master to set the bus state to Op, forcing any slaves which may be stuck in Init or Safe-Op (the SAFEX, in this case) to go to the Operational state. The section of the code you highlighted serves to re-initialize this loop back to the starting address of 1001 as soon as it has reached the address of the last slave on the bus. For example, if you have 5 slaves on the bus the addresses would be 1001, 1002, 1003, 1004, 1005. The value of fbIL_ECATGetNumConfigSlaves.NumConfigSlaves would be 5. So, as soon as the loop index (uiEthercatAddr) is equal to 1006 (1001+5), it resets the loop index back to the start of 1001, before executing the command for a slave address which doesn't exist. In short, you do not want to change it to 1004. The code was written to work for any configuration. Hopefully this adds some clarity.
... View more