Custom enumerations are causing 'Potential conflicting usages of identifier' error when generating code.

43 Ansichten (letzte 30 Tage)
Hi,
I have a model consisting of many models created by different authors inserted using the a ModelReference block.
The Model simulates fine in normal mode, but when I generate code for Accelerated mode or Realtime Target I get the following error.
### Build procedure for model: 'FS_HUD2_004FUN' aborted due to an error.
Potential conflicting usages of identifier 'DISABLE': an enumeration string in data type
'enm_CFG_TSR', and an enumeration string in data type 'enm_CFG_NAVIGATION'
We have a large number of custom enumerations across all the models (many have a enumeration 'DISABLE'/'ENABLE'/'ERROR' etc), but the two in this example are:
classdef enm_CFG_TSR < Simulink.IntEnumType
enumeration
DISABLE(0),
ENABLE(1),
end
end
and
classdef enm_CFG_NAVIGATION < Simulink.IntEnumType
enumeration
DISABLE(0),
ENABLE(1),
end
end
In normal mode I have no issues as the State Charts that use them, use full definitions on their transitions for example:
[IPCHUDMenuTSRReq == 1 ...
&& IPCHUDMenuTSRReq_frsh == 1 ...
&& CFG_TSR == enm_CFG_TSR.ENABLE]
Is there a way to get the compiler to generate unique enumerations in the generated code automatically. As I would like to avoid manually renaming to ensure that there are no duplications as this will be very time consuming, and additionally lead to enumerations that look something like below, which I understand is frowned upon:
classdef enm_CFG_NAVIGATION < Simulink.IntEnumType
enumeration
CFG_NAVIGATION_DISABLE(0),
CFG_NAVIGATION_ENABLE(1),
end
end
Any tips or advice greatly appreciated.

Akzeptierte Antwort

James Marriott
James Marriott am 1 Nov. 2018
From Technical Support:
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:
Additionaly, 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', the issue should be solved too.

Weitere Antworten (0)

Kategorien

Mehr zu Code Interface Definitions finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by