Creating and handling Devicenet devices

Just like any other I/O component, Devicenet devices may be added via the TwinCAT Automation Interface by using the CreateChild() method of the ITcSmTreeItem interface. The SubType specifies the device that should be added.

Code Snippet (C#):

ITcSmTreeItem io = sysManager.LookupTreeItem("TIID");
ITcSmTreeItem devicenet1 = io.CreateChild("Device 1 (EL6752)", 88, null, null);
ITcSmTreeItem devicenet2 = io.CreateChild("Device 2 (EL6752-0010)", 99, null, null);

Code Snippet (Powershell):

$io = $sysManager.LookupTreeItem("TIID")
$devicenet1 = $io.CreateChild("Device 1 (EL6752)", 88, $null, $null)
$devicenet2 = $io.CreateChild("Device 2 (EL6752-0010)", 99, $null, $null)

The following table gives an overview about all Devicenet I/O devices and their corresponding SubTypes. If a device should be missing, you can always find out the SubType yourself by following our documentation article about the XML description of a tree item.

Device

SubType

Devicenet Master FC52xx PCI

41

Devicenet Master EL6752 EtherCAT

88

Devicenet Slave FC52xx PCI

62

Devicenet Slave EL6752 EtherCAT

99

Devicenet Master CX1500-M520 PC104

73

Devicenet Slave CX1500-B520-PC104

74

Devicenet Monitor FC52xx PCI

59

Devicenet boxes can also be attached via CreateChild(). The SubType specifies the box that should be added.

Code Snippet (C#):

ITcSmTreeItem devicenet1box = devicenet1.CreateChild("Box 2 (EL6752-0010)", 5203, null, null);

Code Snippet (Powershell):

$devicenet1box = $devicenet1.CreateChild("Box 2 (EL6752-0010)", 5203, $null, $null)

To add variables to a Devicenet box, simply use the following code snippet. The vInfo parameter specifies the data type of the variable.

Code Snippet (C#):

ITcSmTreeItem inputVars = devicenet1box.LookupChild("Inputs");
inputVars.CreateChild("TestVarInt", 0, null, "INT");
inputVars.CreateChild("TestVarBool", 0, null, "BOOL");

Code Snippet (Powershell):

$inputVars = $devicenet1box.LookupChild("Inputs")
$inputVars.CreateChild("TestVarInt", 0, $null, "INT")
$inputVars.CreateChild("TestVarBool", 0, $null, "BOOL")