Transmit Data on CAN

14 ビュー (過去 30 日間)
Shubham Salvi
Shubham Salvi 2022 年 4 月 6 日
回答済み: Pratyush 2023 年 12 月 19 日
I have raw CAN Data on workspace and I wish to transmit it from Mathwork Virtual CAN bus to Kvaser virtual and observe the output in CAN Explorer.

回答 (1 件)

Pratyush
Pratyush 2023 年 12 月 19 日
Hi Shibham,
I understand that you want to transmit raw CAN data from the MathWorks virtual CAN bus to a Kvaser virtual CAN bus and observe the output in CAN Explorer.
Here's a general outline of the process:
  • Ensure you have the Vehicle Network Toolbox installed in MATLAB, which allows you to use CAN communication.
  • Create a virtual CAN channel in MATLAB that corresponds to the MathWorks virtual CAN bus.
% Open MATLAB and type the following commands:
canCh = canChannel('MathWorks', 'Virtual 1', 'BusSpeed', 500000);
start(canCh);
  • Create CAN message(s) with the raw data you want to transmit.
% Create a CAN message with standard ID 100 and two bytes of data
msg = canMessage(100, false, 2);
msg.Data = [0x12, 0x34];
% Transmit the message
transmit(canCh, msg);
  • Install the Kvaser drivers and make sure the Kvaser virtual CAN bus is properly configured on your system. You may need to use the Kvaser Hardware Setup tool to create a virtual CAN channel.
  • You might need to change the channel in MATLAB to match the Kvaser virtual CAN channel. If Kvaser's virtual channel appears as a device in MATLAB, you can directly use it:
% Assuming the Kvaser virtual CAN channel is visible to MATLAB
canCh = canChannel('Kvaser', 'YourVirtualChannelName', 'BusSpeed', 500000);
start(canCh);
  • Open CAN Explorer and connect it to the Kvaser virtual CAN bus. Configure the CAN Explorer to listen to the correct CAN bus speed and channel. Once connected, you should be able to see the messages transmitted from MATLAB.
Hope this helps.

Community Treasure Hunt

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

Start Hunting!

Translated by