02-13-2012 03:40 AM
Good Morning. I have a program which is running multiple threads. When the user clicks the start test button, a new thread is created to run all the data acquisition and processing tasks. Part of the data acquisition task is to acquire data from an analog to digital card. To start the acquisition, a function is called from the card's SDK. This enables the trigger on the board with a callback called when the card is triggered. I've included in my code a timeout using an async timer so that if a trigger is not received with a defined amount of time, the acquisition is canceled. The problem I have is that no timer ticks are received by the async timer. The basic layout of the code is as follows:
ret = dataAqFuncStart();
if (ret == NO_ERROR)
{
SetanalogTrigTimoutFlag(TRIG_TIMEOUT_CLEAR);
timerId = NewAsyncTimer (ANALOG_IN_TRIG_TIMEOUT, 1, 1,
DaqAnalogInTimer, NULL);
}
if (ret == NO_ERROR)
{
while ((GetdaqAnalogInFlag() == 0) && GetanalogTrigTimoutFlag() == TRIG_TIMEOUT_CLEAR)
{
}
}
Within the callback function for the data acquisition card, the daqAnalogInFlag is set if the card is triggered. In the async timer, analogTrigTimeoutFlag is set on timer tick. I never actually get a timer tick though so my code sits in the while loop. As part of debugging, I was monitoring system resources which showed that both threads of my computer was running at 100%. I placed a 200ms delay in the while loop and this dropped the processor activity by about 3/4. I guess this is because the code was running the while loop frantically obtaining the two flags. Another thing I tried as part of debugging was placing 'GetAsyncTimerAttribute (timerId, ASYNC_ATTR_TIMER_TIME, &timerTime)' in the while loop after the delay. On the first time through the while loop, the value timerTime was 0.0. On the second time through, the time was 5006.598 which clearly incorrect as only approximately 200ms has passed. The final observation was that there was an event call to the timer callback when I close the thread which was created at the start of the test. This indicates that the timer has been created.
Are there any other debugging methods I can use or can anyone point me in the direction of an answer?
Thanks
Solved! Go to Solution.
02-13-2012 05:46 AM
Do you really need an asyncronous timer for getting the timeout? Couldn't you simply check the value from Timer () within the loop and exit on a stated time? Someting like this:
if (ret == NO_ERROR) { tini = Timer (); while ((GetdaqAnalogInFlag() == 0) && (Timer () - tini < 1.0)) { // Some code } // Cleanup code }
Async timers are run in their own separate thread: I don't know what can be happening while creating an async timer in a thread other than the main one.
02-13-2012 06:18 AM
Thanks Roberto. I love a simple solution! I never really knew much about the timer function in CVI so always used async timers. Think I will be using the timer function more often in the future.
Thanks