Creating and linking variables

Once you have created a Retain Handler in TwinCAT, you can declare variables in the PLC and link them to the Retain Handler. The variables have to be identified in the PLC with the keyword VAR_RETAIN.

Prerequisite for this step:

Create variables as follows:

1. Create the variables in your PLC project in a VAR RETAIN area.
Creating and linking variables 1:
2. Click on Build in the toolbar at the top, then on Build Solution.
Creating and linking variables 2:
3. Click on PLC Instance in the tree view on the left and then on the tab Data Area.
Creating and linking variables 3:
4. Under Retain Hdl, select the Retain Handler that you have created.
Creating and linking variables 4:
After selecting a Retain Handler as a target, the symbols in the tree view are linked and a mapping is created.
In the tree view the variables are created from the PLC under the Retain Handler and linked to the variables from the PLC instance.
Creating and linking variables 5:
An existing link is displayed with an arrow symbol.