This is an example on how to use the TwinCAT variant manager, _Boot folders and switch between a variant at runtime.
When a TwinCAT project is successfully compiled, all necessary runtime files are stored in the solution folder under Solution -> TwinCAT project -> "_Boot".
Upon activation , the files in this folder are copied to the target's Boot folder (C:\TwinCAT\3.1\Boot) and then the TwinCAT system is restarted. After a restart, the TwinCAT system loads the files from the boot folder into memory and starts to execute them.
More information about this process is also found here TwinCAT 3 | Machine update at file level.
The difference in the two variants of this example is that RevA uses an EL2809-0000 and RevB uses an EL2809-0015. In RevA, the EL2809-0015 is disabled, while in RevB, the EL2809-0000 is disabled.
Please see the variant manager documentation for further details about features and workflow.
-
A helper PowerShell script and .bat file are used for copying files around from the PLC at runtime. Please see the scripts folder of this repository. These two files are called from the PLC using NT_StartProcess at runtime.
-
The deployment properties of the PLC were modified. Two actions were added. Upon activation, the helper scripts folder is copied to the target, as well as all variant boot folders.
- On startup, the EtherCAT topology is scanned in.
- The Vendor, product, and revision number of each slave is stored in an array and then stored into a file for later reference.
- The actual EtherCAT configuration is also read in.
- The actual EtherCAT configuration is compared against the scanned-in topology. If the two match, a message is sent informing that the scanned topology and the actual configuration match. No further steps need to be taken if this is the case.
- If the scanned-in topology doesn't match the actual configuration, it is then compared against all other variants to see if there is a match.
- If a match is found, a message is sent indicating that the "X" variant matches and that you should consider loading it.
- Knowing what variant now needs to be loaded, this information is passed to a PowerShell script to perform a swap for the appropriate boot folder.
- The PowerShell script performs the following:
- Deletes all files from the boot folder (C:\TwinCAT\3.1\Boot), except the TwinCAT logged events (loggedevents.db).
- Copies all the files from the selected variant boot folder at C:\TwinCAT\3.1\Target\Resource\Variants\X to the boot folder (C:\TwinCAT\3.1\Boot).
- Reboots the PC. A TwinCAT restart could be sufficient as an alternative. See ADS PowerShell Module ->Set-AdsState, use ADS port 10000.
This sample is created by Beckhoff Automation LLC and is provided as-is under the Zero-Clause BSD license.
Should you have any questions regarding the provided sample code, please contact your local Beckhoff support team. Contact information can be found on the official Beckhoff website at https://www.beckhoff.com/en-us/support/.
TwinCAT 3 | Machine update at file level
TwinCAT 3 | Variant Management
TE1000 | TwinCAT 3 ADS PowerShell Module
The following components must be installed to run the sample code:
- TE1000 TwinCAT 3 Engineering version 3.1.4024.0 or higher
- A copy of the PowerShell script and .bat from the scripts folder of this repo stored into C:\TwinCAT\3.1\Target\Resource.