- 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?
28 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
prabhat kumar sharma
el 24 de En. de 2024
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 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!