LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Button responsiveness and operation in loops

Hi,
I have written a program that tells some equipment to source a voltage and read the resulting current. The Labview program works just fine. However, I have recently wanted to add a Cancel button, in order to disregard the results that come from the equipment.

While the equipment is running (takes about 30 seconds), the user should be able to hit the cancel button. The program should wait until the equipment is finished (no big deal since it doesn't take long) and then trash the results. However, once I give the equipment an opportunity to start scanning, Labview refuses to accept input. In fact, it's only after the loop (in which the equipment commands exist) exits that the click is recognized, so the value of the b
utton changes after everything is already done.

I was told that button values are read for each while loop (so that a while loop inside a while loop would reread the button value?), but it doesn't seem to be working.

Long story short, I want a process that monitors this cancel button and responds when I click it. It'd be best if I could force the software to update the button value before the program goes into the "parse the data" section so I could check to see if the button had been pressed while the equipment was running.

This is hard to explain I think, so please ask for clarification if I did a poor job.

Thank you for your help!
-James
0 Kudos
Message 1 of 4
(2,823 Views)
Without seeing your code, it is difficult to determine what is going on. However, it sounds like your communications with the equipment is blocking until finished. There are sveral ways to avoid this.

First, place the user interface including your Cancel button in a separate loop from the equipment communications loop. Transfer data between the loops with queues or functional globals. Put a wait function in each loop. That allows LabVIEW's internal scheduler to switch between the loops without waiting for one to finish.

Second, Look at why your communication loop is bloacking. If you are trying to read N bytes and the read function is waiting until the bytes are available, try calculating the approximate time for the data to accumulate before calli
ng the read. Better is to find out how much data is available and read only that amount. The details depend on what kind of communications you are using.

Third, Learn about state machines. They are often implemented as while loops with a case statement inside. They are very versatile and powerful for the kinds of tasks you want to do. Check examples and search the archives.

Lynn
Message 2 of 4
(2,823 Views)
Excellent answer Lynn.

You punched all of the right buttons!

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 3 of 4
(2,823 Views)
Hi James,

your comment on "button values are read for each while loop " only applies when the button terminal is actually present in the given loop. If I have two nested loops, and the button terminal is outside both, then it won't be read in any loops.

If you pass a wire from the terminal through both loops, it's value won't change, whereas the button may well have a different state. Only the actual terminal of the button will deliver an up-to-date value based on the actual button action on the front panel.

Hope this helps

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 4 of 4
(2,823 Views)