To facilitate code prototyping and model simulation without hardware, Vehicle Network Toolbox™ provides a MathWorks® virtual CAN device with two channels. These channels are identified with the
"MathWorks" and the device
"Virtual 1", and are
accessible in both MATLAB® and Simulink®.
These virtual channels support CAN, CAN FD, and J1939 communication on Windows®, and support CAN and CAN FD on Linux®. Many examples throughout the documentation show how to use these virtual channels, so that you can run them on your own system.
The two virtual channels belong to a common device, so you could send a message on channel 1 and have that message received on channel 1 and channel 2. But because the virtual device is an application-level representation of a CAN/CAN FD bus without an actual bus, the following limitations apply:
The virtual interface does not perform low level protocol activity like arbitration, error frames, acknowledgment, and so on.
Although you can connect multiple channels of the same virtual device in the same MATLAB session or in Simulink models running in that MATLAB session, you cannot use virtual channels to communicate between different MATLAB sessions.
You can view the device and channels in MATLAB with the
ans = 2×6 table Vendor Device Channel DeviceModel ProtocolMode SerialNumber ___________ ___________ _______ ___________ _____________ ____________ "MathWorks" "Virtual 1" 1 "Virtual" "CAN, CAN FD" "0" "MathWorks" "Virtual 1" 2 "Virtual" "CAN, CAN FD" "0"
Create a virtual CAN channel.
canch = canChannel("MathWorks","Virtual 1",1);
Create a virtual CAN FD channel.
canfdch = canFDChannel("MathWorks","Virtual 1",2);
Create a virtual J1939 channel.
db = canDatabase([(matlabroot) '/examples/vnt/data/J1939.dbc']); jch = j1939Channel(db,"MathWorks","Virtual 1",1);