Background Information
The simplest EtherCAT diagnosis involves determining whether each slave device is in the Operational (OP) state and displaying this information on the HMI. Most users implement this functionality within their programs. This approach can indicate where a disconnection has occurred.
For common issues such as occasional disconnections and automatic reconnections (Change), CRC errors caused by external interference, slave data invalidation for unknown reasons (WcState), and data packet loss (LostFrame), merely checking the OP state is insufficient. Experienced TwinCAT engineers would open the XAE development environment and navigate to the Online page of the EtherCAT network for diagnosis. However, often, the machine is located at the end-user's site, where operators are less familiar with TwinCAT.
In such cases, if the PLC program of the equipment incorporates these diagnostic messages and displays the results on the HMI, troubleshooting can be faster and more accurate. In fact, the Tc2_EtherCAT library provides a series of Function Blocks (FBs) that allow the contents displayed on the EtherCAT | Online page to be read into the PLC.
Theoretically, users can write code to invoke these Function Blocks (FBs) to achieve any desired functionality. In practice, however, developing a comprehensive EtherCAT diagnostic program from scratch without any prior code can be quite challenging.
This article provides:
Recently, a customer inquired about this, prompting me to retrieve a relatively complete diagnostic program provided by a colleague a few years ago from my computer:
EthercatDiag_From_20201207.tszip
I have personally tested it and made a few modifications and annotations. It is available for download at the following link:
The function blocks invoked in the routine include:
- Reading configured slaves for EtherCAT (FB_EcGetConfSlaves)
- Reading actually connected slaves for EtherCAT online (FB_EcGetScannedSlaves)
- Reading EtherCAT network topology online (FB_EcGetSlaveTopologyInfo)
- Reading the NetId of the EtherCAT master online (FB_GetLocalAmsNetId)
- Reading the reconnection counts of EtherCAT slaves online (FB_EcGetAllSlavePresentStateChanges)
- Reading abnormal state changes of EtherCAT slaves online (FB_EcGetAllSlaveAbnormalStateChanges)
- Reading the state machine error code of a slave (FB_EcPhysicalReadCmd)
- Reading the frame analysis of the master, such as LostFrame, Rx/Tx errors, etc. (FB_EcMasterFrameStatistic)
The diagnostic information output in the routine includes:
bIsIdentityError;
(Checks if the network topology matches the configuration during startup)
bIsRevisionMismatch;
(Detects if one or more slaves have actual versions higher than those configured during startup)
InitialNoOfSlaves;
(Checks the total number of slaves included in each synchronization unit during startup)
IdentityDiffSlave;
(The name of the first slave where the actual and configured topologies do not match)
bIsLostFrame;
(Whether the current master is in an uninitialized state after packet loss)
LostFrameCount;
(The number of lost packets in the current network since power-on)
bInvalidInputData;
(Whether there is invalid data in a Sync Unit)
InvalidSyncUnit;
(The first Sync Unit with invalid data due to a WC error)
bIsConnectionLost;
(Whether at least one slave in the network has lost connection)
ConnLostSlave;
(The first slave currently in a disconnected state in the network)
bIsCrcError;
(Whether at least one slave has experienced a CRC error)
CrcErrorSlave;
(The first slave reporting a CRC error)
CrcErrorPort;
(The port of the first slave reporting a CRC error where the error occurred)
bIsStateMachineError;
(Whether at least one slave has reported a state machine error)
bIsInitError;
(Whether the error of the first slave reporting a state machine error occurred during initialization)
EsmErrorSlave;
(The first slave reporting a state machine error)
EsmErrorCode;
(The error code reported by the first slave with a state machine error)
OrStateVars;
(The logical "AND" of the State variables for each Sync Unit)
During actual testing, multiple insertions and removals of network cables were required to generate Lost Frame information.
The current value of ConnLostSlave
, which represents the name of the first slave that has lost connection, is Term38(E...
Specifically, it corresponds to the first module Term38(EK1101-0080)
displayed as INIT NO_COM
on the EtherCAT Online interface. This is due to the Ethernet cable being unplugged. Consequently, the second synchronization unit is invalid, as indicated by the value of InvalidSyncUnit
being 2. Additionally, the number of lost frames read, LostFrameCount
, is 15, which matches the display on the EtherCAT Online interface.
By comparing these values, it can be verified that the diagnostic information read by the PLC is consistent with the information provided by TwinCAT on the EtherCAT Online interface.
In fact, the information obtained by the function blocks (FBs) invoked in the routine goes far beyond what is shown in the Output. Users can further develop based on this, for example, by adding more outputs to display on specific HMIs, until the specific requirements of the project are met.
Notes:
- In the example, the total number of slaves in the entire network is obtained by summing the
SlaveCount
of the synchronization units. This method is only applicable when each slave in the synchronization units is either linked to the same Task or not linked at all. Otherwise, two sets ofWcState
andInfodata
may appear underSyncUnits
, as shown in the diagram below:
During testing, since only one EL1002 on the EK1100 was linked to variables while other modules were not, the latter were classified as "Unreferenced". Therefore, for easier monitoring, it is recommended to assign slaves that are refreshed by different Tasks to different SyncUnits.
- Linking BOOL Array Elements in the Program to UINT Variables in IO
The elements in a PLC BOOL array are of BOOL type, but their SIZE is 1 byte.
The
Frm0WcState
variable in IO is of UINT type.When linking PLC variables, due to type mismatch on both sides, you need to select "All Types" in the right-hand panel. Since you want to use the other party's Bit 15 to correspond to your own Bit 0, with a link width of 1 Bit, the Offset, Overlapped, and Bit Width in the above diagram should be set to 15, 0, and 1 respectively.
Keywords:
EtherCAT Diagnostics
Application Scope:
TwinCAT + EtherCAT Users