How to queue CAN messages for transmission?

3 次查看(过去 30 天)
Hello,
I have a number of CAN messages that I'm looking to add to a queue for transmission. When trying to do this with either of the two queue blocks, I get errors about either the output of the queue not being compatible with the transmit block, or (with the other queue block option) the CAN message being the wrong data type, since it's a CAN message and not a basic datatype. It seems like setting up a CAN message FIFO in Simulink should be fairly straightforward, what am I missing? Thanks!
  2 个评论
Chris Mounce
Chris Mounce 2022-6-9
I eventually used an S function with a third party CAN solution that was able to queue up the messages.
However, there is a solution with newer versions of MATLAB that allow for data store indexing. As you can use an indexed data store as a rotating buffer.
It involves 5 steps:
  1. Create a ReadIndex datastore starting at value 1
  2. Create a WriteIndex datastore starting at value 1
  3. Create a MessageBuffer datastore of whatever size you want
  4. Write a message to MessageBuffer at index WriteIndex and then increment WriteIndex. If greater than the size of your MessageBuffer, wrap to 1
  5. Whenever WriteIndex != ReadIndex, read the data in MessageBuffer at index ReadIndex and then increment ReadIndex. If greater than the size of your MessageBuffer, wrap to 1.
Keep in mind that if these writes or reads are called via an interrupt, you could have problems with data integrity.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by