beckhoff TE1000 TwinCAT 3 — 6.3.2 Using Templates

Samples | System Templates at "configuration level": Templates at configuration level can exist as different TwinCAT configurations (*.sln or *.tszip file). Each configuration can contain different content and can be opened and activated by the Automation Interface code. Templates at "(PLC) project level": Templates at (PLC) project level can exist as multiple TwinCAT PLC projects, either as an unpacked folder structure (*.plcproj file) or as a container file (*.tpzip). These PLC projects can then be imported via the Automation Interface code if required. Templates at "structural element level": Templates at structural element level can exist as TwinCAT export files (*.xti).

If required, these files can be imported via the Automation Interface code and contain all the settings that have been made for an EtherCAT master I/O device. As the above description suggests, all the different template levels have one thing in common: the templates exist as files in the file system. It is considered best practice to clearly define which type of "template pool" is to be used at the beginning of the implementation of a custom Automation Interface application. A template pool describes a repository in which all template files (which can also be a mixture of different template levels) are stored.

This could simply be the local (or remote) file system or a source control system (e.g. Team Foundation Server), from which template files are automatically retrieved, checked out and assembled into a new TwinCAT configuration. For a better overview and to simplify the first steps, we have created a separate documentation article that shows how the Visual Studio Object Model (DTE) is used for connection to a Team Foundation Server (TFS) and how these processes are executed via the program code. However, you can get more information about using TFS via the Automation Interface code, and we highly recommend reading the relevant articles on the Microsoft Developer Network (MSDN).

The following topics describe how each template level in the Automation Interface can be used for a different TwinCAT area (I/O, PLC, etc.). Working with configuration templates Templates at configuration level offer the most basic option for using templates. In this scenario, a template pool contains two or more pre-configured TwinCAT configurations and offers them as TwinCAT solution files (*.sln or *.tszip). These files can be opened via the Automation Interface using the Visual Studio method AddFromTemplate(). Code snippet (C#): project = solution.AddFromTemplate(@"C:\TwinCAT Project.tszip", destination, projectName); Code snippet (PowerShell):

$project = $solution.AddFromTemplate(@"C:\TwinCAT Project.tszip", $destination, $projectName) OR Code snippet (C#): project = solution.Open(@"C:\TwinCAT Project 1.sln"); Code snippet (PowerShell): $project = $solution.Open(@"C:\TwinCAT Project 1.sln") Working with I/O templates When working with I/O devices, users often receive the same tasks on the I/O devices again and again. This means making the same settings on the I/O devices with every TwinCAT configuration. TwinCAT offers a mechanism that saves all these settings in a special file format, the XTI file (*.xti).

This file format can be used by the Automation Interface code to import a new configuration using the ImportChild() method defined in the ITcSmTreeItem interface. Code snippet (C#): ITcSmTreeItem io = systemManager.LookupTreeItem("TIID"); ITcSmTreeItem newIo = io.ImportChild(@"C:\IoTemplate.xti", "", true, "SomeName"); TE1000 198 Version: 1.7.0