MATLAB Examples

Generate ENI Files for EtherCAT Devices

This example shows how to generate EtherCAT network information (ENI) files to use in Simulink Real-Time with EtherCAT devices.

The example shows the generation process steps in EtherCAT Configurator and the process steps in the TwinCAT XAE plugin for Microsoft Visual Studio®.

The hardware connections are:

  • EK1100 -- EtherCAT coupler
  • EL3062 -- EtherCAT terminal
  • EL4002 -- EtherCAT terminal
  • EL9011 -- Bus End terminal

The EK1100 coupler connects EtherCAT with the EtherCAT terminals (ELxxxx). One station consists of an EK1100 coupler, any number of EtherCAT terminals, and a bus end terminal.

To provide power connections, connect the 24 V and 0 V terminals of the EK1100 to a 24 V regulated power supply (RPS) +Ve and -Ve terminals.

The EL3062 analog input terminal processes signals in the range of 0-10 V. The voltage is digitized to a resolution of 12 bits and is transmitted.

The EL4002 analog output terminal generates signals in the range of 0 and 10 V.

To configure the EtherCAT network, connect the EtherCAT devices to the development computer on which the EtherCAT configurator is running. This connection permits scanning and discovery of the EtherCAT devices. After the configurator generates the XML file, you can reconnect the EtherCAT devices to the target computer. This diagram shows the suggested connections.

Contents

Install and Run EtherCAT Configurator ET9000

To install the EtherCAT configurator ET9000:

  1. Go to https://www.beckhoff.com/ and select Download.
  2. Select ET9000 and download the setup.
  3. Install the ET9000 configurator and start the software.
  4. Run the configurator and select the correct license keys or select the evaluation option.

The EtherCAT configurator creates an EtherCAT network information (ENI) file from the standardized slave description files (ESI - EtherCAT slave information). To generate the ESI files for the slaves:

  1. Start the ET9000 software.
  2. Right-click I/O Devices and select Scan Devices. Click OK.
  3. Select the correct network interface card (NIC) in your system and click OK.
  4. When the dialog box asks whether to scan for boxes, select Yes. As the EtherCAT devices in your network are scanned, they appear in the System Pane.
  5. When the dialog box asks whether to activate free run mode, select No.

When the scan is complete, expand the Device Hierarchy under I/O Devices in the System Pane. The EL3062 and the EL4002 devices appear under the EK1100 device.

Configure EtherCAT Master Node Data with Configurator

The configurator uses the ESI to configure the EtherCAT master node. This operation includes creating a task, configuring the task, and adding the I/O to the task.

To create an EtherCAT task:

  1. Under SYSTEM - Configuration, right-click Additional Tasks > Append Task.
  2. Provide a name for the task and click OK. In this example, the name of the task is slrt_task.
  3. Click the task. The value Cycle Ticks determines the cycle time. In the settings, it is set to 10ms.

To configure an EtherCAT task outputs:

  1. Click and drag the node Analog output (under AO Outputs Channel 1) to Outputs (under slrt_task).
  2. Select Analog output (under Outputs) and select the Variable tab.
  3. Click the Linked to button and select the corresponding entry (Analog Output under AO Outputs Channel 1 under Term 3).

By using distributed clocks (DC), the EtherCAT real-time Ethernet protocol can synchronize the time in all local bus devices within a narrow tolerance range. Only some EtherCAT devices support DC. When the device supports DC, it is important to configure a device for DC. For example, in the example configuration, the EL4002 supports DC. To configure the EL4002 for DC:

  1. Click Term 3 (EL4002) in the System Pane and select the DC tab. By default, the Operation Mode is set to SM-Synchron. Change Operation Mode to DC-Synchron.
  2. Click the Advanced Settings button and set the Distributed Clock options as shown.

Import a Device with the Configurator

Device import is often part of the workflow for third-party (different manufacturer) devices. Use this process to configure a device that is not present in the Beckhoff system. Numerous motors and their drives fall under this category. Sometimes, you must configure a device that is not present in the Beckhoff system. The TwinCAT EtherCAT master or System Manager uses the device description files for the devices to generate the configuration in online or offline mode.

The device descriptions are contained in ESI files (EtherCAT Slave Information) in XML format. These files can be requested from the respective manufacturer and are made available for download. An XML file can contain several device descriptions.

The ESI files for Beckhoff EtherCAT devices are available on the Beckhoff website and are stored in the TwinCAT installation folder. The default for TwinCAT2 is C:\TwinCAT\IO\EtherCAT. The files are read (once) when you open a new System Manager window and if they have changed since the last time that you opened the System Manager window.

If using a TwinCAT configurator, the TwinCAT installation includes the set of Beckhoff ESI files which were current at the time when the TwinCAT build was created. For TwinCAT 2.11, TwinCAT 3, and later, you can update the ESI folder from the System Manager if the programming PC is connected to the Internet (Option > Update EtherCAT Device Descriptions).

To import a device from an ESI file:

  1. For the ET9000 Configurator, the ESI folder is C:\Program Files (x86)\EtherCAT Configurator\EtherCAT. Paste the file from the manufacturer into this location.
  2. After adding the XML file, restart your configurator and select Actions > Reload Devices.
  3. If the device is connected, you can scan again to add the devices. (See Install and Apply Beckhoff EtherCAT Configurator ET9000.)
  4. If the device is not connected, you can also add the device in Offline mode. If you want to add the device to the same term, right-click your device in the hierarchy and select Append Box. A dialog box appears asking which device to add.
  5. Click the square icon next to Beckhoff Automation GmbH to collapse the hierarchy. You now see the manufacturer whose devices you added.
  6. Select the device that you want to add and click OK. Your device should now appear in the System Pane on the left.
  7. Repeat the steps under Configure EtherCAT Master Node Data to add the Outputs to your task. In this example, drag the available outputs under your drive to Outputs under slrt_task. Remember to make the appropriate DC Configurations for your device.
  8. DC configuration information is available from the manufacturer. In this case, enable DC.
  9. Continue with configuration of the terminals.

Export and Save the EtherCAT Configuration with the Configurator

To generate the ENI file and save the configuration:

  1. Click the node for your EtherCAT device, then click the EtherCAT tab.
  2. Click Export Configuration File.
  3. In the file save dialog box, enter an XML file name, such as BeckhoffAIOconfig.xml for this example, and then click Save. This XML file is the ENI file. The ENI file and the Simulink® Real-Time™ model that uses the ENI file cannot have the same name. They must have different names.
  4. Save the configuration as an ESM file. Click File > Save. If the ESM file corresponding to the ENI file is not present, the Beckhoff ET9000 program cannot open the ENI file.
  5. In the File Save dialog box, enter an ESM file name, such as et9000config.esm, and then click Save.

Install TwinCAT 3.1 XAE and Run Microsoft Visual Studio® with TwinCAT

When you install TwinCAT 3.1 eXtended Automation Engineering (XAE), you can use the integration of this software with Microsoft Visual Studio to program automation objects with IEC 61131-3 and C/C++ languages.

To install the TwinCAT 3.1 XAE:

  1. Go to https://www.beckhoff.com/ and select Download.
  2. Select TwinCAT 3 and download the setup.
  3. Install TwinCAT 3 and start Microsoft Visual Studio.
  4. From the TwinCAT menu, select Show Realtime Ethernet Compatible Devices.
  5. Select the Ethernet adapter for your EtherCAT device, then select Install.

To open a new TwinCAT project in Visual Studio:

  1. Start Visual Studio. Go to File > New > Project.
  2. Under Templates, select TwinCAT Project.
  3. Verify whether the project has been created successfully in the status bar of Microsoft Visual Studio.
  4. Enter your license if this instance is the first time that you are using TwinCAT. If you are using TwinCAT in evaluation mode, fill in the Captcha.
  5. Observe the Solution Explorer pane the right side of Visual Studio.
  6. Go to TWINCAT in the menu and select Scan. You can also right click Solution Explorer > your TwinCAT project > I/O > Devices > Scan.
  7. A dialog box opens with the message All devices may not automatically be found. Click OK and wait for the scan to complete. You now see a dialog box saying New I/O devices have been found.
  8. Ensure that the check box is selected, then click OK. A dialog box appears with a Scan for boxes? message. Click Yes. The EtherCAT devices in your network are scanned, and the devices appear.
  9. You see a dialog box that asks whether to activate free run mode. Select No.
  10. Observe the Solution Explorer and verify that the devices were scanned correctly.

Configure EtherCAT Master Node Data with TwinCAT

To configure the EtherCAT master node, create and configure a task, then add the inputs and outputs to the task.

To create an EtherCAT Task:

  1. In the Solution Explorer, right-click the Task node.
  2. In the Insert Task dialog box, select TwinCAT Task With Image, provide a name for the task, and click OK.
  3. Double-click the task that you created. The value Cycle Ticks determines the cycle time. In this example, it is set to 10 ms.
  4. Create at least one cyclic input/output task. Link this task to at least one input channel and one output channel on each slave device.

By using distributed clocks (DC), the EtherCAT real-time Ethernet protocol can synchronize the time in all local bus devices within a narrow tolerance range. Only some EtherCAT devices support DC. It is important that if a device supports DC, you configured it accordingly. For example, in the example configuration, the EL4002 supports DC.

To configure EtherCAT DC:

  1. Double-click the node Term 3 (EL4002) and select the DC tab.
  2. By default, the Operation Mode is set to SM-Synchron. Change the Operation Mode to DC-Synchron.
  3. Click Advanced Settings and set the Distributed Clock options as shown.

To export and save the EtherCAT configuration, generate the ENI file:

  1. Double-click the node for your EtherCAT device and click the EtherCAT tab.
  2. Click Export Configuration File.
  3. In the Save As dialog box, enter an XML file name, such as twincatconfig.xml, then click Save. This XML file is the ENI file. The ENI file and the Simulink® Real-Time™ model that uses the ENI file cannot have the same name. They must have different names.
  4. If the Solution file corresponding to the ENI file is not saved, the TwinCat XAE program cannot open the ENI XML file. Save the Solution file as an archive (zip file). Select File > Save Project As Archive.
  5. In the Save As dialog box, enter an ESM file name, such as twincatproject, and click Save. The project is saved as a .tnzip archive.

Related Information