필터 지우기
필터 지우기

Send CAN messages from MATLAB to ECU with PEAK device

조회 수: 16 (최근 30일)
Óscar Poveda
Óscar Poveda 2021년 4월 12일
답변: Alexey Molchanov 2022년 2월 9일
Hi!
I am trying to send CAN messages from MATLAB to my connected ECU. I have a PCAN-USB FD (https://www.peak-system.com/PCAN-USB-FD.365.0.html?&L=1), so I start the channel (the third library is installed). Then, I open the database that contain the two message variables. Then, I transmit periodically the messages to this channel. (The code that I am running is below)
The problem is that when the data is transmited, the PEAK device is receiving these messages, but it does not transmit the messages to the CAN bus, for the ECU to receive them.
I don't know if I am doing something wrong, or if there is other way to communicate with my ECU using MATLAB and a PCAN-USB FD.
If someone know something about, it could be so helpful for me.
Thanks in advance.
Óscar.
%CAN TRANSMITED DATA TO THE USB
txCh = canChannel('PEAK-System', 'PCAN_USBBUS1'); % Construct CAN channel connected to specified device
start(txCh);
%%
db = canDatabase('file.dbc'); % Open the database and attach it to the CAN channels
txCh.Database=db;
msg1 = canMessage(db,'ECU_1'); % Definir el mensaje a extraer de .dbc
msg2 = canMessage(db,'ECU_2');
transmitPeriodic(txCh,msg1,'On',0.05); % Transmitir el mensaje a determinada frecuencia
transmitPeriodic(txCh,msg2,'On',0.05);
%%
msg1.Data= data_calculation(50);
msg2.Data = msg1.Data;

답변 (1개)

Alexey Molchanov
Alexey Molchanov 2022년 2월 9일
You need to set up correct speed for CAN interface before use it.

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by