Why am I unable to use CAN blocks from Vehicle Network Toolbox in External Mode of Simulink Desktop Real-Time?

5 views (last 30 days)
I have a model that contains CAN Transmit/Receive blocks from Vehicle Network Toolbox. If I want to run the model in External Mode using Simulink Desktop Real-Time, I get the following error message:
Attempt to include "windows.h"The model being compiled contains a block that can run on host only and cannot be compiled forExternal Mode. Please either switch to Normal Mode or remove the block.### Build procedure for model: '<modelname>' aborted due to an error
Why am I unable to use CAN blocks from Vehicle Network Toolbox in External Mode of Simulink Desktop Real-Time?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 24 May 2022
Edited: MathWorks Support Team on 24 May 2022
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:
https://www.mathworks.com/hardware-support/simulink-desktop-real-time.html
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:
 

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!