- Use a "CAN Pack block" and connect the "CAN_MESSAGE_BUS" to the input.
- Configure the "CAN Pack" block with the correct message ID and data length.
- The output of the "CAN Pack" block will be a CAN_MESSAGE that you can then send using the "CAN Transmit" block.
How do I convert from CAN_MESSAGE_BUS to CAN_MESSAGE?
20 ビュー (過去 30 日間)
古いコメントを表示
I'm trying to create a simple program for embedded coder TI C2000 that receives a CAN message via interrupt, places the message in a FIFO queue, and re-transmits the message from a program loop. I'm able to accomplish this until I need to try and transmit the message.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/894805/image.png)
I'm able to make this work on the receive side, but it's a mess using the CAN Unpack block to output all of the data types of the CAN message and rebuilding the bus object to send to the queue.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/894810/image.png)
The transmit side doesn't work because I can't figure out how to construct a CAN_MESSAGE from a CAN_MESSAGE_BUS. Sending only the data doesn't work since I need to dynamically assign the message ID.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/894815/image.png)
The fundamental problem is that I don't understand what a CAN_MESSAGE type is or how to work with it. It seems to behave as if it were a primitive type because bus operations do not work, but I'm not able to work with it unless I use CAN Pack or CAN Unpack blocks. I'd much prefer to just use the CAN_MESSAGE_BUS type which contains all of the needed information, but the eCAN Transmit/Receive blocks don't allow it.
0 件のコメント
回答 (1 件)
prabhat kumar sharma
2024 年 1 月 24 日
Hi Jonathan ,
In Simulink, the CAN Pack and CAN Unpack blocks are used to convert between the CAN_MESSAGE data type and a Simulink bus object (CAN_MESSAGE_BUS). However, the "CAN" blocks for transmit and receive directly work with the CAN_MESSAGE data type.
Transmitting ‘CAN’ Messages: If you have the ‘CAN_MESSAGE_BUS’, use the CAN Pack block to convert it back to a CAN_MESSAGE object. Use the CAN Transmit block to send the ‘CAN_MESSAGE’ object.
To construct a CAN_MESSAGE from a CAN_MESSAGE_BUS for transmission, you would typically do the following:
For more details on vehicle network toolbox functions you can refer this link:
Standard Flow Chart for Setting Up the Simulink Mode:
Receive Path: CAN Receive block ---> CAN Unpack block ---> FIFO Queue (implemented in State flow or MATLAB Function block)
Transmit Path: FIFO Queue ---> CAN Pack block ---> CAN Transmit block
I hope it helps!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Simulink Supported Hardware についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!