Settings of the TwinCAT module generator
Adds a project export configuration
exportConfig = TwinCAT.ModuleGenerator.ProjectExportConfig('FullPath',FullPathToVSproj);
The full path and name of the Visual Studio project to be created is passed to the 'FullPath' property.
Returns an object of the class TwinCAT.ModuleGenerator.ProjectExportConfig.
Sample call:
FullPathToVSproj = 'C:\BuildDir\MyMATLABFcn';
exportConfig = TwinCAT.ModuleGenerator.ProjectExportConfig('FullPath',FullPathToVSproj);
Methods of the class TwinCAT.ModuleGenerator.ProjectExportConfig
| Adds an export configuration to the project. To create an export configuration, see section Creating an export configuration. The export configuration is appended under Properties in the cell array ClassExportCfg. For an example call, see Module generator quick start.
|
| This creates a mat file and stores the project export configuration in it. The transfer argument is a path where the mat file is to be stored. Example call:
This saves the project export configuration in the current path.
|
| This loads a saved project export configuration. The transfer argument specifies the path of the mat file containing the saved configuration. Example call:
Loads the project export configuration from the current path. |
| Opens a graphical configuration interface for setting up the project export configuration.
|
| Gives an overview of the current project export configuration in the MATLAB® Command Window. See Module generator quick start. Example call:
|

Properties of the class TwinCAT.ModuleGenerator.ProjectExportConfig
Project
Structure with entries for configuring the build properties, the PLC library and the possible callbacks.
Project.FullPath
FullPath to the TwinCAT C++ project to be created.
Project.VendorName
Name of the Vendor. The Vendor Name is used to structure the TwinCAT objects. The vendor is created as a folder within the repository’s path and becomes visible in the structure once the PLC library and the TcCOM object have been inserted.
Project.IncrementVersion
Possible values: “None”, “Revision”, “Build”, “Minor”, “Major”
Default value: “Revision”
This setting determines which of the four digits of the version number are incremented. The basis is the most recent version available on the engineering system (see DrvFileVersion
).
Project.DrvFileVersion
Default: Search for the most recent version on the engineering system. If no existing version is found, it starts at 0.0.0.0.
Direct setting of a version: Can be set directly as a string, e.g. “1.52.32.0”. IncrementVersion
will then not be executed.
Project.Publish
If TRUE, the created TwinCAT C++ project is built for the configured platforms.
Project.PublishPlatformtoolset
This configures the Visual Studio version to use. This can be specified precisely or set to Auto (default).
Project.PublishTcRTx86
If TRUE, XAR is built on a Windows 32-bit platform.
Project.PublishTcRTx64
If TRUE, XAR is built on a Windows 64-bit platform.
Project.PublishTcOSx64
If TRUE, XAR is built on a TwinCAT/BSD platform.
Project.SignTwinCatCertName
A TwinCAT OEM certificate for driver signing can be specified here (not mandatory). The password is to be entered into the Windows Registry of the user with the TcSignTool. Detail see Initial setup of the software.
Project.TmxArchive
Enter a path and file name here as a string in order to create a TMX archive. Example: Project.TmxArchive = “c:\archives\[Date]-[Time]-[LibName][LibVersion].exe” creates a self-extracting TMX archive under c:\archies. The placeholders are resolved in the module generator before the file is written.
Project.GeneratePlcLibrary
If TRUE, a PLC library (*.library) is created in the repository folder for the project.
Project.InstallPlcLibrary
If TRUE, the created PLC library is installed on the local TwinCAT XAE.
Project.PreCodeGenerationCallbackFcn
Here, a function can be called as a string to be called before code generation, i.e., before the TwinCAT C++ project is created.
For example, an m-file MyCallback.m can be created in the workspace with the following content:
function MyCallback(obj)
…
return
The PreCodeGenerationCallbackFcn property is then set to “MyCallback”. By default, the ProjectExporter object is passed to the function, so that you have access to all data of the current project in the callback function.
Project.PostCodeGenerationCallbackFcn
Here, a function can be called as a string to be called after code generation, i.e., after the TwinCAT C++ project is created.
For example, an m-file MyCallback.m can be created in the workspace with the following content:
function MyCallback(obj)
…
return
The PostCodeGenerationCallbackFcn property is then set to “MyCallback”. By default, the ProjectExporter object is passed to the function, so that you have access to all data of the current project in the callback function.
Project.PostPublishCallbackFcn
Here, a function can be called as a string to be called after the compilation, i.e., after the TwinCAT objects are created.
For example, an m-file MyCallback.m can be created in the workspace with the following content:
function MyCallback(obj)
…
return
The PostPublishCallbackFcn property is then set to “MyCallback”. By default, the ProjectExporter object is passed to the function, so that you have access to all data of the current project in the callback function.
Project.OemId
and Project.OemLicenses
Optionally, a generated TcCOM or a function block can be linked to an OEM license. This OEM license is checked when starting the object (in addition to the Beckhoff runtime license TC1220 or TC1320) in TwinCAT 3. If no valid license is available, the module does not start up and an error message appears.
Instructions for creating and managing OEM certificates can be found under TwinCAT3 > TE1000 XAE > Technologies > Security Management.
You can insert your OEM License Check by naming your OEM ID and your license ID or multiple license IDs to be queried. You can find your OEM ID in the Security Management Console (Extended Info activated). The license ID can be viewed by double-clicking on the corresponding license entry in TwinCAT under System > License. Both IDs are also included in the generated License Request File when a Request File is generated with your OEM license.
Example entry:
exportConfig.Project.OemId = '{ABBAABBA-AFFE-AFFE-AFFE-ABBABBAABBAA}';
exportConfig.Project.OemLicenses = '{11111111-0000-FEFE-CCCC-BBBBBBBBBBBB}';
ClassExportCfg
Cell array of the added export configurations. Each export configuration, i.e. each converted MATLAB® function or each converted Simulink® model, can be configured individually.
TcCom.Generate
If TRUE, a TcCOM object is created that can be used in the TwinCAT XAE.
TcCom.FpExceptionsForInit
Options: CallerExceptions, ThrowExceptions, SuppressExceptions, LogExceptions, LogAndHold, LogAndCatch, LogAndDump, LogHoldAndDump, LogCatchAndDump
More in Exception handling.
TcCom.FpExceptionsForUpdate
Options: CallerExceptions, ThrowExceptions, SuppressExceptions, LogExceptions, LogAndHold, LogAndCatch, LogAndDump, LogHoldAndDump, LogCatchAndDump
More in Exception handling.
CallerExceptions: The settings of the caller are adopted, e.g. the task, another TcCOM, or the PLC.
TcCom.ExecutionInfoOutput
If TRUE, another output is created at the TcCOM with information in case of occurring exceptions. More in Exception handling.
TcCom.OnlineChange
If TRUE, the TcCOM can be replaced by Online Change while TwinCAT XAR is in Run mode. See also Online Change for Target for Simulink®.
TcCom.TcComWrapperFb
If TRUE, a TcCOM-Wrapper-FB is created in the generated PLC library.
TcCom.TcComWrapperFbProperties
If TRUE, properties for module parameters are created at TcCOM-Wrapper-FB.
TcCom.TcComWrapperFbPropertyMonitoring
Options: NoMonitoring, CyclicUpdate, ExecutionUpdate
Specifies the monitoring attribute of the properties. In the default case, “No Monitoring” is set, i.e. no attribute is set.
Setting in MATLAB | Attribute on property |
---|---|
ExecutionUpdate | {attribute 'monitoring' := 'variable'} |
CyclicUpdate | {attribute 'monitoring' := 'call'} |
PlcFb.Generate
If TRUE, a function block is created in the PLC library that can be used in the TwinCAT XAE.
PlcFb. FpExceptionsForInit
Floating Point Exceptions within the function block during the init stage can be set.
Options: CallerExceptions, ThrowExceptions, SuppressExceptions, LogExceptions, LogAndHold, LogAndCatch, LogAndDump, LogHoldAndDump, LogCatchAndDump
More in Exception handling.
PlcFb. FpExceptionsForUpdate
Floating Point Exceptions within the function block during the update stage can be set.
Options: CallerExceptions, ThrowExceptions, SuppressExceptions, LogExceptions, LogAndHold, LogAndCatch, LogAndDump, LogHoldAndDump, LogCatchAndDump
More in Exception handling.
Creating and loading an export configuration
When using the TwinCAT Target for MATLAB®, the MATLAB® Coder™ is first used to generate C++ sources. These C++ sources can then be combined into an export configuration in the TwinCAT module generator by:
TwinCAT.ModuleGenerator.Matlab.FunctionExportConfig('MFile',Name,'BuildDir',cppDir)
The path to the C++ sources created by the MATLAB® Coder™ is passed as properties with 'BuildDir'
and the name of the MATLAB® function is passed with 'MFile'
. If, for example, BaseStatistics is selected as the name, the TcCOM object will have this name and the function block in the PLC will be given the name FB_BaseStatistics.
If the TwinCAT Target for Simulink® is used, the approach is somewhat different. Start the build process from Simulink® with the "Run the publish step after project generation" option disabled. Then load the created <modelname>_tcgrt folder as follows in order to add the C++ sources of the Simulink® model to the project export configuration.
TwinCAT.ModuleGenerator.ProjectExportConfig.Load(<modelname>_tcgrt);
Creating TwinCAT objects with the Module Generator
TwinCAT.ModuleGenerator.ProjectExporter()
TwinCAT.ModuleGenerator.ProjectExporter()
triggers the build process for the platforms set in the Project
property. The object of the class TwinCAT.ModuleGenerator.ProjectExportConfig is passed as argument. This creates a folder on the local file system in the repository and stores the created drivers and description files.
Example call:
projExporter = TwinCAT.ModuleGenerator.ProjectExporter(exportConfig);