Editors PLC program and subsequent cold start, persistent variables remain. With a reset of the PLC also RETAIN variables are reinitialized, persistent variables can only be initialized with a overall reset . The persistent variables are saved to a file when the TwinCAT system is shut down and are pre-initialized again with their saved values when the system is restarted. Sample: VAR PERSISTENT Rem2:INT; (* Persistente Variable*) END_VAR In order to check the correctness of the PERSISTENT and RETAIN variables, the system variables contain a byte, bootDataFlags, in the SYSTEMINFO [ } 217] structure. This byte indicates the state of the boot data after loading.
The upper four bits indicate the state of the persistent data, while the lower four bits indicate the state of the retain data. In order to be able to use this information, the "TcSystem.lib" library must be linked in. When shutting TwinCAT down the PERSISTENT and RETAIN data is written into two files on the hard disk. The path can be specified in TwinCAT System Control by means of the TwinCAT system properties (PLC tab). The standard setting is " :\TwinCAT\Boot". The files all have a fixed name with fixed extensions: If the file for the persistent and/or retain variables can not be written when shutting TwinCAT down, the standard reaction is for the backup file to be loaded.
In that case bit 1 of the bootDataFlags (for the RETAIN variables) in the PLC and/or bit 5 (for the PERSISTENT variables) is set. If the back-up file is not to be used under any conditions, a setting must be made in the NT registry. In the registry editor, under [HKEY_LOCAL_MACHINE\SOFTWARE\Beckhoff\TwinCAT\Plc] "ClearInvalidRetainData"=dword:00000000 "ClearInvalidPersistentData"=dword:00000000 the value of "ClearInvalidRetainData" or of "ClearInvalidPersistentData" must be set to 1. The default setting is 0. Constants, Typed literals Constants are identified by the key word CONSTANT . They can be declared locally or globally. Syntax: VAR CONSTANT : := ; END_VAR TX1200 118 Version:
1.3 Bit number Description 0 RETAIN variables: LOADED (without error) 1 RETAIN variables: INVALID (the back-up copy was loaded, since no valid data was present) 2 RETAIN variables: REQUESTED (RETAIN variables should be loaded, a setting in TwinCAT System Control) 3 reserved 4 PERSISTENT variables: LOADED (without error) 5 PERSISTENT variables:
INVALID (the back-up copy was loaded, since no valid data was present) 6 reserved 7 reserved File name Description TCPLC P x.wbp _ _ Boot project (x = number of the run-time system) TCPLC R x.wbp _ _ RETAIN variables (x = number of the run-time system) TCPLC T x.wbp _ _ PERSISTENT variables (x = number of the run-time system) TCPLC R x.wb~ _ _ Backup copy of the RETAIN variables (x = number of the run-time system) TCPLC T x.wb~ _ _ Backup copy of the PERSISTENT variables (x = number of the run-time system)