From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

type cast

Solved!
Go to solution

I have an enum inside a dowhile loop.  The loop uses shift reg to feed back the next state of the enum.  Sometimes I want to stay in the current enum state (actually go back to it).  I'm trying this "subvi" so that I can keep each enum increment or come back to the current state as a general vi. 

 

Question:  is it ok to use the type cast in this manner?? 

 

If a certain condition ( in my state) is met I increment the enum and goto the next state.  If not, I stay in the current state ( don't increment the count).

 

 

0 Kudos
Message 1 of 19
(3,498 Views)

But you do not need to

The +1 and Select will return your enum

 

No need to type cast

Unless you have gone into the Object Properties and messed with the "Output Configurations"

 

But I now see that you are not passing in an enum "Current State"

Omar
0 Kudos
Message 2 of 19
(3,475 Views)

Omar_II wrote:

No need to type cast

Unless you have gone into the Object Properties and messed with the "Output Configurations"


I think you missed the point of the OP wanting to make this a "generic" subVI, implying a reuse subVI.  In my experience, making a reuse VI that acts on a enum just does not work out well.  You will end up converting back and forth and weird things can happen when you try to increment past the largest value of your enum (direct adding will cause a rollover, casting from a number whose value is larger than the enum will allow will coerce to the last value).

 

I suggest just making this subVI a template and making copies from the template for the state machines you actually will use this on.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 19
(3,462 Views)

Hi clint,

 

I have an enum inside a dowhile loop

No, you have not! It's a ring or a simple numeric control!

 

An Enum looks like this:

check.png

And an enum is safe to increment, it will automatically wrap from last to first item…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 19
(3,459 Views)

crossrulz wrote:

In my experience, making a reuse VI that acts on a enum just does not work out well. You will end up converting back and forth and weird things can happen when you try to increment past the largest value of your enum (direct adding will cause a rollover, casting from a number whose value is larger than the enum will allow will coerce to the last value).


Also miss match between Enum U32, Enum U16 and Enum U8 does not work very well.

Omar
0 Kudos
Message 5 of 19
(3,451 Views)

Clint,

     To illustrate the point that Omar, Crossrulz, and Gerd are making, consider the following Snippet (if you drag this picture to a Block Diagram, it will become executable LabVIEW Code that you can run yourself).

Enum Rainbow.png

Color is an Enum that I defined as "Red, Orange, ..., Violet".  As you can see, within the While Loop I add the current value to the Rainbow Array, increment it to the next Color, and stop when I get the first color back again (meaning I've "wrapped around").  This idea will work with any Enum.

 

Bob Schor

0 Kudos
Message 6 of 19
(3,388 Views)

Guess I should have provided more info..See below:

so my question is:

can I use type cast in this manner??  do I even need to?  If I took the enum ( test1..test2..) and just added 1 to it would it cause problems??

 

It sounds like I shouldn't be doing what I'm asking from the replies I'm getting.

 

Thanks.

0 Kudos
Message 7 of 19
(3,255 Views)

Hi Clint,

 

right now it will give problems as you still DON'T work with an enum in your loop.

 

There's a coercion dot and they have a meaning!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 19
(3,249 Views)

so my test1..test2 the way I have it ISN'T an enum??

0 Kudos
Message 9 of 19
(3,232 Views)

there is a shipping example w LV2014.."State Machine Fundamentals.vi"  I thought I did the same thing they did but they don't have the coercion dot and they made thier enum a type def...What am I doing wrong??  Or better yet how do I do what I'm doing correctly?  ..get rid of the dot?

0 Kudos
Message 10 of 19
(3,226 Views)