Simulink - change in behaviour of Enumerated Constant block with R2023B?

10 次查看(过去 30 天)
My company is running tests to make sure our old models work with the latest Simulink version. We have a test of all the default block types, and the Enumerated Constant block is giving us an error.
It's set up exactly like the default described in this page : https://www.mathworks.com/help/simulink/slref/enumeratedconstant.html
Enum SlDemoSign with default value SlDemoSign.Positive
When we run the model it gives:
Error in opInitFunction (line 101)
GenerateModel(action, model, platform, preBuildCmd, postBuildCmd, listSub, StandAloneModel, SlxFormat, compilerVersionName); - Show complete stack trace
Caused by:
Error using opInitFunction>CompileModel
'Enum: SlDemoSign' does not resolve to a valid data type for parameter 'OutDataTypeStr' in 'rtdemo1_all_blocks/SS_ALL_BLOCKS/all_sources/Enumerated Constant'. - Show complete stack trace
Error using opInitFunction>CompileModel
Cannot register enumerated data type because value specified is not a class. - Show complete stack trace
Error using opInitFunction>CompileModel
optoolbox.rtlabtools.rtlab_api_helper: INFO: Error evaluating parameter 'Value' in 'rtdemo1_all_blocks/SS_ALL_BLOCKS/all_sources/Enumerated Constant' - Show complete stack trace
Error using opInitFunction>CompileModel
Unable to resolve the name 'SlDemoSign.Positive'. - Show complete stack trace
Running the model and clicking the Enum shows this:
I was able to get it working by creating a SlDemoSign.m file. I don't know why this is necessary now, though.
classdef SlDemoSign < Simulink.IntEnumType
enumeration
enum1(0)
Positive(1)
end
methods (Static)
function retVal = getDefaultValue()
retVal = SlDemoSign.enum1;
end
end
end
This is a new problem with Simulink R2023B. Our models are all from version R2015B which we can't change because they need to be backwards-compatible.
Does anyone have any insight? Thank you
  1 个评论
VIGNESH BALAJI
VIGNESH BALAJI 2024-5-28
@Jamie i am also using Matlab R2023B and facing the same problem. Where did you add this file ? Can you please provide me clear instructions for a beginner ?

请先登录,再进行评论。

回答(1 个)

Ayush
Ayush 2023-12-1
Hi Jamie
I understand that the “Enumerated Constant” block is erroring out by default in MATLAB R2023b which was not the case in the earlier versions.
Based on your exploration, you are on the right path in creating a “SIDemoSign.m” file in your project workspace to define the enumerations class for the block and is the expected behaviour as per the documentation. In earlier versions of MATLAB up until R2023a this file “SIDemoSign.m” was referred by the “Enumerated Constant” block by default. Please refer to the below documentation to know more about how to use enumerated data in Simulink Model:
Upon further investigation, this file/script for the class definition was used by an example present in the root workspace, hence was accessible by the “Enumerated Constant” block by default. It has now been moved to the Example Manager in MATLAB R2023b and hence it is no longer in that path and thus leading to an error.
% In R2023a
>> which SlDemoSign
C:\Program Files\MATLAB\R2023a\toolbox\simulink\simdemos\simfeatures\SlDemoSign.m % SlDemoSign constructor
% In R2023b
>> which SlDemoSign
'SlDemoSign' not found.
Here is the reference for "SIDemoSign.m" that you can use to define an enumerations class in your model's base workspace and resolve this issue across your model.
% In R2023b you can run:
>> openExample('SlDemoSign.m')
% to open the file, which will also show where you can find it now.
Hope it helps,
Regards,
Ayush Misra
  1 个评论
Jamie
Jamie 2023-12-1
Thank you Ayush, indeed I've been able to get this going by using a SlDemoSign.m from an earlier version of MATLAB.
The one I posted above is incomplete, the full file is as follows:
classdef SlDemoSign < Simulink.IntEnumType
% SLDEMOSIGN Enumerated class to represent sign of real numbers
%
% Allowable values:
% - SlDemoSign.Positive
% - SlDemoSign.Zero
% - SlDemoSign.Negative
% Copyright 1990-2010 The MathWorks, Inc.
enumeration
Positive(1)
Zero(0)
Negative(-1)
end
end
% EOF

请先登录,再进行评论。

类别

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

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by