PLC export enum with values

7 次查看(过去 30 天)
Martin Ploom
Martin Ploom 2020-7-17
Hey!
I got a question, how could I export my 'enum' from Simulink with PLC exporter keeping the values for 'enum'. For example my 'enum' values in data dictionary are:
and I need the exported code to have the same values, but when Simulink exports to PLC, it does not keep the value:
Is it a bug, is it intended or is there a setting for it that I did not manage to find?
Thank you in advance!

回答(1 个)

Sri Kapali
Sri Kapali 2021-2-18
Hello,
My understanding is that your model contains enumerated data types, and when you generate code, the generated code does not contain the values for your enumerated data types.
For example, the generated code is
TYPE demo:
(demo1, demo2);
END_TYPE
However, the code you expect is
TYPE demo:
(demo1:=0, demo2:=10);
END_TYPE
I had a couple of questions:
1.What version of MATLAB are you using?
2.What version of Simulink PLC Coder are you using?
In R2020a Simulink PLC Coder added a feature to generate the enum to integer type as a pat of the generated code. For more information, see https://www.mathworks.com/help/releases/R2020a/plccoder/ug/plc-coder-symbols.html#mw_90db60fa-d201-42b7-942b-9ca6d26ac828
and modified the myEnum class to demo and used the values you had created by creating this code:
classdef demo < Simulink.IntEnumType
%
% Copyright 2019 The MathWorks, Inc.
enumeration
demo1 (0)
demo2 (10)
end
end
I then enabled the Generate enum cast function option and the generated code contains the enum types with their values.
This behavior was added in R2020a and was not available in prior releases.
  2 个评论
Martin Ploom
Martin Ploom 2021-2-22
Thank you for looking into it!
Answers to the questions:
  1. 2019b
  2. Version 3.1
Unfortunately cannot access the 2nd link at the moment to see how you approached it in full.
Roshan Wijetunge
Roshan Wijetunge 2022-12-13
I have the same question, but it doesn't work for me. I have enums defined with the values as in the exampe above, but when I generate PLC code, the resulting Enum definitions do not set the values, it is just a list of comma seperated identifiers. I am using 2022a and have tried enabling the Generate enum cast function option, but makes no difference.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink PLC Coder 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by