LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Set enum values through vi server

Solved!
Go to solution

I know enum value can be set using Scan From String function during run time. Also I know if I have enums with same values, I can build them into an array and set the values in a for loop using the Scan From String function. I have enums with different values, if I build them into an array, data types are converted and the value property becomes variant data type, then I don't know how it can be handled. I tried to use To More Specific Class, it doesn't help. Any suggestions? Thanks. 

0 Kudos
Message 1 of 16
(3,671 Views)

@guangdew1 wrote:

Any suggestions? Thanks. 


Your explaining what you've tried, but not what you are trying to achieve.

 

Scan From String doesn't really set an enum value, it creates a new variable with a value. Adding enum values to an array, converts the enums to integers. So I suppose you're talking about enum references? If you get variant values, you can convert them to integers (Variant To Data), or to an enum.

 

I think you're walking on thin ice here. Doing this stuff wrong can seriously harm your LabVIEW experience.

 

You know about typedefs? Not knowing about them and working with enums is a very bad situation...

0 Kudos
Message 2 of 16
(3,615 Views)

I may not have made myself clear, the attached vi further explained it. This is LabVIEW 2013, if you want to have lower version, let me know. The vi can be run if you disable the broken part.

 

I cannot post a snippet, everything related with references are messed up if I do.

0 Kudos
Message 3 of 16
(3,593 Views)

Forgot the attachment.

0 Kudos
Message 4 of 16
(3,591 Views)

This Nugget I wrote on Using Control references may help you.

 

One example included in that nugget shows how to use a trial and error approach to casting the reference to the correct type.

 

Also be aware that using Type-defined Enums will help out.

 

Ben 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 5 of 16
(3,576 Views)
Solution
Accepted by topic author guangdew1

That's exactly what I was thinking you where doing.

 

Since the Scan From String works on the enum strings, and doesn't except variants, you're on your own. Get the enum strings from it's Strings[] property, and compare them:

Enum array.png

 

Note this isn't exactly the same as Scan From String. Scan From String matches the longest string in the enum, and excepts text behind the input string. So "yes sir" would also match yes. The search will succeed only if there is an exact match. You could change this of course. The concept should be clear.

 

Message 6 of 16
(3,569 Views)

Hi Ben,

 

I'm reading your nugget, what I want to do is just like your concern, set default behavior of an executable. 

 

You mentioned to make enum into typedef, I tried to make them either typedef or strict typedef, but I don't see it helps, could you explain?

 

Thanks.

 

0 Kudos
Message 7 of 16
(3,537 Views)

@guangdew1 wrote:

Hi Ben,

 

I'm reading your nugget, what I want to do is just like your concern, set default behavior of an executable. 

 

You mentioned to make enum into typedef, I tried to make them either typedef or strict typedef, but I don't see it helps, could you explain?

 

Thanks.

 


At the time I wrote that Nugget, we were running LV 8.0 or so and did have nearly as many options or tool-kits as we do now. I linked that Nugget to show you how a value for an unknown type control an be set. What you should do is scan the replies to that nugget and find the various other tools-kits that are available. I THNK "Moore-good ideas" may have a complete tool-kit. It may also be built into the OpenG Toolkit.

 

re: Type definitions...

 

I use then anytime I have an enum or a cluster that is used more than one place. The type definition will update all instances of the widget when I modify it. I wrote another Nugget on Type defs that you can find here.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 8 of 16
(3,528 Views)

If you mix enums you need to use the numerical representation instead.

Mixed Enums to value.png

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 9 of 16
(3,524 Views)

@Yamaeda wrote:

If you mix enums you need to use the numerical representation instead.

Mixed Enums to value.png

/Y


That example is just ONE of the newer features available in modern versions of LabVIEW that I alluded too.

 

Those functions can be found on a variant sub-palette.

 

Just like working in a machine shop, it is a good idea to get an idea about ALL of the tools in in your tool-box otherwise you will find yourself trying to drive a screw with a hammer.

 

But in fairness to my old nugget, back then we only had hammers and screwdrivers had not yet been invented. (smiley-wink).

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 10 of 16
(3,516 Views)