# Tool Support

# Overview

<span lang="EN-US">The CGI Connector offers support for multiple ‘tools’ for which it can generate specific code to make integration easier.</span>

<span lang="EN-US">Currently the following tools are supported:</span>

<table border="1" id="bkmrk-property-name-descri" style="border-collapse: collapse; width: 97.5309%; height: 76.7657px;"><colgroup><col style="width: 16.3511%;"></col><col style="width: 83.6489%;"></col></colgroup><tbody><tr style="height: 29.7969px;"><td class="align-center" style="background-color: rgb(230, 126, 35); height: 29.7969px;"><span style="color: rgb(255, 255, 255);">**Name**</span></td><td class="align-center" style="background-color: rgb(230, 126, 35); height: 29.7969px;"><span style="color: rgb(255, 255, 255);">**Description**</span></td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">**Generic**</td><td style="height: 29.7969px;">Standard generic C/C++ interface for integration into other C/C++ based software.</td></tr><tr style="height: 17.1719px;"><td style="height: 17.1719px;">**MATLAB**</td><td style="height: 17.1719px;">Integration for MathWorks MATLAB

</td></tr></tbody></table>

---

# Generic

The ‘Generic’ tool provides a plain C/C++ based interface which can be used to integrate the CGI application into any C/C++ based software.

This generic interface is also the basis for the integration of other tools and will therefore always be present.

#### Special Features  


There are no tool specific features.

#### Limitations  


There are no limitations when using the ‘Generic’ tool.

#### Generators  


This tool does not use any special code generator tools.

---

# MATLAB

The ‘MATLAB’ tool offers special features to make integration into MathWorks MATLAB easier.

#### Requirements

The following requirements must be fulfilled to be able to use the CGI Connector with MATLAB:

**MATLAB Version:** The current version is tested to run with MATLAB 2021b. However newer versions are also expected to be compatible.

**MEX Compiler:** It is necessary to configure the compiler that is used by MATLAB to build a MEX File. This can be achieved by calling “mex -setup" and “mex -setup c++” from within MATLAB. The configured compiler must match with the compiler used to build the CGI Studio application.

The “mex” command must also be executable from the command line. This can be done by adding the correct path in the systems environment variables. Alternatively, the build scripts can be modified to point directly to the mex executable.

#### Special Features

Interfaces defined in a MATLAB module have the following tool specific properties.

<div drawio-diagram="8519"><img src="https://doc316en.candera.eu/uploads/images/drawio/2025-08/drawing-7-1754986857.png" alt=""/></div>

<table border="1" id="bkmrk-property-name-descri" style="border-collapse: collapse; width: 97.5309%; height: 219.953px;"><colgroup><col style="width: 16.3511%;"></col><col style="width: 83.6489%;"></col></colgroup><tbody><tr style="height: 16.7969px;"><td class="align-center" style="background-color: rgb(230, 126, 35); height: 16.7969px;"><span style="color: rgb(255, 255, 255);">**Property Name**</span></td><td class="align-center" style="background-color: rgb(230, 126, 35); height: 16.7969px;"><span style="color: rgb(255, 255, 255);">**Description**</span></td></tr><tr style="height: 46.5938px;"><td style="height: 46.5938px;">**Port**</td><td style="height: 46.5938px;"><span lang="EN-US" style="font-size: 10.0pt; mso-bidi-font-size: 11.0pt; line-height: 107%; font-family: 'Daytona',sans-serif; mso-fareast-font-family: 游明朝; mso-fareast-theme-font: minor-fareast; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA;">Defines the port index of the interface for the generated MATLAB S-Function block.  
When specifying ‘-1’ the port index will be calculated automatically during code generation.</span></td></tr><tr><td>**Port Width**</td><td><span lang="EN-US" style="font-size: 10.0pt; mso-bidi-font-size: 11.0pt; line-height: 107%; font-family: 'Daytona',sans-serif; mso-fareast-font-family: 游明朝; mso-fareast-theme-font: minor-fareast; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA;">Specifies the MATLAB port width. This option is only visible if the interface uses a dynamic length datatype. </span></td></tr></tbody></table>

#### Limitations

Currently the following limitation apply:

- Interfaces that use dynamic sized data need to specify a fixed sized for MATLAB side. See <span style="color: rgb(230, 126, 35);">[“Special Features”](https://doc316en.candera.eu/link/1236#bkmrk-special-features)</span> for more details.

#### Generators

This tool is located at “cgi\_studio\_connector/bin/MatlabCodeGenerator.exe” and generates files to be used in MathWorks MATLAB.

It has the following arguments:

<table border="1" id="bkmrk-full-name-short-name" style="border-collapse: collapse; width: 97.5309%; height: 51.3907px;"><colgroup><col style="width: 16.3498%;"></col><col style="width: 13.0545%;"></col><col style="width: 11.2831%;"></col><col style="width: 59.3125%;"></col></colgroup><tbody><tr style="height: 29.7969px;"><td class="align-center" style="background-color: rgb(230, 126, 35); height: 29.7969px;"><span style="color: rgb(255, 255, 255);">**Full Name**</span></td><td class="align-center" style="background-color: rgb(230, 126, 35); height: 29.7969px;"><span style="color: rgb(255, 255, 255);">**Short Name**</span></td><td class="align-center" style="background-color: rgb(230, 126, 35); height: 29.7969px;"><span style="color: rgb(255, 255, 255);">**Optional**</span></td><td class="align-center" style="background-color: rgb(230, 126, 35); height: 29.7969px;"><span style="color: rgb(255, 255, 255);">**Description**</span></td></tr><tr style="height: 21.5938px;"><td style="height: 21.5938px;">**-definitionFile**</td><td style="height: 21.5938px;"><span lang="EN-US" style="font-size: 10.0pt; mso-bidi-font-size: 11.0pt; line-height: 107%; font-family: 'Daytona',sans-serif; mso-fareast-font-family: 游明朝; mso-fareast-theme-font: minor-fareast; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA;">-d</span></td><td style="height: 21.5938px;"><span lang="EN-US" style="font-size: 10.0pt; mso-bidi-font-size: 11.0pt; line-height: 107%; font-family: 'Daytona',sans-serif; mso-fareast-font-family: 游明朝; mso-fareast-theme-font: minor-fareast; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA;">No</span></td><td style="height: 21.5938px;">File containing interface definition</td></tr><tr><td>**-complexTypes**</td><td><span lang="EN-US" style="font-size: 10.0pt; mso-bidi-font-size: 11.0pt; line-height: 107%; font-family: 'Daytona',sans-serif; mso-fareast-font-family: 游明朝; mso-fareast-theme-font: minor-fareast; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA;">-ct</span></td><td><span lang="EN-US" style="font-size: 10.0pt; mso-bidi-font-size: 11.0pt; line-height: 107%; font-family: 'Daytona',sans-serif; mso-fareast-font-family: 游明朝; mso-fareast-theme-font: minor-fareast; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA;">Yes</span></td><td>Path of Complex-Type definition file</td></tr><tr><td>**-outputPath**</td><td><span lang="EN-US" style="font-size: 10.0pt; mso-bidi-font-size: 11.0pt; line-height: 107%; font-family: 'Daytona',sans-serif; mso-fareast-font-family: 游明朝; mso-fareast-theme-font: minor-fareast; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA;">-o</span></td><td><span lang="EN-US" style="font-size: 10.0pt; mso-bidi-font-size: 11.0pt; line-height: 107%; font-family: 'Daytona',sans-serif; mso-fareast-font-family: 游明朝; mso-fareast-theme-font: minor-fareast; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: JA; mso-bidi-language: AR-SA;">Yes</span></td><td>Path for generated output files</td></tr></tbody></table>

#### Usage

<span lang="EN-US">To use the MATLAB integration the following steps are required.</span>

1. <span lang="EN-US">**Build CGI Application**  
    As the integration into MATLAB simulation uses TCP/IP to send data between MATLAB and the CGI Application, this feature needs to be enabled. To do this the ‘APPLICATION\_IPC\_ENABLED’ and ‘APPLICATION\_IPC\_INTERFACE\_ENABLED’ CMake flags must be set. This is already done when building the application using the default builds from within the Connector.  
      
    When running the generated MATLAB code after integration into the application code the IPC communication is however not required anymore.  
      
    </span>
2. **<span lang="EN-US">Build Integration Modules</span>**<span lang="EN-US">  
    </span>After the application is built, the ‘MATLAB Integration’ can be built. The integration must be built matching the Release/Debug configuration of the CGI Application.
    
      
    If the MATLAB application is already opened and the Model has been started before, it is required to unload the S-Function from MATLAB before building a new version. This can be done by running ‘clear mex’ command in MATLAB.
    
      
    <div drawio-diagram="8320"><img src="https://doc316en.candera.eu/uploads/images/drawio/2025-04/drawing-7-1744616582.png" alt=""/></div>
3. **Startup MATLAB model** After the build is finished, the MATLAB application can be opened. The default template includes all related MATLAB component in the ‘src\\Matlab’ folder.  
    <div drawio-diagram="8329"><img src="https://doc316en.candera.eu/uploads/images/drawio/2025-04/drawing-7-1744870709.png" alt=""/></div>
    
    The ‘CgiStudio\_Startup.m’ script needs to be run in MATLAB to include the ‘CgiStudio’ code folder and files.
    
    <div drawio-diagram="7231"><img src="https://doc316en.candera.eu/uploads/images/drawio/2024-10/drawing-7-1730343288.png" alt=""/></div>
    
    If already run before, it is sufficient to only run the ‘CgiStudio/Synchronize.m’ script.
4. **Add CGI Studio block**  
    The integration provides a ‘CGI Studio’ library which contains the ‘CGI Studio Integration’ block.   
    <div drawio-diagram="7232"><img src="https://doc316en.candera.eu/uploads/images/drawio/2024-10/drawing-7-1730343343.png" alt=""/></div>
    
    This block can be added to the Model to represent a Module defined with the CGI Connector. The provided ‘ControllerModule’ model already contains one such block per default.
5. **Configure Module**  
    After a ‘CGI Studio Integration’ block has been added, it can be configured by double clicking it. This will open a dialog which allows the user to select the module this block should represent. Additionally, the Sample Time for the block can be configured.  
    <div drawio-diagram="8321"><img src="https://doc316en.candera.eu/uploads/images/drawio/2025-04/drawing-7-1744616640.png" alt=""/></div>
    
    After the module has been selected, the block will show all configured input- and output interfaces as ports.
    
    <div drawio-diagram="7234"><img src="https://doc316en.candera.eu/uploads/images/drawio/2024-10/drawing-7-1730343417.png" alt=""/></div>
    
    <p class="callout info">It might be required to update the model (CTRL + D) to show the ports.  
    </p>
6. **Running the Simulation**  
    When running the simulation, the CGI Application must be started beforehand. Similar after stopping the simulation the CGI Application should be closed afterwards.

#### Additional Information

**<span lang="EN-US">Actions/Events: </span>**<span lang="EN-US">Actions are triggered by any flank change. If an action has additional data an additional port with the suffix ‘\_Data’ is generated. The same applies also to events.</span>

<span lang="EN-US">**Module Changes:** If a module can’t be found in the generated code, the block will indicate this by adding ‘\[Not found\]’ to the Module name. If the containing MATLAB model is opened newly no ports will be generated and connected signals will be disconnected. If the model has already been opened before, the latest generated ports will be kept (until it is reopened). Therefore, if the name of a module is changed, it is recommended to open the MATLAB model before generating the new integration code. Doing so will keep all signals connected.</span>

<span lang="EN-US">**S-Function:** It is possible to directly use the generated S-Function without making use of the CGI Studio block, by using a standard S-Function block.</span>

<div drawio-diagram="8520"><img src="https://doc316en.candera.eu/uploads/images/drawio/2025-08/drawing-7-1754987003.png" alt=""/></div>

The name of the S-Function is “CgiStudioIntegration”, and the first parameter indicates the MATLAB-Id of the module the block should represent. This Id can be found in the Interface-Definition XML file or the generated MATLAB code (e.g. in ‘\[PROJECT\]srcMatlab\\CgiStudio\\Modules.xml’ called MID). The second parameter refers to the sample time of the S-Function.

In this case no named ports will be generated for the module.

---