Why do I get the error "Cannot register enumerated data type" when trying to update/run/build my model in AUTOSAR Blockset?
26 views (last 30 days)
Show older comments
MathWorks Support Team
on 14 Oct 2022
Edited: MathWorks Support Team
on 29 Jun 2023
After declaring the data type, the following error message occurs during the update/run/build. Would you confirm what this error message means?
Invalid setting in 'AAA/BBB' for parameter 'OutDataTypeStr'.
Caused by:
Error evaluating properties of Simulink.Bus object 'CCC' in workspace 'base' (used by block 'AAA/BBB')
Cannot register enumerated data type 'DDD' for 'AAA/BBB' because there is a global variable with the same name as this type
Error resolving DataType 'Enum: DDD'
Accepted Answer
MathWorks Support Team
on 29 Jun 2023
Edited: MathWorks Support Team
on 29 Jun 2023
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 behavior in C:
In order 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 (in this case 'AnotherEnum' and 'OneEnum') from the Model Explorer and enabling 'Add Class Name To Enum Names' (for one or both of them), the issue is solved.
0 Comments
More Answers (0)
See Also
Categories
Find more on String 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!