Converting a simulink bus to bytes and back

5 visualizaciones (últimos 30 días)
Nathan Zimmerman
Nathan Zimmerman el 9 de Ag. de 2017
Hello, I am attempting to C++ code-gen a matlab function block that converts a non-virtual bus to a byte array for storage in the OS. I also need to then convert this byte array back into a struct/bus. In C, this is easy to do with a struct and a union but i'd be nice to have a matlab solution that works for any bus else I mine as well just use C for everything.
I can convert the bus to bytes by using:
1. Getting and iterating through the fieldnames
2. Flattening the resulting data then typecasting to unit8
3. Concatenating this data to a variable sized byte array.
4. Write the byte array to the OS.
For converting bytes to bus I can:
1. Pull the byte array from the OS.
1. Get fieldnames for all the elements of the bus object
2. Determine the shape and byte size of a given bus entry
3. Pull the number of byte elements out of the buffer, cast it to the data type of the bus entry, then reshape it to be the same size as the bus.
While this process has worked for some buses I get random code gen errors depending upon the bus. Is there a better way to do this? Again keep in mind, it must code gen.

Respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by