TwinCAT 2
Startup
TwinCAT basically uses two user interfaces: the TwinCAT System Manager for communication with the electromechanical components and TwinCAT PLC Control for the development and compilation of a controller. The starting point is the TwinCAT System Manager.
After successful installation of the TwinCAT system on the PC to be used for development, the TwinCAT 2 System Manager displays the following user interface after startup:
![TwinCAT 2 1:](Images/png/9007201839238283__en-US__Web.png)
Generally, TwinCAT can be used in local or remote mode. Once the TwinCAT system including the user interface (standard) is installed on the respective PLC, TwinCAT can be used in local mode and thereby the next step is “Insert Device”.
If the intention is to address the TwinCAT runtime environment installed on a PLC as development environment remotely from another system, the target system must be made known first. In the menu under “Actions” → “Choose Target System...”, via the symbol “” or the “F8” key, open the following window:
![TwinCAT 2 3:](Images/png/9007201839306251__en-US__Web.png)
Use “Search (Ethernet)...” to enter the target system. Thus a next dialog opens to either:
- enter the known computer name after “Enter Host Name / IP:” (as shown in red)
- perform a “Broadcast Search” (if the exact computer name is not known)
- enter the known computer IP or AmsNetID.
![TwinCAT 2 4:](Images/png/2604409867__en-US__Web.png)
Once the target system has been entered, it is available for selection as follows (a password may have to be entered):
![TwinCAT 2 5:](Images/png/2584855563__Web.png)
After confirmation with “OK” the target system can be accessed via the System Manager.
Adding devices
In the configuration tree of the TwinCAT 2 System Manager user interface on the left, select “I/O Devices” and then right-click to open a context menu and select “Scan Devices…”, or start the action in the menu bar via . The TwinCAT System Manager may first have to be set to “Config mode” via
or via menu
“Actions” → “Set/Reset TwinCAT to Config Mode…” (Shift + F4).
![TwinCAT 2 8:](Images/png/9007201840216971__en-US__Web.png)
Confirm the warning message, which follows, and select “EtherCAT” in the dialog:
![TwinCAT 2 9:](Images/png/2604973067__en-US__Web.png)
Confirm the message “Find new boxes”, in order to determine the terminals connected to the devices. “Free Run” enables manipulation of input and output values in “Config mode” and should also be acknowledged.
Based on the sample configuration described at the beginning of this section, the result is as follows:
![TwinCAT 2 10:](Images/png/9007201843149963__en-US__Web.png)
The whole process consists of two stages, which may be performed separately (first determine the devices, then determine the connected elements such as boxes, terminals, etc.). A scan can also be initiated by selecting “Device ...” from the context menu, which then reads the elements present in the configuration below:
![TwinCAT 2 11:](Images/png/9007201853064203__en-US__Web.png)
This functionality is useful if the actual configuration is modified at short notice.
Programming and integrating the PLC
TwinCAT PLC Control is the development environment for the creation of the controller in different program environments: TwinCAT PLC Control supports all languages described in IEC 61131-3. There are two text-based languages and three graphical languages.
- Text-based languages
- Instruction List (IL)
- Structured Text (ST)
- Graphical languages
- Function Block Diagram (FBD)
- Ladder Diagram (LD)
- The Continuous Function Chart Editor (CFC)
- Sequential Function Chart (SFC)
The following section refers to Structured Text (ST).
After starting TwinCAT PLC Control, the following user interface is shown for an initial project:
![TwinCAT 2 12:](Images/png/9007201843168651__en-US__Web.png)
Sample variables and a sample program have been created and stored under the name “PLC_example.pro”:
![TwinCAT 2 13:](Images/png/9007201843338763__en-US__Web.png)
Warning 1990 (missing “VAR_CONFIG”) after a compile process indicates that the variables defined as external (with the ID “AT%I*” or “AT%Q*”) have not been assigned. After successful compilation, TwinCAT PLC Control creates a “*.tpy” file in the directory in which the project was stored. This file (“*.tpy”) contains variable assignments and is not known to the System Manager, hence the warning. Once the System Manager has been notified, the warning no longer appears.
First, integrate the TwinCAT PLC Control project in the System Manager via the context menu of the PLC configuration; right-click and select “Append PLC Project…”:
![TwinCAT 2 14:](Images/png/2625789835__en-US__Web.png)
Select the PLC configuration “PLC_example.tpy” in the browser window that opens. The project including the two variables identified with “AT” are then integrated in the configuration tree of the System Manager:
![TwinCAT 2 15:](Images/png/9007201848249611__en-US__Web.png)
The two variables “bEL1004_Ch4” and “nEL2008_value” can now be assigned to certain process objects of the I/O configuration.
Assigning variables
Open a window for selecting a suitable process object (PDO) via the context menu of a variable of the integrated project “PLC_example” and via “Modify Link...” “Standard”:
![TwinCAT 2 16:](Images/png/9007201848283147__en-US__Web.png)
In the window that opens, the process object for the variable “bEL1004_Ch4” of type BOOL can be selected from the PLC configuration tree:
![TwinCAT 2 17:](Images/png/9007201848356619__en-US__Web.png)
According to the default setting, certain PDO objects are now available for selection. In this sample the input of channel 4 of the EL1004 terminal is selected for linking. In contrast, the checkbox “All types” must be ticked for creating the link for the output variables, in order to allocate a set of eight separate output bits to a byte variable. The following diagram shows the whole process:
![TwinCAT 2 18:](Images/png/9007201849812747__en-US__Web.png)
Note that the “Continuous” checkbox was also activated. This is designed to allocate the bits contained in the byte of the variable “nEL2008_value” sequentially to all eight selected output bits of the EL2008 terminal. In this way it is possible to subsequently address all eight outputs of the terminal in the program with a byte corresponding to bit 0 for channel 1 to bit 7 for channel 8 of the PLC. A special symbol () at the yellow or red object of the variable indicates that a link exists. The links can also be checked by selecting a “Goto Link Variable” from the context menu of a variable. The object opposite, in this case the PDO, is automatically selected:
![TwinCAT 2 20:](Images/png/2607728907__en-US__Web.png)
The process of assigning variables to the PDO is completed via the menu selection “Actions” → “Generate Mappings”, key Ctrl+M or by clicking on the symbol in the menu.
This can be visualized in the configuration:
![TwinCAT 2 22:](Images/png/9007201849821195__en-US__Web.png)
The process of creating links can also take place in the opposite direction, i.e. starting with individual PDOs to variable. However, in this example it would then not be possible to select all output bits for the EL2008, since the terminal only makes individual digital outputs available. If a terminal has a byte, word, integer or similar PDO, it is possible to allocate this to a set of bit-standardized variables. Here, too, a “Goto Link Variable” from the context menu of a PDO can be executed in the other direction, so that the respective PLC instance can then be selected.
Activation of the configuration
The allocation of PDO to PLC variables has now established the connection from the controller to the inputs and outputs of the terminals. The configuration can now be activated. First, the configuration can be verified via (or via “Actions” → “Check Configuration”). If no error is present, the configuration can be activated via
(or via “Actions” → “Activate Configuration…”) to transfer the System Manager settings to the runtime system. Confirm the messages “Old configurations are overwritten!” and “Restart TwinCAT system in Run mode” with “OK”.
A few seconds later the real-time status is displayed at the bottom right in the System Manager. The PLC system can then be started as described below.
Starting the controller
Starting from a remote system, the PLC control has to be linked with the Embedded PC over Ethernet via “Online” → “Choose Run-Time System…”:
![TwinCAT 2 26:](Images/png/9007201851314571__en-US__Web.png)
In this sample “Runtime system 1 (port 801)” is selected and confirmed. Link the PLC with the real-time system via menu option “Online” → “Login”, the F11 key or by clicking on the symbol . The control program can then be loaded for execution. This results in the message “No program on the controller! Should the new program be loaded?”, which should be acknowledged with “Yes”. The runtime environment is ready for the program start:
![TwinCAT 2 28:](Images/png/9007201851349643__en-US__Web.png)
The PLC can now be started via “Online” → “Run”, F5 key or .