04/02/2019
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.comSo 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
05/30/2017
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.
04/02/2019
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
05/30/2017
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.
1 Guest(s)