Example: EtherCAT Communication Diagnosis Steps
These are the steps to diagnose EtherCAT communication errors.
Examples are for how an application program can help a technician detect the issue and repair it.
Diagnosing EtherCAT Communication Errors
This flow chart explains the steps involved in diagnosing the EtherCAT errors.
-
- Click the blue fields in the flow chart to see sample code that can be used in a program to help with diagnosis.
Code Examples for Diagnosing EtherCAT Communication Errors
![Closed](../../../Skins/Default/Stylesheets/Images/transparent.gif)
This sample code checks for any Working Counter failure using the function ECATWCStatus.
If there is one or more working counter errors, the return value is greater than 0 (zero).
WC_ErrorCount := ECATWCStatus( 0 );
IF WC_ErrorCount > 0 THEN
WC_error :=TRUE; // There is a communication problem.
ELSE
WC_error := FALSE; // No communication problem
END_IF;
![Closed](../../../Skins/Default/Stylesheets/Images/transparent.gif)
The GetCtrlErrors function is used to get the Errors and Alarms in the controller that are related to EtherCAT.
ControllerErrorStatus:= GetCtrlErrors(ActiveError, ActiveAlarm) ;
A31Active := ActiveAlarm[31]; // True if A31 is active.
A38Active := ActiveAlarm[38]; // True if A38 alarm is active
E30Active := ActiveError[30] // True if E30 is active.
// Process the alarms and Errors here.
![Closed](../../../Skins/Default/Stylesheets/Images/transparent.gif)
The ECATDeviceStatus function block is used to read the device state of the application.
Inst_ECATDeviceStatus(True, slaveAddress);
IF Inst_ECATDeviceStatus.Done THEN
IF Inst_ECATDeviceStatus.LinkStatus = EC_LINK_NO_COMMUNICATION THEN
device_not_reachable := TRUE; // Device is not reachable. Link to the device is broken.
END_IF
IF Inst_ECATDeviceStatus.State <> EC_STATE_OP THEN
device_not_in_OPMODE := TRUE; // Slave is not in Operational mode.
END_IF
END_IF;
![Closed](../../../Skins/Default/Stylesheets/Images/transparent.gif)
This sample code uses the ECATCommErrors function block to identify the connections that have errors.
Inst_ECATCommErrors( TRUE, connections);
IF Inst_ECATCommErrors.Done THEN
IF Inst_ECATCommErrors.ConnectionCount > 0 THEN
// Process the connection errors here.
END_IF;
END_IF
-
- See the article Building KAS Applications with Built-in EtherCAT Diagnostics on KDN for a code sample and project file that uses EtherCAT diagnostics.