beckhoff TE1000 TwinCAT 3 — 6.5.6 Reading and setting the declaration and implementation of a POU

Samples | PLC 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 .TcPou file or the corresponding files for DUTs and/or GVLs.

The sample shows two options: importing a single file or importing multiple files at once by storing the file paths in a string array. 6.5.6 Reading and setting the declaration and implementation of a POU | Reading and setting the declaration and implementation of a POU Each POU with a declaration and implementation area exposes these via the interfaces ITcPlcDeclaration and ITcPlcImplementation . You can read and set both areas using the properties DeclarationText and ImplementationText . ImplementationXml provides the implementation in PLCopen XML format. Requirements TwinCAT XAE is installed and started. A DTE connection to the target instance is active.

ITcSysManager is initialized in an STA thread. The target POU is included in the PLC project. Setting the declaration and implementation The POU's Tree Item is converted via cast to ITcPlcDeclaration and ITcPlcImplementation . The respective content is set using the properties DeclarationText and ImplementationText . // Cast directly to declaration and implementation interfaces ITcSmTreeItem method = sysManager.LookupTreeItem(@"TIPC^PLC1^PLC1 Project^POUs^MyFB^MyMethod"); ITcPlcDeclaration decl = method as ITcPlcDeclaration; decl.DeclarationText = "VAR_INPUT\n nValue :

INT;\nEND_VAR"; ITcPlcImplementation impl = method as ITcPlcImplementation; impl.ImplementationText = "MyMethod := nValue > 0;"; Reading the declaration and implementation These same properties can also be read. The following sample creates a function block and then reads its declaration, implementation, and implementation XML. $plcPousItem = $systemManager.LookupTreeItem("TIPC^PlcGenerated^PlcGenerated Project^POUs") $newFb = $plcPousItem.CreateChild("FB_TEST", 604, "", 6) $decl = $newFb.DeclarationText $impl = $newFb.ImplementationText $implXml = $newFb.ImplementationXml TE1000 232 Version: 1.7.0