Hellow.
I have a question about how to union in simulink in simulink coder.
I know how to create the bus of struct using the 'Simulink bus' in dictionary file. (*.sldd)
However, i can't see the part that creates the union.
Does Mathoworks support the method of generating code an union as shown below?
If so, could you tell me how?
thank you
**************************************************************************************
typedef union
{
uint32 R;
uint16 H;
} Test_u;
**************************************************************************************

 Akzeptierte Antwort

Angelo Yeo
Angelo Yeo am 8 Mai 2024

0 Stimmen

Hi @WJKIM,
Current Simulink bus does not support union. Could we get a clearer understanding of why you want to realize the Simulink.Bus object as a union in the generated code? Is there any particular use case for this request?

2 Kommentare

WJKIM
WJKIM am 10 Mai 2024
Hi.
I respond to that.
If there are many flags (for example, Fault Flags), i can save memory space by using union.
This is only my opinion.
rikro
rikro am 13 Feb. 2025
I am looking for the same purpose for fault flags . Is there a way we can use Union ?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Anurag Ojha
Anurag Ojha am 8 Mai 2024

1 Stimme

Hello
You can refer to following file exchange link to get more information:
I hope this helps you resolve your query

4 Kommentare

WJKIM
WJKIM am 10 Mai 2024
Thank you for feedback.
I will try it
WJKIM
WJKIM am 13 Mai 2024
Hello,
I have a question about your link.
I found the 'TempBus' in *.m file. And its configuration of code generation is as follow:
Data scope : Imported
Header file : DataTypeImport.h
However, i don't find the DataTypeImport.h file.
Could you tell me where it is? How can i get that?
Meghna
Meghna am 16 Jul. 2024
Hello,
Following up on this as well, how is the header supposed to look/are there any examples?
Thanks!
安晏
安晏 am 9 Mär. 2026
Hello,
I have try this way: I defined union type in my *.h file, and union name is xx_TypeDef. And I Create Bus, Which DataScope is 'Imported', and special *.h file. Then, I Create Simulink.Signal with data Type is The Bus. After Code Generation, I found The union object generated. But!!! union object init is illegal, which init both member in union object. This mean, simulink coder always treat bus object as c-struct.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Deployment, Integration, and Supported Hardware finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 8 Mai 2024

Kommentiert:

am 9 Mär. 2026

Community Treasure Hunt

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

Start Hunting!

Translated by