Main Content

CAN Input/Output

This example shows how to transfer data through CAN bus. The model sends data within one computer, from one CAN channel to another. The two CAN channels can be either virtual channels or physical channels on a dual-channel CAN device. Two different CAN messages using different message identifiers are being transmitted. You can modify the model to communicate between two computers by splitting this model into its send and receive parts and running the models on two computers. The yellow blocks are used to send the data, the blue blocks are used to receive the data.

Note:This model runs on Microsoft Windows only.

Run Model in Connected IO Mode

  1. To switch toConnected IOmode if needed, on the桌面实时tab, selectMode>Connected IO.

  2. To start the real-time execution, on theSimulationtab, clickRun.

Run Model in Run in Kernel Mode

  1. To switch toRun in Kernelmode if needed, on the桌面实时tab, selectMode>Run in Kernel.

  2. To start the real-time execution, clickRun in Real Time.

The model builds, connects to Simulink inRun in Kernelmode, and starts.

Open the Model

These commands open the model and suppress warning about board not installed.

w = warning('off','sldrt:blkgui:boardnotonlist'); open_system(fullfile(matlabroot,'toolbox','sldrt','sldrtexamples','sldrtex_canio')); warning(w);

Close Open Scopes

close_system(find_system(gcs ,'BlockType',“范围”));

Clean Up Model

clear closeallbdcloseall

See Also