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
AddClassExportConfig
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.
Sample call see Modul-Generator-Quickstart.
Save
Creates a mat file and stores the project export configuration in it. Transfer argument is a path where the mat file is to be stored.
Sample call:
exportConfig.Save(pwd)
Saves the project export configuration in the current path.
Load
Loads a saved project export configuration. The transfer argument is the path where the mat file with the saved configuration is located.
Sample call:
exportConfig.Load(pwd)
Loads the project export configuration from the current path.
Edit
Opens a graphical configuration interface for configuring the project export configuration.
disp
Gives an overview in the MATLAB® Command Window of the current project export configuration. See Quick start.
Sample call:
exportConfig.disp
alternatively disp(exportConfig)
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 in the path of the repository and is visible in the structure when the PLC library and the TcCOM object are inserted.
Project.IncrementVersion
Possible values: "None", "Revision", "Build", "Minor", Major"
Default: "Revision
This setting influences at which of the four digits the version should be incremented. The basis is the last version available on the engineering system (see DrvFileVersion
).
Project.DrvFileVersion
Default: searches for the last version on the engineering system. If no existing version is found, it is started with 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
Configures the Visual Studio version to use. This can be specified precisely or set to Auto (default).
Project.PublishTcRTx86
If TRUE, then XAR is built on a Windows 32-bit platform.
Project.PublishTcRTx64
If TRUE, then XAR is built on a Windows 64-bit platform.
Project.PublishTcOSx64
If TRUE, then 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 Setting up driver signing.
Project.TmxArchive
Enter a path and file name here as a string in order to create a Creating TMX archives. 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, then 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
A function can be called here as a string, which is called before the code generation, i.e. the creation of the TwinCAT C++ project.
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 Settings of the TwinCAT module generator is passed to the function, so that you have access to all data of the current project in the callback function.
Project.PostCodeGenerationCallbackFcn
A function can be called here as a string, which is called after code generation, i.e. creation of the TwinCAT C++ project.
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 Settings of the TwinCAT module generator is passed to the function, so that you have access to all data of the current project in the callback function.
Project.PostPublishCallbackFcn
A function can be called here as a string that is called after the compilation, i.e. creation of the TwinCAT objects.
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 Settings of the TwinCAT module generator 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 (besides 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.
How to create and manage 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.
Sample 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, which 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, then 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 is created in the generated PLC library.
TcCom.TcComWrapperFbProperties
If TRUE, properties for module parameters are created at .
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, which can be used in the TwinCAT XAE.
PlcFb. FpExceptionsForInit
Floating Point Exceptions within the function block during the init phase 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 phase 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.
Sample call:
projExporter = TwinCAT.ModuleGenerator.ProjectExporter(exportConfig);