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.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Stuck in a do while!! How do I exit when the user clicks on a button?

Hello, I was wandering if anyone could help. I have written a program to send a code to a PIC and record the returned data in a text display before saving. The program needs to have a delay between receiving the data and requesting the next. It also needs a start and stop button, the problem is that once I start the program running I get stuck within a do while loop. I have looked at the GetUserEvent but cant get it to work. Are there any good examples? Or could you tell me how to get it to work.
Thanks

Nigel

P.S. I am using LabWindows CVI V6.0
P.S. I have attached the program code.
Download All
0 Kudos
Message 1 of 5
(3,367 Views)
You didn't include the UIR file but anyway, seems you want to read data from
your device every so often. I would suggest that you use a timer control.
When you press START button, configure your SerialPort, clear all
input/output queues. Also remember by default serial timeouts are 5seconds.
After you done this, turn on the timer and have a global flag which tells
you that timer is ON. Now in timer callback, just read your data and display
in the text box or whatever you want. I don't know what your device sends
when you send 1 byte to it (why are Flushing the input Q after reading from
it?). The timer callback should also check the global variable and read data
only if global variable is ON. On STOP button callback, turn off that global
variable that you turned on in START callack.

The way you have your code, STST will never become 0. Reason is that you are
using Delay function which hangs up GUI. You need to have something like

do {

ProcessSysetmEvents();
} while (STST != 0);

ProcessSystemEvents processes your GUI events.

I use my own Delay something like follows:

void Wait(double NumOfSeconds)
{
double t0;
double t1;

t0 = Timer();
t1 = Timer();

while ((t1-t0) < NumOfSeconds) {
ProcessSystemEvents();
t1 = Timer();
}
}

Let me know if you need more help.


vishi


"njc" wrote in message
news:506500000008000000747E0000-1042324653000@exchange.ni.com...
> Hello, I was wandering if anyone could help. I have written a program
> to send a code to a PIC and record the returned data in a text display
> before saving. The program needs to have a delay between receiving the
> data and requesting the next. It also needs a start and stop button,
> the problem is that once I start the program running I get stuck
> within a do while loop. I have looked at the GetUserEvent but cant get
> it to work. Are there any good examples? Or could you tell me how to
> get it to work.
> Thanks
>
> Nigel
>
> P.S. I am using LabWindows CVI V6.0
> P.S. I have attached the program code.
0 Kudos
Message 2 of 5
(3,367 Views)
The better way is to use a Timer Contro and enable it ( at the beginning of your communication ) , disable it ( when you have finished to communicate).
Other way is to use a loop with Delay(1.0); to wait ( 1 second for example) inside the loop.That function do not lock the events.
0 Kudos
Message 3 of 5
(3,367 Views)
Hello

Building on Pierre's answer, you could even use the async timer, which runs the same way as a timer, only in its own thread, so any time comsuming task that the timer might handle will not block the GUI thread. You can find an example of it under ..\CVI\samples\toolbox\.

Thanks

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 4 of 5
(3,367 Views)
Have managed to get it working. Thanks for all the advice, it was much appreciated.
Nigel
0 Kudos
Message 5 of 5
(3,367 Views)