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

조회 수: 5 (최근 30일)
Jamie
Jamie 2023년 11월 17일
댓글: VIGNESH BALAJI 2024년 5월 28일
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