How to queue CAN messages for transmission?

1 visualización (últimos 30 días)
Chris Mounce
Chris Mounce el 11 de Mzo. de 2020
Comentada: Chris Mounce el 9 de Jun. de 2022
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 comentarios
Adrian Izbicki
Adrian Izbicki el 9 de Jun. de 2022
Did you find a solution for this?
Chris Mounce
Chris Mounce el 9 de Jun. de 2022
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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by