Avatar

Please consider registering
guest

sp_LogInOut Log In sp_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 RSS sp_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
Moderator
Moderators
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: 960
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: 267

Currently Online:
21 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 124

pramanj: 86

ibrahim: 74

rocket science: 65

kapsl: 57

Sabari: 51

gjevremovic: 49

Xavier: 43

fred: 41

TimK: 41

Member Stats:

Guest Posters: 0

Members: 1749

Moderators: 15

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1323

Posts: 5649

Newest Members:

WalterFOUNC, datafastproxiespx01, LenkaLok, seoninet, justinevillanuev, namtrott5457, DonaldWibip, AlfredoEthix, andreidla, everangel7021

Moderators: Jouni Aro: 960, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 860, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 25, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 222, Lusetti: 0

Administrators: admin: 1