beckhoff TE1000 TwinCAT 3 — 6.5.4 Exporting PLC code in PLCopen format

Samples | PLC // Assign program to PlcTask (SubType 650, name must match exactly) ITcSmTreeItem task = sysManager.LookupTreeItem(@"TIPC^PLC1^PLC1 Project^PlcTask"); task.CreateChild("MyProg", 650); The SubType 650 for task assignment requires that the child name match the program name exactly. The program itself is created as a program POU using SubType 602. The path to the PlcTask node is TIPC^ ^ Project^PlcTask. 6.5.4 Exporting PLC code in PLCopen format | Exporting PLC code in PLCopen format ITcPlcOpenImportExport2.PlcOpenExport2 allows you to export individual POUs or entire subtrees of a PLC project as PLCopen XML.

The ITcPlcOpenImportExport2 interface is obtained by casting the PLC project Tree Item. The elements to be exported are addressed using a project-specific selector. The bSubTree parameter controls whether only the specified elements are exported, or whether all child elements are also exported. Requirements TwinCAT XAE is installed and started. A DTE connection to the target instance is active. ITcSysManager is initialized in an STA thread. A PLC project is included in the solution. The ITcPlcOpenImportExport2 interface is available starting with TwinCAT Build 4019. C# sample The selector is project-specific and uses ; as a separator, such as "POUs.fb1;POUs.fb2" .

Using bSubTree = true exports all sub-elements of the selected element, including methods, actions, transitions, and properties. Without this flag, only the explicitly listed elements are exported.

ITcSmTreeItem plcProject = sysManager.LookupTreeItem(@"TIPC^PLC1^PLC1 Project"); ITcPlcOpenImportExport2 exportInterface = (ITcPlcOpenImportExport2)plcProject; // Export a single POU exportInterface.PlcOpenExport2( @"C:\Export\MyProg.xml", // output file "POUs.MyProg", // selection (project-relative, ';' as separator) false // false = only listed elements, not recursive ); // Export selected POUs exportInterface.PlcOpenExport2( @"C:\Export\MyProg.xml", // output file "POUs.MyProg;DUTs.MyDUT", // selection (project-relative, ';' as separator) false // false = only listed elements, not recursive ); // Export entire POUs folder recursively exportInterface.PlcOpenExport2( @"C:\Export\AllPOUs.xml", "POUs", true // true = entire subtree including methods, actions, transitions, properties ); PowerShell sample The PowerShell sample calls PlcOpenExport2 with the same three parameters as the C# sample.

$plcProject = $sysManager.LookupTreeItem(@"TIPC^PLC1^PLC1 Project"); # Export a single POU $plcProject.PlcOpenExport2( 'C:\Export\MyProg.xml', # output file 'POUs.MyProg', # selection (project-relative,';' as separator) $false # false = only listed elements, not recursive ); # Export selected POUs TE1000 228 Version: 1.7.0