How can I import structures from C and use them as bus elements in a .sldd dictionnary?

13 次查看(过去 30 天)
Hi,
I would like to import structures from a C header and then export them in a .sldd dictionnary linked to a static library, and use them as bus elements in custom busses used in the library.
I have used Simulink.importExternalCTypes to import the structures into my workspace without issue. I then opened my dictionnary through Simulink.data.dictionary.open and exported my structures into the dictionnary with importFromBaseWorkspace before closing the dictionnary with Simulink.data.dictionary.close, and everything went fine. I can see my structures imported as busses in the dictionnary, I can use them and use my custom busses in my library.
However, once I tried to add my imported structure as a bus element to a custom bus in my dictionnary, I had a lot of compilation errors which I do not understand. Moreover, the bus editor won't let me save my dictionnary when I try to remove the bus element which causes the issue, which means the bus element comes back when I refresh the editor.
Please find below a screenshot of the compilation errors
Is there a way to export those structures and use them as bus editors? If not, what alternatives do I have to get a similar result? I would like for it all to be static and usable directly in a static library, without having to import all of it in my workspace everytime I want to work on my library
Thank you in advance.

采纳的回答

Suman Sahu
Suman Sahu 2023-8-24
Hi François,
You want to import structures from a C header file and then export them to a SLDD dictionary. Instead of first importing the structures from C header file into the workspace and then exporting it to a SLDD dictionary, you can try to directly import the structures as a “Simulink.Bus” type into a SLDD dictionary. Here is an example code for how you can achieve that:
Consider an example C header file named “struct.h” containing the following struct:
typedef struct {
double coeff;
double init;
} params_T;
Simulink.importExternalCTypes(struct.h, DataDictionary, dict_name.sldd, OutputDir, dir_for_sldd_file);
This will directly export the struct from C header into the specified SLDD dictionary inside the specified directory.
You can refer to the following documentations to learn more about “Simulink.importExternalCTypes” function and adding bus elements to bus objects:
  1 个评论
François Lemire
François Lemire 2023-9-1
Hi,
Thank you very much for the answer. It didn't solve the issue on its own, but at least it made the importation of the structs and enums way easier and cleaner.
However, I found a solution to my problem. It came from the fact that I was using the enums inside of a stateflow, and the Action Language of the stateflow was set to Matlab instead of C. I changed it and it solved the issue.

请先登录,再进行评论。

更多回答(0 个)

类别

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

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by