How to implement enum strings properly? | OPC UA Standard | Forum

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
How to implement enum strings properly?
Avatar
Max
Member
Members
Forum Posts: 3
Member Since:
04/02/2019
sp_UserOfflineSmall Offline
1
05/27/2019 - 07:22
sp_Permalink sp_Print
Hello,

I want to expose an enumeration as an OPC UA variable.

So I did what appeared to be the most straight forward way of doing this:

    var enumTest = CreateVariable(root, "enumTest", "enumTest", BuiltInType.Enumeration, ValueRanks.Scalar);

How do I specify the individual values of the values as strings? According to the specification part 3, table 16 there are properties for this:

View post on imgur.com
%MINIFYHTMLcf996d1e3e84dd25cf6ca9d0b8910a9938% So I tried to use EnumString, like so: var enumTest = CreateVariable(root, "enumTest", "enumTest", BuiltInType.Enumeration, ValueRanks.Scalar); enumTest.EnumStrings = new PropertyState<LocalizedText[]>(enumTest) { NodeId = new NodeId(new Guid("B36CB462-9E1B-413D-9796-C35DD26AA289")), BrowseName = new QualifiedName("EnumStrings", 0), Value = new [] { new LocalizedText("A"), new LocalizedText("B"), new LocalizedText("C"), } }; enumTest.Value = 2; But that doesn't work at all. The enumeration strings are not recognized. They don't even show up as properties of the node. Chances are this code is incomplete or wrong or both, but there's no clear documentation on how to do this. Feel free to correct me. Other places on the internet where this question was asked seem to indicate that a custom type definition is necessary. Is this true? I do not understand why, because the EnumStrings property is already there!? There's a different type of variable MultiStateDiscreteItemVariable, which isn't actually an enum: var multiTest = CreateMultiStateDiscreteItemVariable(root, "multiTest", "multiTest", "A", "B", "C"); This works out of the box, with the EnumStrings property available on the variable. This appears to go against the specification however, which clearly states: The EnumStrings Property only applies for Enumeration DataTypes. It shall not be applied for other DataTypes. A MultiStateDiscreteItemVariable isn't of DataType Enumeration. So my question is: what's the proper way to create an enumeration according to the OPC Foundation? Which of the two ways outlined above should I choose and why? Or is there another way? thanks for your help
Avatar
Randy Armstrong
Admin
Forum Posts: 270
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
06/05/2019 - 18:30
sp_Permalink sp_Print

You are using the .NET codebase so the APIs available to you are set my the .NET codebase. It is not a specification issue.

The API should allow you to add any Property to a variable but it can be tricky. You need to call "CreateVariable" for the property too. You can't just create the parent and set the member.

Avatar
Max
Member
Members
Forum Posts: 3
Member Since:
04/02/2019
sp_UserOfflineSmall Offline
3
06/07/2019 - 05:37
sp_Permalink sp_Print

Hi Randy

Randy Armstrong said
The API should allow you to add any Property to a variable but it can be tricky. You need to call "CreateVariable" for the property too. You can't just create the parent and set the member.  

Thanks, this clarifies how to add the property.

---

Can you answer the questions that I've asked?

So my question is: what's the proper way to create an enumeration according to the OPC Foundation? Which of the two ways outlined above should I choose and why? Or is there another way?

---

Can you please elaborate on the following?

Randy Armstrong said
You are using the .NET codebase so the APIs available to you are set my the .NET codebase. It is not a specification issue.

Again, with the following line of code, the C# code base creates a variable that's not an enumeration, but has the EnumStrings property:

var multiTest = CreateMultiStateDiscreteItemVariable(root, "multiTest", "multiTest", "A", "B", "C");

while the specification states that:
The EnumStrings Property only applies for Enumeration DataTypes. It shall not be applied for other DataTypes.

This appears to be a contradiction. Can you explain how and why it is not?

 

thank you

Avatar
Randy Armstrong
Admin
Forum Posts: 270
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
4
06/10/2019 - 07:56
sp_Permalink sp_Print

There is subtle difference between the two:

The Property defined in Part 3 is a Property that can be added to a DataType Node if it is an Enumeration.

The Property in Part 8 is defined on a VariableType Node.

i.e. the statement in Part 3 only applies if someone is thinking of adding the Property to a DataType Node. 

Forum Timezone: America/Phoenix
Most Users Ever Online: 143
Currently Online:
16
Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Newest Members:
andre.broering@stud.th-owl.de
Forum Stats:
Groups: 2
Forums: 9
Topics: 565
Posts: 1611

 

Member Stats:
Guest Posters: 1
Members: 98700
Moderators: 10
Admins: 3
Administrators: michael.bryant@opcfoundation.org, thomas.burke@opcfoundation.org, Randy Armstrong
Moderators: matthias.damm@ascolab.com, s.hoppe@beckhoff.com, paul.hunkar@dsinteroperability.com, jouni.aro@prosys.fi, tim.fortin@honeywell.com, Jim.Luth@Schneider-Electric.com, Karl-Heinz Deiretsbacher, stefan.hoppe@opcfoundation.org, alexander.allmendinger@opcfoundation.org, Karl Deiretsbacher