Configuring the CANopen system
CANopen masters and slaves are created under the I/O node via CreateChild. The SubType determines the device type. The EtherCAT-based EL6751 and EL6751-0010 cards use SubTypes 87 and 98, respectively. After creation, the corresponding hardware resource is assigned using ClaimResources. If the network configuration is available as a DBC file, TwinCAT can automatically create the slaves defined in it.
Requirements
- A TwinCAT solution is open, and a DTE connection is active.
ITcSysManagerwas initialized as a COM object in an STA thread.- The EL6751 is available as a master, and the EL6751-0010 is available as a slave.
- for DBC file import: TwinCAT 3.1, Build 4018 or later.
C# sample
The master and slave are created under the I/O node TIID with CreateChild. Immediately after creation, ClaimResources assigns the first available hardware resource to the device.
ITcSmTreeItem devices = sysManager.LookupTreeItem("TIID");
// CANOpen master (SubType 87 = EL6751)
ITcSmTreeItem canMaster = devices.CreateChild("Device 2 (EL6751)", 87, "", null);
canMaster.ClaimResources(1);
// CANOpen slave (SubType 98 = EL6751-0010)
ITcSmTreeItem canSlave = devices.CreateChild("Device 3 (EL6751-0010)", 98, "", null);
canSlave.ClaimResources(1);
PowerShell sample
$devices = $sysManager.LookupTreeItem("TIID")
$canMaster = $devices.CreateChild("Device 2 (EL6751)", 87, "")
$canMaster.ClaimResources(1)
$canSlave = $devices.CreateChild("Device 3 (EL6751-0010)", 98, "")
$canSlave.ClaimResources(1)
Import a DBC file from TwinCAT 3.1 Build 4018
A DBC file, or CAN database, describes the messages and signals in a CAN network. When importing via the Automation Interface, the CANopen slaves defined in the DBC file are automatically created as subnodes of the master. The individual import options determine which messages are imported and how existing configurations are handled.
string dbcImportXml = @"<TreeItem>
<DeviceDef>
<CanOpenMaster>
<ImportDbcFile>
<FileName>C:\Projects\CANConfig\can_config.dbc</FileName>
<ImportExtendedMessages>false</ImportExtendedMessages>
<ImportMultiplexedDataMessages>false</ImportMultiplexedDataMessages>
<KeepUnchangedMessages>true</KeepUnchangedMessages>
<ExtBoxesSupport>false</ExtBoxesSupport>
<VectorXXXSupport>false</VectorXXXSupport>
<CommunicateWithSlavesFromDbcFile>true</CommunicateWithSlavesFromDbcFile>
</ImportDbcFile>
</CanOpenMaster>
</DeviceDef>
</TreeItem>";
canMaster.ConsumeXml(dbcImportXml);
The complete XML structure for device configuration is as follows:
<DeviceDef>
<AmsPort>28673</AmsPort>
<AmsNetId>172.17.251.109.2.1</AmsNetId>
<AddressInfo>
<Ecat>
<EtherCATDeviceId>0</EtherCATDeviceId>
</Ecat>
</AddressInfo>
<MaxBoxes>126</MaxBoxes>
<ScanBoxes>false</ScanBoxes>
<CanOpenMaster>
<ImportDbcFile>
<FileName>c:\dbc_file_folder\dbc_file_to_be_imported.dbc</FileName>
<ImportExtendedMessages>false</ImportExtendedMessages>
<ImportMultiplexedDataMessages>false</ImportMultiplexedDataMessages>
<KeepUnchangedMessages>true</KeepUnchangedMessages>
<ExtBoxesSupport>false</ExtBoxesSupport>
<VectorXXXSupport>false</VectorXXXSupport>
<CommunicateWithSlavesFromDbcFile>true</CommunicateWithSlavesFromDbcFile>
</ImportDbcFile>
</CanOpenMaster>
<Fcxxxx>
<CalculateEquiTimes>0</CalculateEquiTimes>
<NodeId>127</NodeId>
<Baudrate>500 k</Baudrate>
<DisableNodeStateModification>false</DisableNodeStateModification>
</Fcxxxx>
</DeviceDef>
The modified XML structure is read into the CANopen master node via ConsumeXml().
![]() | An overview of the import options:
|
According to the source, the “Simulate slaves from dbc file” option is not supported.
