I tried using the VISA calls viOpenDefaultRM(), viOpen(), viSetAttribute(), viWrite(), and viRead() functions <~per the example~> to replace the Windows SDK calls CreateFile(), WriteFile(), FlushFileBuffers(), and ReadFile(), just for fun.
All initialization and async serial write functions worked fine. However, my thread that polls the serial port using viRead() does not seem to work. The while loop always returns no data even though 3 batches of 60-80 bytes have been sent through the RS-232 line (in my test configuration).
static DWORD WINAPI rcvThread(LPVOID parm)
{
while (WaitForSingleObject(haltEvent,50)!=WAIT_OBJECT_0)
{
status = viReadAsync (instr, temp, VI_NULL,
&bytes_read);
// sta
tus = viRead( instr, temp, VI_NULL,
// &bytes_read );
if (status == VI_SUCCESS)
{
// process data received
}
else
{
// keep reading
}
}
}
As you can see, I tried using viReadAsync(), and viRead(), with similar results (no data read). I put a breakpoint on VI_SUCCESS, but it never got there.
I am currently sticking with FlushFileBuffers() <~less changes to my code~>, but I'd like to know what I am doing wrong with this viRead() call.