Blocks from Vehicle Network Toolbox (VNT) are not supported with External Mode of Simulink Desktop Real-Time (SLDRT) because they access drivers which are not available to the real-time kernel.
Depending on the CAN device being used, there are the following possible solutions:
1. Vector, Kvaser and PEAK-System CAN devices
SLDRT supports CAN devices by Vector (since R2009a), as well as Kvaser and PEAK-System (since R2019b) for External Mode. Check the following page to see if your CAN hardware is natively supported by SLDRT:
If your hardware is supported, upgrade your MATLAB release if necessary, and replace the CAN blocks from VNT by Packet Input / Output blocks from SLDRT. This should allow you to run your simulation in External Mode. Here is an example model:
2. Other CAN devices
It is not possible to use SLDRT in External Mode with other CAN devices. This is because In External Mode, the model, solver and drivers are converted to C code and run in a real-time kernel. In this mode, VNT drivers are not supported to be used with SLDRT. SLDRT requires specialized drivers that operate independently in real-time (these are not the sames as the standard USB drivers used by Windows / MacOS to talk to the device). SLDRT includes these specialized drivers only for the CAN boards mentioned at the top, but not for all CAN devices supported by VNT.
The only option for other CAN devices is to use the VNT blocks in Normal Mode or Accelerator Mode. In this mode, the simulation itself operates "normally" in Simulink and is using VNT to talk to the CAN device via the vendor device driver, but is not using a real-time driver. Although Normal Mode is not primarily meant to be used with non-real-time drivers from VNT, this does work and for certain models it can do exactly what the user needs. Of course, there are cases when it does not work, and it is up to the user to decide.
To learn more about the differences between Normal Mode and External Mode when using SLDRT, see the following MATLAB Answers post:
Best Answer