How can I import structures from C and use them as bus elements in a .sldd dictionnary?
15 次查看(过去 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.
0 个评论
采纳的回答
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:
更多回答(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!