Settings of the TwinCAT module generator

The TwinCAT module generator is used to convert the C/C++ code generated by the MATLAB® Coder™ into TwinCAT objects. The configuration parameters can be used to influence the TwinCAT objects that are created. This main section provides an introduction to configuration with TwinCAT.ModuleGenerator.ProjectExportConfig and guides you to the more detailed subsections.

It is important to understand the distinction between the project level and the functional level:

ProjectExportConfig contains an array of entries called ClassExportCfg, each of which refers to a FunctionExportConfig. This allows multiple MATLAB® functions to be grouped into a single ProjectExportConfig and managed together.

Adds a project export configuration

You can access the configuration through an object of the TwinCAT.ModuleGenerator.ProjectExportConfig class. This object serves as the project framework and collects the individual FunctionExportConfig entries for the MATLAB® functions to be exported in its ClassExportCfg property.

exportCfg = 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.

Example 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.

For an example call, see Module generator quick start.

 

Save

 

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:

exportCfg.Save(pwd)

This saves the project export configuration in the current path.

 

Load

 

This loads a saved project export configuration. The transfer argument specifies the path of the mat file containing the saved configuration.

Example call:

exportCfg.Load(pwd)

Loads the project export configuration from the current path.

Edit

 

Opens a graphical configuration interface for setting up the project export configuration.

 

disp

 

Gives an overview of the current project export configuration in the MATLAB® Command Window. See Module generator quick start.

Example call:

exportCfg.disp or disp(exportCfg)

 

Settings of the TwinCAT module generator 1:

Properties of the class TwinCAT.ModuleGenerator.ProjectExportConfig

The properties are summarized in the overview table of all configuration parameters.

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(exportCfg);