Creating and handling Profinet devices
This article explains how to create and handle Profinet I/O devices via TwinCAT Automation Interface. The following topics are being discussed:
- Creating Profinet devices
 - Adding Profinet boxes
 - Adding Profinet modules
 - Adding Profinet Sub-Modules
 
Creating Profinet devices
To create Profinet I/O devices (Controller/Device), the ITcSmTreeItem::CreateChild() method can be used. The Sub Type sets the actual type that should be added.
Name  | Sub Type  | 
|---|---|
Profinet Controller (RT)  | 113  | 
Profinet Controller CCAT (RT)  | 140  | 
Profinet Controller EL6631 (RT, EtherCAT)  | 119  | 
Profinet Controller EL6632 (RT + IRT, EtherCAT)  | 126  | 
Profinet Device (RT)  | 115  | 
Profinet Device CCAT (RT)  | 142  | 
Profinet Device CCAT (RT + IRT)  | 143  | 
Profinet Device EL6631 (RT, EtherCAT)  | 118  | 
Code Snippet (C#):
ITcSmTreeItem io = sysManager.LookupTreeItem("TIID");
ITcSmTreeItem profinetController = io.CreateChild("Profinet Controller", 113, null, null);Code Snippet (Powershell):
$io = $sysManager.LookupTreeItem("TIID")
$profinetController = $io.CreateChild("Profinet Controller", 113, $null, $null)Adding Profinet boxes
To create boxes below a Profinet device, the ITcSmTreeItem::CreateChild() may be used. The Sub Type depends on the box that should be added. The following table gives an overview about possible values:
Name  | Sub Type  | 
|---|---|
BK9102  | 9125  | 
EK9300  | 9128  | 
EL6631  | 9130  | 
In addition some knowledge about the corresponding Profinet GSD file is required to use the vInfo parameter properly. The vInfo parameter is composed of the following syntax: PathToGSDfile#ModuleIdentNumber#BoxFlags#DAPNumber
The ModuleIdentNumber can be determined from within the GSD file, e.g. via the XML structure <ProfileBody><ApplicationProcess><DeviceAccessPointList><DeviceAccessPointItem ModuleIdentNumber>. The ModuleIdentNumber is usually unique. If not, the DAPNumber specifies the position in the DeviceAccessPointList.
The following BoxFlags are currently interpreted:
Name  | Value  | Description  | 
|---|---|---|
GENERATE_NAME_FROM_PAB  | 0x0004  | Profinet name will be generated via process image  | 
GET_STATIONNAME  | 0x0400  | Profinet name from TC config will be used (tree item name)  | 
SET_NOT_IP_TO_OS  | 0x4000  | CE-only: Profinet IP will not be registered in OS  | 
Code Snippet (C#):
ITcSmTreeItem profinetEL6631 = profinetController.CreateChild("EL6631", 9130, null, "C:\\TwinCAT\\3.1\\Config\\Io\\Profinet\\GSDML-V2.31-beckhoff-EL6631-20140508.xml#0x3");Code Snippet (Powershell):
$profinetEL6631 = $profinetController.CreateChild("EL6631", 9130, $null, "C:\\TwinCAT\\3.1\\Config\\Io\\Profinet\\GSDML-V2.31-beckhoff-EL6631-20140508.xml#0x3")Adding Profinet modules
Profinet modules are created below the API node of a Profinet box. The API node is automatically created when adding a Profinet box to the TwinCAT configuration. To add Profinet modules the ITcSmTreeItem::CreateChild() method may be used. The SubType determines the position of the module within the <ProfileBody><ApplicationProcess><ModuleList> XML structure of the corresponding GSD file.
Code Snippet (C#):
ITcSmTreeItem profinetEL6631api = profinetEL6631.get_Child(1);
ITcSmTreeItem profinetModule1 = profinetEL6631api.CreateChild("", 30, null, null); // SubType 30 = 200 Byte In-Out
ITcSmTreeItem profinetModule2 = profinetEL6631api.CreateChild("", 12, null, null); // SubType 12 = 8 Byte In-Out
ITcSmTreeItem profinetModule3 = profinetEL6631api.CreateChild("", 8, null, null); // SubType 8 = 4 Byte Out
Code Snippet (Powershell):
$profinetEL6631api = $profinetEL6631.get_Child(1)
$profinetModule1 = $profinetEL6631api.CreateChild("", 30, $null, $null)
$profinetModule2 = $profinetEL6631api.CreateChild("", 12, $null, $null)
$profinetModule3 = $profinetEL6631api.CreateChild("", 8, $null, $null)
Adding Profinet Sub-Modules
Profinet Sub-Modules can be added below a so-called Profinet Modular Module. The handling is very similar to when adding regular Profinet modules. The Sub Type determines the position of the Sub-Module within the <ProfileBody><ApplicationProcess><ModuleList> XML structure of the corresponding GSD file.
Code Snippet (C#):
ITcSmTreeItem profinetModularModule = profinetEL6631api.CreateChild("", 98, null, null);    // SubType 98 = Modular
ITcSmTreeItem modularModule1 = profinetModularModule.CreateChild("", 12, null, null);       // SubType 12 = 8 Byte In-Out
ITcSmTreeItem modularModule2 = profinetModularModule.CreateChild("", 14, null, null);       // SubType 14 = 16 Byte Out
ITcSmTreeItem modularModule3 = profinetModularModule.CreateChild("", 31, null, null);       // SubType 31 = 8 Word InCode Snippet (Powershell):
$profinetModularModule = $profinetEL6631api.CreateChild("", 98, $null, $null) 
$modularModule1 = $profinetModularModule.CreateChild("", 12, $null, $null)
$modularModule2 = $profinetModularModule.CreateChild("", 14, $null, $null) 
$modularModule3 = $profinetModularModule.CreateChild("", 31, $null, $null)