MATLAB Answers

PLC export enum with values

1 view (last 30 days)
Martin Ploom
Martin Ploom on 17 Jul 2020
Commented: Martin Ploom on 22 Feb 2021
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!

Answers (1)

Sri Kapali
Sri Kapali on 18 Feb 2021
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.
  1 Comment
Martin Ploom
Martin Ploom on 22 Feb 2021
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.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!

Translated by