Question: EtherCAT Error detection in IEC
Answer: Master:
Diagnostics Message can be read within the Master configuration tab.
Same in EtherCAT_Master.m_sLastMesage
Slave:
Slave State can be read within the Slave configuration tab. Diagnostics Current State
Same with SlaveName.wState (call of the slave instance is required)
Example:
Code:
EK1100(); // Name of the slave = "EK1100"
EL1004();
EL2008();
IF NOT EK1100.wState = ETC_SLAVE_STATE.ETC_SLAVE_OPERATIONAL THEN
// do something
END_IF
Snippet:Snippet:
A very good example is the ethercat example in the CODESYS store:
http://store.codesys.com/ethercat-example.html#SupportCode:
(* Get some information of the slaves and master. It is possible to go through all masters and slaves
and get information about them. *)
(* EtherCAT_Master is an instance of the IoDrvEtherCAT function block.*)
(* The number of active slaves *)
uiActiveSlaves := EtherCAT_Master.NumberActiveSlaves;
(* Get the ETCMaster *)
pEtcMasterFB := EtherCAT_Master.Master;
(* The number of SDO's *)
iSDOCnt := pEtcMasterFB^.GetNumberOfSDO;
(* Go through all Slaves *)
pSlave := Ethercat_Master.FirstSlave;
WHILE pSlave <> 0 DO
(* get the address of the current slave. This can also be found under the device in the "Slave" tab. *)
uiSlaveAddr := pSlave^.SlaveAddr;
pSlave^();
(* Get the state of the slave *)
(* With pSlave^.SetOpMode(ETC_SLAVE_STATE), the state can be set.*)
IF pSlave^.wState = ETC_SLAVE_STATE.ETC_SLAVE_OPERATIONAL THEN
;
END_IF
pSlave := pSlave^.NextInstance;
END_WHILE
Back to FAQ overview