beckhoff TE1000 TwinCAT 3 — 6.5.3 Linking a PLC task to a program

Samples | PLC Requirements A TwinCAT solution containing at least one PLC project is open.

PowerShell sample $sln = $dte.Solution $sysMan = $sln.Projects.Item(1).Object # Compile SysMan project using the SolutionBuild interface $sysManProject = $dte.Solution.Projects.Item(1) $sysManProjectPath = $sysManProject.FullName $sysMan.ConfigurationManager.ActiveTargetPlatform = "TwinCAT RT (x64)" $sln.SolutionBuild.BuildProject("Release|TwinCAT RT (x64)", $sysManProjectPath, $true) # Compile SysMan-Project with BuildTargetPlatform command $sysMan.BuildTargetPlatform("TwinCAT RT (x64)") # Compile PLC project (path to .plcproj file) $plcProjectPath = "C:\Projects\MyProject\PLC1\PLC1.plcproj" $sysMan.ConfigurationManager.ActiveTargetPlatform = "TwinCAT RT (x64)" $sln.SolutionBuild.BuildProject("Release|TwinCAT RT (x64)", $plcProjectPath, $true) # Check result (0 = success) $lastBuildInfo = $sln.SolutionBuild.LastBuildInfo if ($lastBuildInfo -ne 0) { Write-Error "Build fehlgeschlagen" } C# sample EnvDTE.Solution sln = dte.Solution; string plcProjectPath = @"C:\Projects\MyProject\PLC1\PLC1.plcproj"; systemManager.ConfigurationManager.ActiveTargetPlatform = "TwinCAT RT (x64)"; // Third parameter:

true = wait until build is complete sln.SolutionBuild.BuildProject("Release|TwinCAT RT (x64)", plcProjectPath, true); int result = sln.SolutionBuild.LastBuildInfo; // 0 = success The first parameter is the build configuration, such as "Release|TwinCAT RT (x64)" or "Debug|TwinCAT RT (x64)" . The third parameter, true , blocks the call until the build is complete. LastBuildInfo != 0 indicates an error. The exact error messages are listed in the DTE's error list. Before starting a build via the DTE's SolutionBuild interface, you must use System Manager to set the target platform to the appropriate configuration. Otherwise, a clean build is not possible.

The official TwinCAT Platform Matrix provides a complete overview of the supported target platforms (operating system, processor, PE/ELF format). 6.5.3 Linking a PLC task to a program | Linking a PLC task to a program In TwinCAT, a PLC program of type Program must be explicitly assigned to a PlcTask. This is done via CreateChild with the SubType 650 . The name of the child object created must be identical to the program name. Requirements A PLC project is included in the solution.

C# sample // Create PLC project ITcSmTreeItem plcNode = sysManager.LookupTreeItem("TIPC"); ITcSmTreeItem plcProject = plcNode.CreateChild("PLC1", 0, "", "Standard PLC Template"); // Create program POU (SubType 602 = Program) ITcSmTreeItem pous = sysManager.LookupTreeItem(@"TIPC^PLC1^PLC1 Project^POUs"); pous.CreateChild("MyProg", 602); TE1000 227 Version: 1.7.0