External mode (Tc External Mode)

Simulink offers various execution modes. In addition to "Normal mode", in which the Simulink model is calculated directly in the Simulink environment, an "External mode" is available. In this mode Simulink only acts as a graphical interface, without performing calculations in the background. Once the model with the corresponding settings has been converted into a TcCOM module, Simulink can link to the instantiated TcCOM object that is currently running in the TwinCAT real-time environment. In this case the internal module signals are transferred to Simulink via ADS, where they can be recorded or shown with the corresponding Simulink blocks. Parameters that were modified in Simulink can be written online into the TcCOM object. However, such an online parameter modification is only possible for parameters that are defined as "tunable".

Configuration of the module generator

An External Mode connection is only possible if the generated module supports it. To this end External Mode must be activated in the settings for the Simulink Coder under TC External Mode before the module is generated:

External mode (Tc External Mode) 1:

In addition, there is a button for preconfiguring the "External Mode" connection. For information on configuring the "External Mode" connection see section "Establishing a connection". Further parameters under this tab are:

Parameter

Description

Default value

Allow real-time execution commands via External Mode

Defines the default value of the module parameter "AllowExecutionCommands", which specifies whether the module should process start and stop commands from Simulink.

Special behavior of this parameter: The module parameter "AllowExecutionCommands" is ReadOnly, if the value is FALSE. In this case the code is optimized in terms of the execution time and therefore does not contain the code sections for processing start/stop commands.

FALSE

By default wait on External Mode start command

Default value of the module parameter "WaitForStartCommand"

FALSE

Module parameter

For configuring the behavior in external mode (on the XAE side) the parameter External Mode is defined as a structure in generated modules, which contains the following elements:

Parameter

Description

Default value

Activated

ReadOnly. Determines whether the generated module supports the external mode.

Setting the module generator

AllowExecutionCommands

Only relevant if "Activated"=TRUE.
ReadOnly if the default value is FALSE, since in this case the code sections are not included in the generated code. That is, this parameter can disable the processing of start and stop commands, but it cannot enable it, if it was not created during code generation.

Setting the module generator

TRUE

Enables Simulink to start and stop the module execution via the "External Mode" connection.

FALSE

Start and stop commands are ignored in the module.

WaitForStartCommand

Only relevant if "Activated" is TRUE and "AllowExecutionCommands" is TRUE

Setting the module generator

TRUE

When TwinCAT has started the module is not executed automatically but waits for the start command from Simulink.

FALSE

The module starts immediately with the assigned TwinCAT task. (default)


For further information on adapting the module parameters in XAE see section "Parameterization of the generated module".

Establish connection from Simulink®

The "External Mode" connection can be started from Simulink via the Connect to Target icon, which appears in the Simulink toolbar when External mode is selected:

External mode (Tc External Mode) 2:


If connection data are missing or incorrect, the following dialogs are displayed one after the other, so that the user can reconfigure the connection:

External mode (Tc External Mode) 3: External mode (Tc External Mode) 4:


The first dialog box shows a list of target systems, the second box shows a list of the available module instances on the selected target system. In the following dialog the user can specify whether the new connection data should be stored. Once the connection data have been stored, the connection is established automatically, if the connection data point to a valid and suitable module.
The stored connection data can be modified at any time in the coder settings via the button Setup ADS Connection under TC External Mode.

Transfer of the calculation results for "minor time steps"

Under certain circumstances, signal values transferred via ADS may differ from the values that were copied to other process images via "output mapping". See Transfer of the calculation results for "minor time steps".

Parameterization in TwinCAT

Large models necessitate communication of large data volumes between TwinCAT and Simulink. This takes place via ADS. On the TwinCAT side, buffers are created as part of the process. The buffers can be adapted for incoming and outgoing data (default: 10,000 bytes), and the timeout threshold can be adjusted (default: 3.0 seconds).

External mode (Tc External Mode) 5: