LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

NewAsyncTimer

I am using Timer() to time the response time of a serial port but when I move
the panel or maximize and minimize any other applications the timer values
are way off and stay that way. I have read the suggestions of using NewAsyncTimer,
but I am not sure exactly how it works. Could someone explain NewAsyncTimer
function to me, or show me an example of how it can replace the basic Timer
function? Thank you.
0 Kudos
Message 1 of 5
(4,957 Views)
I'm glad someone else is seeing this besides me. I'm glad you pointed out
the triggering mechanism. NI's response "don't use it" is not the right
answer. It's a serious bug that NI needs to fix. It has cost us many headaches
here. In fact they should issue notices to all customers, I'm sure we're
not the only two that are affected by this.

Sorry I can't answer your real question about how to use NewAsyncTimer.

"Marlise" wrote:
>>I am using Timer() to time the response time of a serial port but when
I move>the panel or maximize and minimize any other applications the timer
values>are way off and stay that way. I have read the suggestions of using
NewAsyncTimer,>but I am not sure exactly how it works. Could someone explain
NewAsyncTimer>function
to me, or show me an example of how it can replace
the basic Timer>function? Thank you.
0 Kudos
Message 2 of 5
(4,957 Views)
The Timer() function is an inappropriate tool to use if you are conducting
timing operations and you don't want the user interface operations to interfere.
This is not a bug, this type of behavior just requires multithreaded programming.
If you program is in a single thread, then it can only do one thing at a
time. So, if a user interface operation causes a significant delay due to
a redraw on maximize, user interface operation, etc. nothing else in the
program can be done until that delay passes. Therefore, your Timer() call
will be delayed as is the rest of the program. Multithreaded programming
solves this problem by dividing the program into independent tasks that can
be executed at the same time. This is how the Asynchronous Timer works.
It creates a separate thread that generates events independent of the user
interface thread. That's why this was recommended as a solution to your
problem. CVI 5.5 also comes with a complete library of multithreading functions
and the debugger was redesigned to debug multithreaded applications. So
you could also build your own thread model instead of using the Ansynchronous
Timer() with built in multithreading.

Best Regards,

Chris Matthews
Measurement Studio PSE
National Instruments


"John Boro" wrote:
>>I'm glad someone else is seeing this besides me. I'm glad you pointed out>the
triggering mechanism. NI's response "don't use it" is not the right>answer.
It's a serious bug that NI needs to fix. It has cost us many headaches>here.
In fact they should issue notices to all customers, I'm sure we're>not the
only two that are affected by this.>>Sorry I can't answer your real question
about how to use NewAsyncTimer.>>"Marlise" wrote:>>>I
am using Timer() to time the response time of a serial port but when>I move>the
panel or maximize and minimize any other applications the timer>values>are
way off and stay that way. I have read the suggestions of using>NewAsyncTimer,>but
I am not sure exactly how it works. Could someone explain>NewAsyncTimer>function
to me, or show me an example of how it can replace>the basic Timer>function?
Thank you.
0 Kudos
Message 4 of 5
(4,957 Views)
#include "asynctmr.h"
#include "main.h"

static int main_panel;

static int sec;

int CVICALLBACK Timer_Seconds(int reserved,int timerId,int event,void
*callbackData,int eventData1,int eventData2)
{
if(sec == 59)
sec == 0;
else
sec++;
SetCtrlVal(main_panel,PANEL_SEC,sec);
return(0);
}

int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR
lpszCmdLine, int nCmdShow)
{
if ((main_panel = LoadPanel (0, "main.uir", PANEL)) < 0)
return -1;
DisplayPanel (main_panel);
NewAsyncTimer(1.0,-1,1,Timer_Seconds,0);

RunUserInterface ();
DiscardPanel (main_panel);
return 0;
}

int CVICALLBACK MainPanel_Exit (int panel, int control, int event,void
*callbackData, int eventData1, int eventData2)
{
switch(event)
{
case EVENT_COMMIT:
QuitUserIn
terface(0);
break;
}
return 0;
}



Marlise wrote in message
news:393e6d06@newsgroups.ni.com...
>
> I am using Timer() to time the response time of a serial port but when I
move
> the panel or maximize and minimize any other applications the timer values
> are way off and stay that way. I have read the suggestions of using
NewAsyncTimer,
> but I am not sure exactly how it works. Could someone explain
NewAsyncTimer
> function to me, or show me an example of how it can replace the basic
Timer
> function? Thank you.
0 Kudos
Message 3 of 5
(4,957 Views)
The better way to do that is to use Visa. I've already do such a program.
The asynchronous mechanism handle both the response event and the timeout
event.
Marlise a écrit dans le message :
393e6d06@newsgroups.ni.com...
>
> I am using Timer() to time the response time of a serial port but when I
move
> the panel or maximize and minimize any other applications the timer values
> are way off and stay that way. I have read the suggestions of using
NewAsyncTimer,
> but I am not sure exactly how it works. Could someone explain
NewAsyncTimer
> function to me, or show me an example of how it can replace the basic
Timer
> function? Thank you.
0 Kudos
Message 5 of 5
(4,957 Views)