PDA

View Full Version : WaitForSingleObject



^NyAw^
10th February 2012, 17:07
Hi,

I'm developing and application that uses a DAQ(Digital Acquisition) Card on Windows.
In the sample examples there is this piece of code:


IntThread(void* pArg)
{
while (1) {
if (WaitForSingleObject(hEvent[0], INFINITE) == WAIT_OBJECT_0) {
int_count++;
ResetEvent(hEvent[0]);
InvalidateRect(hMainWnd, NULL, FALSE);
}
}
_endthread();
}


I don't understand how to reimplement the "WaitForSingleObject" function.
As I understand, the DAQ card driver sends an event that is catched on this function, so maybe is the only way to get the driver event processed?

Thanks,

wysota
10th February 2012, 17:30
Basically what WaitForSingleObject() does is that it tells the operating system to put the process to sleep until something happens. This "something" decides on the semantics of the call. It can be a semaphore but probably also a socket or a bunch of other things that can be "waited for". So it all boils down to what hEvent[0] really is and whether you can get access to it in a non-blocking fashion.

^NyAw^
10th February 2012, 17:44
Hi,

hEvent is initialized by a DAQ function call:


I16 DIO_SetDualInterrupt (U16 CardNumber, I16 Int1Mode, I16 Int2Mode, HANDLE *hEvent)


I think that what happens is that the driver comunicates to the operating system that there was an event and the OS is the one that wake up the calling process.
So really, there is no other way to solve this without using this function.

Thanks,

kuzulis
10th February 2012, 20:34
Use QWinEventNotifier class instead of WaitForSingleObject