Cannot register enumerated data type for global variable issue
23 views (last 30 days)
Show older comments
Hi,
I simulate model using sim Matlab script command programmatically. When it runs, it stores data from sldd to Matlab base workspace. And when there is input with enum type, it gives the following error :
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)simtestautomationgui('pushbutton4_Callback',hObject,eventdata,guidata(hObject)) - Show complete stack trace
Caused by:
Error using simtestautomation (line 737)
Cannot register enumerated data type 'SNSR_STATUS_TYPE' for 'IvtTmpSnDiag_Testsimulation/IvtTempDiag/IvtTempDiag/IvtTempDiag_Vref_FltStatus' because there is a global variable with the same name as this type - Show complete stack trace
Error using simtestautomation (line 737)
Error evaluating DataType 'Enum: SNSR_STATUS_TYPE' - Show complete stack trace
I see that SNSR_STATUS_TYPE is loaded into base workspace and think that it tries to register this enum again for input variable of enum type. I could not find a fix for this problem. Could you please help me to fix this issue ? Thanks.
2 Comments
Walter Roberson
on 9 Mar 2021
Could you check to see if there is a literal global variable with the name? If you remove the name from the base workspace does that give you a different situation?
Answers (1)
Arun
on 16 Feb 2024
Hi Baris,
I understand that you are facing error “cannot register enumerated data type ”XXX...” for “ZZZ...” because there is a global variable with the same name as this type”.
In MATLAB/Simulink, the Enumeration elements reside within their own class definition and are considered separate sets of entities. Because of this, two Enumeration elements in different classes can have the same name.
However, when these Enumeration elements are converted to C, they are converted from respective class properties to basic enumeration types. All entities of enumeration type in C are public in the global namespace. Because these entities are now in the same namespace, two entities with the same name will cause a redeclaration error. The following link provides more information regarding this behaviour in C:
To avoid this error automatically, please enter the following code in the class definition of the Enumeration types:
methods (Static = true)
function retVal = addClassNameToEnumNames()
retVal = true;
end
end
This tells the Simulink Coder to prefix the Enumeration elements for that Enumeration type with its class name in the generated C code. Therefore, the naming conflict is resolved. More details about the 'addClassNameToEnumNames' function can be found at the following documentation link:
If the two Enum types are defined in the data dictionary of your model as 'Simulink Enumerated Type', by clicking on the Name of the objects from the Model Explorer and enabling 'Add Class Name to Enum Names' (for one or both of them), the issue is solved.
Hope this helps.
0 Comments
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!