CodeGenerationDemo

The Scripting Container (download here) is a C# WPF application which represents a collection of all available Automation Interface samples. Most of these samples are also available as a standalone sample download - however, as new samples become available, they will be first published in the Scripting Container before creating a separate sample. Therefore we recommend to become familiar with this application and to check periodically for new samples.

This article describes the general structure of the Scripting Container application and consists of the following topics:

The Graphical User Interface (GUI)

After you have started the CodeGenerationDemo application, its GUI will look as follows:

CodeGenerationDemo 1:

On the left hand side you can select from three different TwinCAT configuration, each with its own I/O, Axis and PLC configuration.

The dropdown box on the top right side lets you choose which Visual Studio version the script code should use to create the configuration - in case you have different Visual Studio versions installed on your system.

To start the configuration creation, simply select a configuration and press "Generate".

Location of sample scripts ("Where's the Automation Interface code???" )

The actual Automation Interface code can be found within the following classes:

Depending on the selected configuration, the CodeGenerationDemo application instantiates one of the three ConfigurationScriptX.cs classes, which all derive from CodeGenerationScript.cs.

Each class provides corresponding methods for creating the PLC, Axis or I/O configuration.

Location of data ("Where does all the data come from?")

Each configuration has its own I/O, Axis and PLC settings. As you may have already noticed, this configuration is not hard-coded into the Automation Interface code (like in other AI samples). In this demo, these settings are stored in an XML file that can be found under "CodeGenerationDemo\Data\Orders.xml". This XML file specifies two important XML sub-structures which are used to store TwinCAT settings.

Main description of a configuration:

<MachineOrders>
<Order id="1">
...
</Order>
</MachineOrders>

This structure defines a configuration and sets its global descriptive properties, e.g. Name, Description, ... . These properties will be shown on the GUI below the configuration selection.

Actual configuration with a reference to its description:

<AvailableConfigurations>
<Configuration id="..." name="...">
...
</Configuration>
</AvailableConfigurations>

This structure specifies the I/Os, Axis, PLC libraries and linking.