Avatar
Please consider registering
guest
sp_LogInOut Log Insp_Registration Register
Register | Lost password?
Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Feed Topic RSSsp_TopicIcon
How to use own enum as input parameter type for methods
March 7, 2013
11:03, EET
Avatar
fred
Member
Members
Forum Posts: 41
Member Since:
January 27, 2012
sp_UserOfflineSmall Offline

Hi,

I was wondering if there is a way to use an own enum implementation, which extends Enumeration, as DataType for input argument of a method.

What I want to achieve is a way to allow e.g. “OK”, “NOK” as values for an input argument.

WIth DataType Boolean I only get a checkbox for setting the input value using UaExpert. What I want to see is a select box with my two defined options.

Is this possible? If yes, how to define this in Argument array?

Thanks.

Best regards

March 8, 2013
7:52, EET
Avatar
Otso Palonen
Espoo, Finland
Member
Members
Forum Posts: 32
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Hi,

Yes, using a custom Enumeration as argument for a method is possible. SampleConsoleServer.createMyEnumNode() has a sample of adding your own Enumeration type. Then use the NodeId of your custom enumeration as the DataType of the argument (example of creating a custom method can be found in SampleConsoleServer.createMethodNode()). Using the latest version of UaExpert, you should see a drop-down of the possible values as input argument.

Best regards,
– Otso

March 8, 2013
9:03, EET
Avatar
fred
Member
Members
Forum Posts: 41
Member Since:
January 27, 2012
sp_UserOfflineSmall Offline

Hi Otso,

Thanks for your answer. I have the latest version. However, I can’t find method createMyEnumNode() in the SampleConsoleServer code!

I already created an enum which works and I also think I found my error. I tried to use the “public enum …” in setDataType(..) method instead of creating this enum as a DataType/Subtype of enumeration too.

However, also when I use my own EnumType I do not get Dropdown in UaExpert. Could you provide a short code snippet on how to do that?

That’s what I have done:

Argument[] inputs = new Argument[1];
inputs[0] = new Argument();
inputs[0].setName(“Input1”);
inputs[0].setDataType(myOwnEnumType.getNodeId());
inputs[0].setValueRank(ValueRanks.Scalar);
inputs[0].setArrayDimensions(null);
inputs[0].setDescription(new LocalizedText(“Value for Input1”, Locale.ENGLISH));
setMyMethod.setInputArguments(inputs);

where myOwnEnumType is defined as a UaDataTypeNode.

Best regards,

Fred

March 12, 2013
13:28, EET
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1029
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

The problems seems to be in the example type definition, if you followed the blog post sample.

The EnumStrings property must be defined as


    PlainProperty enumStringsProperty = new PlainProperty(
            myNodeManager, myEnumStringsId, new QualifiedName("EnumStrings"),
            new LocalizedText("EnumStrings", LocalizedText.NO_LOCALE));

in order to define the BrowseName in namespace 0. The “default” constructor defines the BrowseName in the same namespace with the NodeId.

  // WRONG
  PlainProperty enumStringsProperty = new PlainProperty(
            myNodeManager, myEnumStringsId, "EnumStrings",
            LocalizedText.NO_LOCALE);

Since EnumStrings is a standard property, the BrowseName must be defined in the standard namespace.

SampleConsoleServer.createMyEnumNode() is not yet in the released SDK sample code (version 1.4.2).

March 13, 2013
7:05, EET
Avatar
fred
Member
Members
Forum Posts: 41
Member Since:
January 27, 2012
sp_UserOfflineSmall Offline

Thanks Juoni,

Defining the EnumStrings property the correct way, helped a lot 😉

Best regards,
Fred

Forum Timezone: Europe/Helsinki
Most Users Ever Online: 1919
Currently Online:
Guest(s) 23
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 90
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 732
Moderators: 8
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1545
Posts: 6516
Newest Members:
mood edibles, LouieWreve, daniellabdx, janessan21, sammiebeak359, gena7127517, thorstenbouldin, Brett.Rollason, steven014223542, Roberthat
Moderators: Jouni Aro: 1029, Pyry: 1, Petri: 1, Bjarne Boström: 1045, Jimmy Ni: 26, Matti Siponen: 353, Lusetti: 0, Elias: 0
Administrators: admin: 1