LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Integer to Enum conversion

Hi all,
   While playing with the "state diagram editor" I noticed a function that I hadn't seen before, an "Integer to Enum conversion". I've looked throughout the palettes (LabVIEW 7.1.1 Professional Developer Addition) without finding it anywhere other than on the diagram created by the state diagram editor. Anyone else stumbled on this in one of the palettes? Kind of helpful little widget at times.
 
P.M.
Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



Message 1 of 25
(9,035 Views)
I have not seen that control before but cant you just do the same thing with a typecast?
 
Paul
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
Message 2 of 25
(9,016 Views)


@LV_Pro wrote:
... Anyone else stumbled on this in one of the palettes? Kind of helpful little widget at times.

It looks cosmetically similar to OpenG's "Coerce to Enum" which is (was?) a merged VI and predates the State Diagram Editor.

I think one advantage that using OpenG's had (has?) over typecasting was being immune to the oops factor that results when the integer doesn't have the same representation as the enum.


 

=====================================================
Fading out. " ... J. Arthur Rank on gong."
Message 3 of 25
(9,008 Views)

Well that is the thing about this function, it is taking an I32 in and converting it to the appropriate enum type/value apparently.

Wonder if it will show up in 8.0?

 

P.M.

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



Message 4 of 25
(9,006 Views)

Hi Putnam,

Excelent question. THe SD Editor is an amazing tool!

1) On the surface that VI looks like a type cast but it does what a type cast can not do. Please see the attached "Not_a_Typecast.vi".

2) It is found OK on machines that do not have the SDE but does not show up in the VI hairchy. I guess it is imbeded in the VI, somehow!?

3) It looks like it the output of the only VI added when the SDE is installed. I suggest you conduct the following experiment.

 

a) Copy the VI named ";DNI_IntToEnum.vi" (found in Program Files\Nationla Instruments\LabVIEW 7.1\addons\statediagram) to another location using an name that does not start with ";"

b) Open it using LV and take a look around. I looked at this VI before I started learning about scripting so I do not have a full aprreciation for what it is doing.

 

And if you find that interesting then save evrything you have open and then try the following AFTER YOU SAVE EVERYTHING!

NOTE LV 7.1 with State Digram Editor required.

 

1) Download the two attached VI's.

2) Open both and then open the diagram of "Test.vi"

3) Run "WhoRunning.vi".

4) Go to the diagram of "Test.vi" and choose "Edit State Diagram.

5) Every VI involved in the SD Editor will then be opened and you will have to use the Task Manager to kill LV!

 

Again this is another hole I have not crawled into but I am convinced that there is some power full stuff hiding in the VI that open.

 

BTW: I wrote "WhoRunning.vi" after seeing the hiarchy screen flicker while opening the SDE. After trying a bunch of ctrl-a 's I resorted to using LV to help out.

 

Please share improvements to this VI if you make them.

I am very interested in others observations re: any of the above.
 
Ben

PS: Please save all of your work before you try any of the above. Backing up all of LabVIEW may also be a good idea.

Message Edited by Ben on 09-03-2005 10:32 AM

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Download All
Message 5 of 25
(8,994 Views)
Ben,

That's pretty cool.  I've made a VI before that's similiar to Who's Running (except with more stuff) for my investigations into what's going on with my system.  If you open those VI's and get a path you can have the full path which is good for looking around.

So anyway, fyi, the location of those files that open is in some of the LabVIEW system LLB's that are renamed as resources.  Those particular files were here:

LabVIEW\resource\vidialogs.rsc\file.vi


Just make a copy of vidialogs.rsc and rename it to an LLB to open it.

Message 6 of 25
(8,848 Views)
Oh I get it.  I don't think anything special is going on here.  I looked at it again... the files that are loaded are just used to display the popup dialog box. 
Message 7 of 25
(8,847 Views)
Um, one more comment Ben...

I looked at Not A Typecast later this afternoon and something didn't ring true.  I wrote a routine awhile ago to give me an array for an enum, so if I update the enum (add an item for example), then the next time the program runs, the array will also include one more item. 

Anyway, that routine uses a for loop index that gets typecasted to the enum I'm building an array for.  A quick look at it showed your error:  Typecasting an I32 to an U16 enum.  Place a U16 conversion in front of the typecast in your loop and the enum will convert just fine.
Message 8 of 25
(8,964 Views)

Hi m3nth,

 

Yes, I should have written "it does what a type cast can not do [without help]."

 
I am still very curious about what is really hapening inside DNI_IntToEnum.vi. The part that really strikes my interest is in "PropType" where there a lot of interesting operations.
 
To try to understand the Int to Enum better i put together the VI's in the attached ZIPs. Note: LV 7.1 only. Could not get these to work in LV 7.0.
 
What I wanted to do was to get the code in that case running so I could learn what this thing is doing. The tricky part was getting some widget to wire up to the control called "extNodeRefNum".
 
The top level VI is "Unbundle_Caller.vi" and just (ahem) calls a sub VI which is a cut and paste of the code found in "PropType". Note: I did clean up the code a little so it was readable and added Mike Porter's Error fork Stacker.
 
THe VI runs without errors so this COULD imply the code in "PropType" is intended to act on the Int to Enum function.
 
Before you run this eaxample
 
CLOSE AND SAVE EVERYTHING!
 
but do take a peak at "UntitledVI before you run the top level. You will see it just has a Int to Enum, and is not broken.
 
After running "Unbundle_Caller.VI" Untitled will be broken and the error list will indicate the int to enum is broken.
 
So what doe sall this mean?
 
I hope to get some help from Y'all in figuring out what is with this function that can not be handled with a template that uses a To U16 and a Type cast?
 
Each state of a SD needs a different enum for its transitions.
 
The enum's order can be edited to control the order of the transision checks.
 
These tweo fact amy play a part in the answer.
 
Sorry Putnam but I do not think I have answered your Q!
 
What do you think?
 
Ben
 
CLOSE EVERYTHING BEFORE TRYING THIS EAXAMPLE!
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 9 of 25
(8,939 Views)
First of all (for those catching up), my two posts which are now at the bottom of this thread were written before the ones which are now above it.

Second...

Ben... I don't actually have the SD editor.  Which may be why I couldn't find the "DNI_IntToEnum.vi" file anywhere in my LabVIEW directory.  I'm wondering if that file actually has a semi-colon in front of it though??? (which I also searched for). 

As soon as I opened your zip file I saw XNode code, so it looks like (from your post full of questions) that you may have stumbled on XNodes without realizing what they are or how they work.  Xnodes look like LabVIEW primatives but they actually have more code inside of them (code that can break) that you can't edit unless you rename them to something not starting with semicolon D (";DWhatever.vi") and open them to edit.  Or perhaps you've managed this with your scripting abilities and broke the code inside of that XNode.  Anyway...

You'll see the little red X in the icon for Xnode related stuff in LabVIEW... that is what the ExternalNode is actually referring to (shortened to "X").  It is suspected among us (*wink*) that NI is ramping up this ability to use for a scripting package they have said they intend to sell, but they have already implemented it in a number of things such as timed loops and the storage VI's. 

See here for complete XNode documentation:
http://xnodes.lavausergroup.org/XNode.html

And here for a discussion post:
http://forums.lavausergroup.org/index.php?showtopic=1624&hl=xnode

See Adam Rofer's previous site and the crazy things you can do with XNodes like playing MineSweeper on the Block Diagram...
http://www.angelfire.com/scary/lv/
Message 10 of 25
(8,895 Views)