Importing and exporting an ENI file to and from a (simulation) device
An ENI file (EtherCAT Network Information) is an XML file that describes a complete EtherCAT topology. It contains all slaves, along with their addresses and process data, and is typically exported from an existing TwinCAT configuration. By importing the data into a simulation device, an EtherCAT topology can be replicated without the need for real hardware. This is useful for testing and development when the physical system is not available.
Both processes are controlled via ConsumeXml: the export on the EtherCAT master using the ExportConfigurationFile element, and the import on the simulation device using the ImportConfigurationFile element.
Requirements
- A TwinCAT solution is open, and a DTE connection is active.
ITcSysManagerwas initialized as a COM object in an STA thread.- For export: A configured EtherCAT master is present in the I/O configuration
- For import: An ENI file in the format
.xmlis located at a known absolute path.
Exporting an ENI file from an existing configuration
In the TwinCAT interface, the ENI file is generated on the EtherCAT master via the EtherCAT tab using the Export Configuration File… button. In the Automation Interface, this corresponds to a ConsumeXml call on the master node using the ExportConfigurationFile element. The element's content is the target path of the file to be written.
C# sample
ITcSmTreeItem ecMaster = sysManager.LookupTreeItem(@"TIID^EtherCAT Master");
// Export ENI configuration file
ecMaster.ConsumeXml(
@"<TreeItem><EtherCAT><ExportConfigurationFile>" +
@"C:\Projects\EtherCATConfig.xml" +
@"</ExportConfigurationFile></EtherCAT></TreeItem>"
);PowerShell sample
$ecMaster = $sysManager.LookupTreeItem("TIID^EtherCAT Master")
# Export ENI configuration file
$ecMaster.ConsumeXml("<TreeItem><EtherCAT><ExportConfigurationFile>C:\Projects\EtherCATConfig.xml</ExportConfigurationFile></EtherCAT></TreeItem>")![]() | The export is performed on the EtherCAT master node, not on a slave. As with the import, the file path must be a full absolute path. |
Importing an ENI file into a simulation device
First, an EtherCAT simulation device with SubType 144 is created under the I/O node TIID. The ENI file is then loaded using ConsumeXml with the ImportConfigurationFile element. After the import, all slaves described in the file appear as configured devices under the simulation device, identical to the original configuration, including addresses and PDO mapping.
C# sample
First, an EtherCAT simulation device with SubType 144 is created under the I/O node TIID. The ENI file is then loaded via ConsumeXml using the element ImportConfigurationFile. After the import, all slaves described in the file appear as configured devices under the simulation device, identical to the original configuration, including addresses and PDO mapping.
ITcSmTreeItem ioNode = sysManager.LookupTreeItem("TIID");
// Create EtherCAT simulation device (SubType 144)
ITcSmTreeItem ecSimDevice = ioNode.CreateChild("EtherCAT_Sim", 144);
// Import ENI configuration file
ecSimDevice.ConsumeXml(
@"<TreeItem><EtherCAT><ImportConfigurationFile>" +
@"C:\Projects\EtherCATConfig.xml" +
@"</ImportConfigurationFile></EtherCAT></TreeItem>"
);
PowerShell sample
$ioNode = $sysManager.LookupTreeItem("TIID")
# Create EtherCAT simulation device (SubType 144)
$ecSimDevice = $ioNode.CreateChild("EtherCAT_Sim", 144)
# Import ENI configuration file
$ecSimDevice.ConsumeXml("<TreeItem><EtherCAT><ImportConfigurationFile>C:\Projects\EtherCATConfig.xml</ImportConfigurationFile></EtherCAT></TreeItem>")
![]() | The simulation device with SubType |
