LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Fetching VI - How to STOP the VI?

Hi.
 
I am creating this VI to Fetch Data into an XY Array. Kindly see the attached VI. But I am having problem on the Main Stop Function. If I run this VI, I can do the "Reset", "Fetch" and "Stop (a switch to save the last data I inputted)". But this VI will NOT STOP even if I push the "MAIN STOP" button.
Can somebody teach me to correct this VI. I would appreciate to receive any feedback.
 
Thank you very much. 
0 Kudos
Message 1 of 15
(4,039 Views)

First, I'd say you just have to many nested loops.

Second, you have local variables of the outermost loops stopbutton inside the nested loops. The problem is, that your main stop button is just read during its first iteration - afterwards the inner loops are running and as the main stop button can not be read, the vi won't stop.

I'd suggest you to copy this vi, delete all operations from the loops (just leave a wait function in) and run the vi in highlighting mode and look what happens.

Thomas

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 2 of 15
(4,032 Views)
Hi Bong,

like Thomas said: too much nested loops. A local is only updated when the control is read!

I changed your vi a little bit, also some other things (array operations in lower loop...). Try to use more "LV style" operations, your programs will be faster.
The "Main stop" now runs in its own loop to be read every 500ms. This should solve your first problem.

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 15
(4,029 Views)
Dear Mr Thomas and Mr GerdW,
 
Thank you for the replies and the revised VI. I ran the VI but it is showing the same problem. Even if I hit the Main Stop button, the VI still runs. The "Run" Icon still shows it is running.
 
I have attached the original VI. This VI is the Producer/Consumer VI used to fetch data. It has the Stop button inside the inner while loop to save the data I last inputted.
I plan to put this VI inside a big while loop where the big while loop's Stop button is independent to the Stop Button on the inner while loop. Or, I will place this VI in parallel with other VI.
 
If I press the inner while loop's stop button it will only function as a switch to save data.
But if i will push the outer while loop's Stop Button, it should stop the whole VI.
 
I would appreciate your kind assistance.
0 Kudos
Message 4 of 15
(4,026 Views)
I modivied GerdW's vi, so that it works.
 
 
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 5 of 15
(4,015 Views)
"I modivied GerdW's vi, so that it works."
 
- It works. Thank you very much. May I ask why you thought of using the local variable of the Main Stop 2 Indicator (LED) to stop the whole VI instead of the Main Stop itself? Also, what is the purpose of putting a constant "False" to the Main Stop 2 Indicator (LED)  outside the two while loops?
 
Thank you always for rendering assistance. The forum has always been a big help to me.
0 Kudos
Message 6 of 15
(3,996 Views)

Hi Bong,

I'll chime in on this one.  The local variable is initialized outside the loops so that it will always start off in a known state...in other words, if it wasn't initialized, there's a chance its state would be True on the next run of the VI, causing the loops to stop immediately on their first iteration.  Technically, the code isn't quite correct right now, because there is no data dependency between the initialization of the boolean and the loops themselves...there is the possibility that a race condition could occur if the loops started executing before the local variable was written to.  To be correct, that local variable should be initialized in a sequence frame, and the wire should exit the frame and go into the loop border, ensuring the local gets initialized before the loops start.

As for your other question, the local variable is used to check the stop condition in the loop simply because the boolean's terminal is already being used elsewhere (specifically, in the Event Structure).

Hope this helps,
-D

0 Kudos
Message 7 of 15
(3,994 Views)
Hi
 
In addition to what Darren said:
 
I switched the mechanical action of the stopbutton to "Latch When Released". This allows no local variables of this control. For this reason I inserted the indicator, which holds the state of the stop button. So I could use local variables of this indicator to stop the parallel loop.
 
Darren, you're right about the initialisation - I'd build up the app in a different way. But obviously Bong is not yet so into LV, which is why I did not write anything about semaphores, occurences and so on. I think just for a simple starter this helps. Anyway - I once read an article somewhere about the fact, that code, place outside the main loop(s) is executed first - always. Actually I don't rely on that - so for me this was clear. 😉
 
Thomas
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 8 of 15
(3,976 Views)

Darren and Thomas,

Thank you very much for response. I understood your replies.

"To be correct, that local variable should be initialized in a sequence frame, and the wire should exit the frame and go into the loop border, ensuring the local gets initialized before the loops start."

When you say sequence frame, is it an another event structure? If its not asking too much, can you please teach me how can I make the initialization in a sequence frame using VI. This is for my future reference too. Thank you very much.

0 Kudos
Message 9 of 15
(3,960 Views)

No, the sequence-structure has nothing to do with the event-structure.

In the picture you can see it - in such a structure, each case is executed after the other.

Message Edited by becktho on 02-21-2006 09:47 AM

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
Message 10 of 15
(3,958 Views)