Linked List to Check All Slaves

To monitor individual slaves, the instance is called up in the program and the status is determined through wState. To simplify this, all masters and slaves can be determined through linked lists and all slaves can be checked with a simple WHILE loop. The properties NextInstance and LastInstance exist for the masters as well as the slaves. These properties return a pointer to the next or previous slave. There is also the property FirstSlave for the master, which provides a pointer to the first slave The example below outlines how all slaves can be checked.

Example

Declaration:

pSlave: POINTER TO ETCSlave;

Program:

pSlave := EtherCAT_Master.FirstSlave;
WHILE pSlave <> 0 DO
pSlave^();
IF pSlave^.wState = ETC_SLAVE_STATE.ETC_SLAVE_OPERATIONAL
THEN
;
END_IF
pSlave := pSlave^.NextInstance;
END_WHILE

To start, the first slave on the master is called via “EtherCAT_Master.FirstSlave.” The respective instance is called up during the WHILE loop, thus determining wState. Then the status can be checked. The pointer on the next slave is called with “pSlave^.NextInstance.” At the end of the list, the pointer is NULL and the loop is exited.