Creating PLC objects
PLC objects such as methods, properties, actions, function blocks, or folders are created using CreateChild. The call takes the name of the new element, the SubType as a numeric value specifying the desired object type, and an optional vInfo array containing additional information such as the IEC languages or the return data type. The SubType determines which element is created.
Requirements
- TwinCAT XAE is installed and started.
- A DTE connection to the target instance is active.
ITcSysManageris initialized in an STA thread.- A PLC project with at least one function block exists.
SubType reference
The following table lists the SubType values for CreateChild, along with their internal tag, object type, and the elements of the vInfo array. A dash in the vInfo-Parameter column indicates that no creation parameters are documented for this element.
SubType | Tag | Item | Category | vInfo parameter |
|---|---|---|---|---|
600 | TREEITEMTYPE_PLCAPP | PLC application, root object | – | – |
601 | TREEITEMTYPE_PLCFOLDER | PLC folder | Folder | No vInfo parameter; use |
602 | TREEITEMTYPE_PLCPOUPROG | Program | POU | [0, optional]: IEC languages as specified at |
603 | TREEITEMTYPE_PLCPOUFUNC | Function | POU | [0]: IEC language. [1]: Return data type, such as DINT or BOOL. |
604 | TREEITEMTYPE_PLCPOUFB | Function block | POU | [0, optional]: IEC language. [1–4, optional]: Extends/Implements analogous to program. |
605 | TREEITEMTYPE_PLCDUTENUM | Enum | DUT | [0, optional]: Declaration text. |
606 | TREEITEMTYPE_PLCDUTSTRUCT | Struct | DUT | [0, optional]: Declaration text. |
607 | TREEITEMTYPE_PLCDUTUNION | Union | DUT | [0, optional]: Declaration text. |
608 | TREEITEMTYPE_PLCACTION | Action | POU | [0, optional]: IEC language. [1, optional]: PLCopen XML string containing the code. |
609 | TREEITEMTYPE_PLCMETHOD | Method | POU | [0, optional]: IEC language. [1, optional]: Return data type. [2, optional]: Access modifier. [3, optional]: PLCopen XML string. |
610 | TREEITEMTYPE_PLCITFMETH | Method (interface) | Interface | [0]: Return data type. |
611 | TREEITEMTYPE_PLCPROP | Property | POU | [0]: IEC language. [1]: Return data type. [2, optional]: Access modifier. |
612 | TREEITEMTYPE_PLCITFPROP | Property (interface) | Interface | [0]: Return data type. |
613 | TREEITEMTYPE_PLCPROPGET | Property Get | POU | [0, optional]: IEC language. [1, optional]: Access modifier. [2, optional]: PLCopen XML. |
614 | TREEITEMTYPE_PLCPROPSET | Property Set | POU | [0, optional]: IEC language. [1, optional]: Access modifier. [2, optional]: PLCopen XML. |
615 | TREEITEMTYPE_PLCGVL | Global variable list | GVL | [0, optional]: Declaration text. |
616 | TREEITEMTYPE_PLCTRANS | Transition | POU | [0, optional]: IEC language. [1, optional]: PLCopen XML with code. |
617 | TREEITEMTYPE_PLCLIBMAN | Library manager | – | – |
618 | TREEITEMTYPE_PLCITF | Interface | Interface | [0, optional]: Extension type. |
619 | TREEITEMTYPE_PLCVISOBJ | Visualization object | – | – |
620 | TREEITEMTYPE_PLCVISMAN | Visualization manager | – | – |
621 | TREEITEMTYPE_PLCTASK | PLC task object | – | – |
622 | TREEITEMTYPE_PLCPROGREF | Program reference | – | – |
623 | TREEITEMTYPE_PLCDUTALIAS | Alias | DUT | [0, optional]: Declaration text. |
624 | TREEITEMTYPE_PLCEXTDATATYPECONT | External data type container | – | – |
625 | TREEITEMTYPE_PLCTMCDESCRIPTION | TMC description file | – | – |
629 | – | Parameter list | PL | [0, optional]: Declaration text. |
631 | – | UML Class Diagram | POU | No vInfo parameter. |
654 | TREEITEMTYPE_PLCITFPROPGET | Property Get (interface) | Interface | No vInfo parameter; use |
655 | TREEITEMTYPE_PLCITFPROPSET | Property Set (interface) | Interface | No vInfo parameter; use |
C# sample: Creating a method
// Look up function block
ITcSmTreeItem fb = sysManager.LookupTreeItem(@"TIPC^PLC1^PLC1 Project^POUs^MyFB");
// Create method (SubType 609 — source-verified)
// vInfo[0] = method name, vInfo[1] = return type (REQUIRED)
object[] vInfoMethod = new object[] { "MyMethod", "BOOL" };
fb.CreateChild("MyMethod", 609, "", vInfoMethod);
// Create folder for methods (SubType 601 — available from TC 4024.14)
ITcSmTreeItem folder = fb.CreateChild("Folder", 601);
ITcSmTreeItem methodInFolder = folder.CreateChild("MyMethod2", 609);
Reading and setting the declaration and implementation
Reading and setting the declaration and implementation text of a POU is described in a separate article: Reading and setting the declaration and implementation of a POU.
PLC access modifier
The following access modifiers are valid: PUBLIC, PRIVATE, PROTECTED, and INTERNAL.
Creating a function block using Extends or Implements
string[] vInfo;
bool bExtends = true;
bool bImplements = true;
if (bExtends && bImplements)
{
vInfo = new string[5];
vInfo[0] = language.AsString();
vInfo[1] = "Extends";
vInfo[2] = "ADSRDSTATE";
vInfo[3] = "Implements";
vInfo[4] = "ITcADI";
}
else if (bExtends)
{
vInfo = new string[3];
vInfo[0] = language.AsString();
vInfo[1] = "Extends";
vInfo[2] = "ADSRDSTATE";
}
else
{
vInfo = new string[1];
vInfo[0] = language.AsString();
}
ITcSmTreeItem newPOU = parent.CreateChild("FB_Test", 604, "", vInfo);
Import POUs (templates)
C#:
ITcSmTreeItem plcProject = systemManager.LookupTreeItem("TIPC^PlcGenerated^PlcGenerated Project");
plcProject.CreateChild("NameOfImportedPOU", 58, null, pathToPouFile);
plcProject.CreateChild(null, 58, null, stringArrayWithPathsToPouFiles);
PowerShell:
$plcProject = $systemManager.LookupTreeItem("TIPC^PlcGenerated^PlcGenerated Project")
$plcProject.CreateChild("NameOfImportedPOU", 58, $null, $pathToPouFile)
$plcProject.CreateChild($null, 58, $null, $stringArrayWithPathsToPouFiles)
![]() | A POU template file can be a |
