IoDrvEtherCAT (FB)

FUNCTION_BLOCK IoDrvEtherCAT EXTENDS IoDrvBase IMPLEMENTS ICmpIoDrvParameter

Implicit Master Instance

The function block instance for the EtherCAT master. An instance type IoDrvEtherCAT is generated for each EtherCAT master that is inserted into the device tree. The name of the instance corresponds to the name of the master in the device tree. The availability of the instance is shown in the IEC Objects area of the EtherCAT I/O Mapping dialog box of the master

Examples how to use the master instance

  • Restarting the master with the xRestart variable:

    EtherCAT_Master.xRestart := xRestart;

    EtherCAT_Master();

  • Stopping communication on the bus with the xStop variable:

    EtherCAT_Master.xStopBus := xStop;

    EtherCAT_Master();

  • Calling the master for retrieving information about the download success of the configuration parameters:

    EtherCAT_Master();

    xFinish := EtherCAT_Master.xConfigFinished;

Chained List for Checking of All Slaves

For the monitoring of individual slaves in the program the instance is called and the state is determined via wState. For simplification all masters and slaves can be determined by chained lists and all slaves can be checked by a simple WHILE loop. The properties NextInstance and LastInstance exist for both the master and the slave. These properties point to the next or previous slave. For the master there is an additional property, FirstSlave, which provides a pointer to the first slave. In accordance with the following example you can check all slaves:

Example

Following example code checks all slaves for operational mode

PROGRAM PLC_PRG
VAR
   pSlave: POINTER TO ETCSlave;
END_VAR
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

Initially, the first slave is fetched to the master via EtherCAT_Master.FirstSlave. In the WHILE loop the respective instance is called and wState is thus determined. The status can then be checked. The pointer to the next slave is fetched with pSlave^.NextInstance. If the list is finished, the pointer is ZERO and the loop ends.

InOut:

Scope

Name

Type

Initial

Comment

Input

xRestart

BOOL

FALSE

Rising edge: The master is restarted and all configuration parameters are reloaded.

xStopBus

BOOL

FALSE

Stop the bus when signal is true

Output

xConfigFinished

BOOL

TRUE: Transfer of all configuration parameters was completed with no errors. Communication is running on the bus.

xDistributedClockInSync

BOOL

If distributed clocks are used, then the PLC is synchronized with the first EtherCAT slave with the DC option activated. The output is TRUE as soon as the synchronization is ended successfully. This signal can be used, for example, for activating SoftMotion function blocks when the PLC is in synchronous mode. Otherwise position jumps can occur. When starting the PLC, the output is FALSE and switches to TRUE after a few seconds. If the synchrony is lost due to an error, then the output is reset to FALSE.

xError

BOOL

The output is TRUE when an error occurs when starting the EtherCAT stack, or communication with the slaves is interrupted because no more messages can be received (for example, due to a damaged cable).

xSyncInWindow

BOOL

The output is TRUE when the Sync Window Monitoring option is activated and the synchronization of all slaves is within the Sync Window.

Properties:

Methods:

Structure: