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:
- A PLC project created in TwinCAT.
Create variables as follows:
- 1. Create the variables in your PLC project in a VAR RETAIN area.
- 2. Click on Build in the toolbar at the top, then on Build Solution.
- 3. Click on PLC Instance in the tree view on the left and then on the tab Data Area.
- 4. Under Retain Hdl, select the Retain Handler that you have created.
- 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.
An existing link is displayed with an arrow symbol.