Can I use CAN Unpack without the CAN receive block?

6 views (last 30 days)
I have a complex Simulink model that provides a custom GUI for our instrument, running on Speedgoat, with the resulting messages being sent over CAN bus to our HW.
I'd now like to modify the model to send the messages out via UDP as well as the CAN bus. I've connected the output of our logic which generates the correct CAN message to the CAN unpack block just prior to the CAN write block. I've set the CAN unpack block data output format to be raw data and selected the following tick boxes under output ports, output identifier and output length.
I was expecting the resulting data, ID and length to then reflect the CAN message, allowing me to pack these into a UDP frame.
What I'm seeing is that although the CAN messages come out correctly on the physical CAN bus, the outputs of the CAN unpack block are all 0, they don't reflect the CAN message that is connected to the input.
I understand that the unpack block is usually for use with a CAN receive block, but are there any restrictions preventing it from doing what I'd like?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 29 Jan 2019
As you have noted, the approach you described for CAN Pack and CAN Unpack is not directly supported (For CAN Unpack to unpack a message with any ID, or for CAN Pack to take ID and length as inputs).
Some other alternatives to consider:
  • Since R2017b, there is an option to use CAN Pack with a Simulink bus object data type output (using Output as bus option), which might allow you to get to the raw data directly without using CAN Unpack.
  • Depending on whether you expect a finite set of CAN message ID values to be used, you might be able to implement some logic in Simulink which uses the current implementation (16a or later) of CAN Pack and CAN Unpack to achieve what you need.
  • You might be able to create custom blocks (a custom S-function) that does the pack and unpack operations. For 16a using CAN_MESSAGE bus datatype (see <https://www.mathworks.com/help/releases/R2016a/vnt/ug/building-custom-blocks.html https://www.mathworks.com/help/releases/R2016a/vnt/ug/building-custom-blocks.html >) or using the CAN_MESSAGE_BUS datatype in 17b or later.

More Answers (0)

Tags

No tags entered yet.

Products


Release

R2016a

Community Treasure Hunt

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

Start Hunting!