Connecting to External mode

You can connect from your Simulink® environment to a running TcCOM object or an instance of the PLC function block in the TwinCAT XAR via External mode.

Connecting to External mode 1:

Restriction on code interface packaging

The code interface packaging defines the behavior for multiple instances of a created class in TwinCAT. If the External mode is to be used, the setting C++ Class is not allowed.

Connecting to External mode 2:

Simulation time in Simulink® set to "inf"

Set the Simulink® simulation time to "inf". For operation in TwinCAT, it makes no sense to stop the execution of the module after a defined time.

Code generation settings in Simulink®
1. Under Code Generation > Interface, set the External mode parameter.

Connecting to External mode 3:

2. Define the permissions of the External mode (separately adjustable for TcCOM and PlcFb).
Shown in the following screenshot as an example for TcCOM.
Connecting to External mode 4:
Connect to a runtime object with the External mode
3. Open the External mode control panel.
4. Select Connect.
Connecting to External mode 5:
5. Select the connected target and object instance.
Connecting to External mode 6:
After selecting OK, you will be connected to the object. The Connect button on the External mode control panel has changed to Disconnect and you can see the simulation time transferred from the target in Simulink®.

As can be seen in the above graphic for selecting the object in a target, the External mode is available for TcCOM instances as well as for PLC-FB instances.

Connecting to External mode 7:

Bidirectional ADS route required

For the External mode, a bidirectional ADS route is necessary. Unidirectional routes cause a timeout in communication.