EtherCAT Init

Initialize EtherCAT Master node with data in Beckhoff configuration file


Simulink® Real-Time™ Library for EtherCAT®


The EtherCAT Init block initializes the EtherCAT master stack. The block specifies the Ethernet interface cards in the network.

Before you use this block, create and save an EtherCAT Network Information (ENI) file. You export the ENI file from one of the following EtherCAT configurators: the Beckhoff® ET9000, the Beckhoff TwinCAT®, or the Acontis EC-Engineer. See Configure EtherCAT Network.

Click Browse to find the ENI file. To read the ENI file and store the data in the EtherCAT Init block, click Refresh Data.

The Simulink Real-Time software supports multiple EtherCAT networks. To use multiple networks:

  • Use a different Ethernet card interface for each EtherCAT network.

  • In the model, use one EtherCAT Init block for each network.

Block Outputs



A vector containing six values:

[ErrVal MasterState DCErrVal MasterToNetworkClkDiff 
 DCInitState NetworkToSlaveClkDiff]

  • ErrVal0 if no error occurs. Otherwise, this element contains a value from EtherCAT Init Block Error Values.

    After you read ErrVal, the block clears it. To hold ErrVal for later examination, send it to a Signal Latch block.

  • MasterState — one of the following states.

    INIT1Initialization – The system finds slave devices and initializes the communication controller.
    PREOP2Preoperational — The system uses the communication controller to exchange system-specific initialization data. In this state, the network cannot transmit or receive signal data.
    SAFEOP4Safe operational — The network is running and ready for full operation. The master sends input data to the slave device. The slave device output remains in a safe state.
    OP8Operational — The network is in full operation. The master sends input data to the slave device. The slave device responds with output data.

  • DCErrVal0 if the distributed clock is turned off or if no error occurs. Otherwise, this element contains a value from EtherCAT Init Block DC Error Values.

  • MasterToNetworkClkDiff — Difference, in nanoseconds, between the master stack clock on the target computer and the clock on the first EtherCAT slave device that has enabled DC.

  • DCInitState1 if the distributed clock has been started. If 0, DC has not yet been initialized or the XML configuration file did not enable DC.

  • NetworkToSlaveClkDiff — Difference, in nanoseconds, between the clock on the first EtherCAT slave device and the least closely locked clock on the remaining slave devices. Applies only to slave devices that have enabled DC. If only one device on the network has enabled DC, this value is 0.

Block Parameters

Config file (ENI)

Specify the ENI file that you exported from the EtherCAT configurator.

Specify the full path name. If you specify only the file name and more than one file with that name exists on the MATLAB® path, MATLAB displays a message box to select the file that you want.

Device index

A unique integer in the range 0 to 15 that identifies the Ethernet card for an EtherCAT network.

For each EtherCAT network, the software generates a unique device index. The software inserts that device index as Device index into the EtherCAT Init block that represents the network.

PCI bus

Enter the PCI bus number for the Ethernet card.

PCI slot

Enter the PCI slot number for the Ethernet card.

Enable Log and Debugging

Select this check box to enable access to debugging and logging block parameters.

When you select Enable Log and Debugging, the following block parameters are visible.

Enable DC

Selected by default. Clear it only for driver and network debugging.

To disable distributed clocks for a reason other than debugging, modify the configuration file to disable the clocks. Do not clear the Enable DC check box unless MathWorks® technical support suggests that you do so.

Log link layer error messages, Log master state changes, Log all state changes, Log base clock changes, Log master config changes

Select these check boxes to generate driver-level messages for driver and network debugging.

For a high-speed model, turning these options on can cause CPU overloads.

Target log filename

Enter the name of the log file on the target computer, in single quotes. The default value is 'c:\dbglog.txt'.

If the target computer does not have a usable disk partition, the software does not create the log file.

Was this topic helpful?