Converting a simulink bus to bytes and back
조회 수: 10 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulink Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!