LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I use a formula node to start the execution of a case structure?

Hi,

 

I am working on editing a VI to make it much easier to understand (for colleagues and non LV users). For one reason or another, the VI's creators did not fully make use of the power of case structures and other structure types. In the application we need it for, the instrument cycles and repeats measurements on several objects. We are interested in measuring the motor currents for several motors in the system. As it stands now, for each sample object's run, there is a separate sub-vi diagram which displays its waveform trace and several indicators such as max current, time at max, etc. That code was contained within a T/F case structure and copied and pasted 20 plus times.... Obviously the vi became extrememly cluttered and needed a huge screen to see. The trigger for the current case structures is an EQUALS comparison between one input (which is the sample object counter; and this part I will likely leave unchanged since it makes a lot of sense already) and a constant which was defined 1 through 20+ for case. 

 

I have since made one case structure and 20+ instances of that case and have labeled them (at the top selection box near the detent arrows) "1", "2", 3, etc. I am wondering if I can use a formula node to act as the "trigger" which sets each case structure running? I believe that a simple IF statement should work. Please see a snippet of my attempt at making this in C below.

 

For the node, I defined X as the input and Y as the output. The input to the node, X, is connected to the sample object counter. The output, Y, is connected to the case selector of the case structure. My attempt at the code is below:

 

 

int32 y

 

For(x == 1)

   y = "1";

 For(x == 2)

   y = "2";

 

etc, etc.

 

Is that above code snippet correct? Do i need something like "ENDIF" or "end if" at the end? Does "y" have to be defined as "int32" or can it be something else?

 

Thanks for the help!

0 Kudos
Message 1 of 5
(2,582 Views)

Is your formula node doing anything else besides what is shown?

 

Why don't you just wire the value that is going into it at X directly into the selector of the case structure?

0 Kudos
Message 2 of 5
(2,575 Views)

Time ran out on my edit.

 

 

 

You also have numerous problems with the syntax of the code in your formula node.

 

You are using "For" but this isn't a For loop.  It looks like you are using and If Then Else structure.

Also, you defined y to be int32, but your assignments to that variable are all strings.

 

The correct syntax for what you posted is:

 

int32 y; if(x== 1){ y = 1; } else if(x == 2){ y = 2; }

But then there is no reason to do this for such a trivial operation.

0 Kudos
Message 3 of 5
(2,572 Views)

Sorry, I was tired when i posted this. Obviously "For" should be "IF". I will look into wiring the object counter input directly into the case selector. However, if I can't get that to work for one reason or another, will the formula node as I have it work for my purposes?

 

Also, the formula node isn't being used to do anything else.

0 Kudos
Message 4 of 5
(2,558 Views)

Sure, but since your stated goal is to make a VI easier to understand, creating a formula node would do just the opposite. Don't 'look into' wiring the counter to the case statement, just do it.

 

 

0 Kudos
Message 5 of 5
(2,550 Views)