LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Case structure only executing one case

Solved!
Go to solution

I am (still) trying to control the ThorLab stages LTS300 and MTS50-Z8. I have written the program attached below for this. The program essentially starts communication with the stages, then does some movements with them, then disconnects them. I have been asked to also include an "ABORT" or "STOP IMMEDIATELY" button, just in case anything goes wrong with the stages, that termiantes communication witht he stages straight away. The stop immediately button in the below vi does stop the program when pressed, however, I expected the program to run the movement routine when the button has not yet been pressed. But nothing happens. Could someone explain where I am going wrong. I've also included images of the true/false case for the button and the subdiagrams the button should trigger. I fear that this is very simple...
Thanks in advance

0 Kudos
Message 1 of 7
(4,037 Views)

Your code only executes a TRUE case by the look of it.

0 Kudos
Message 2 of 7
(4,029 Views)

Hi bockdoug,

 

The stop immediately button in the below vi does stop the program when pressed, however, I expected the program to run the movement routine when the button has not yet been pressed. But nothing happens.

This is an easy answer: THINK DATAFLOW!

Simple way to find the bug: use debugging tools like highlight execution…

 

I have been asked to also include an "ABORT" or "STOP IMMEDIATELY" button, just in case anything goes wrong with the stages, that termiantes communication witht he stages straight away.

You need to edit your state machine then!

Btw. use an enum with useful items instead of those "0", "1" steps…

Best regards,
GerdW


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

Hey, thanks to you two for both your answers. After some reading, this looks like a producer/consumer problem. Could I solve this by putting the true and false cases in separate for loops? Is this what you mean by using the dataflow? This way, the while loop inside the false case will run the movements, and the while loop inside the true case will abort the process. I don't have access to LabView at the moment, so can only try it out in about 10 hours...

0 Kudos
Message 4 of 7
(3,966 Views)

Hi bockdoug,

 

After some reading, this looks like a producer/consumer problem.

Well, you want to be able to break current operations by a STOP button: you could stay with your state machine, but you need to check the STOP button in each state (as often as needed)…

 

Could I solve this by putting the true and false cases in separate for loops?

How/why do you want to separate TRUE and FALSE cases in different loops?

 

Is this what you mean by using the dataflow?

Surely not!

Examine the DATAFLOW by using highlight execution debugging - then you (start to) understand it and you see why your current VI does NOT work as intended!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 7
(3,961 Views)

Ok, so, after running with highlight execution, it seems like the initial false value of the button never leaves the while loop. But when the button is pressed and its value becomes true, the true state does leave the while loop and the true case is executed, shutting down the devices. This does not make any sense to me!
Also, the only probelm I can see with my code is that the leftmost while loop polls the state of the button every 20 ms. Does this mean that, once I get it to work, the false case restarts itself every 20 ms. Or does the case structure wait with accepting another value until the subdiagram has fully executed?
I am now trying your suggestion about checking the stop button in each state.

0 Kudos
Message 6 of 7
(3,926 Views)
Solution
Accepted by topic author bockdoug

@bockdoug wrote:

This does not make any sense to me!


Rules of dataflow:

1. No code can execute until it has all of its inputs

2. No code will output anything until is has completed running

3. A loop cannot iterate until everything inside of it has completed running

 

So what is happening is you have a data dependency between the loop and the case structure.  The case structure cannot run until it has an input from the loop.  But the loop will not output its value until is has completed running.  And the only way to stop that loop (and allow its output to be passed on) is when the loop termination is set to TRUE.


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 7 of 7
(3,905 Views)