We ended up finding out that our lower level serial driver that was sitting on top of the Virtual Com port was waking up from WaitCommEvent() even though we had set the Comm Mask to only wake up when new characters where in the RX buffer. We weren't double checking that there were actually new bytes. I still think WaitCommEvent() shouldn't be waking the thread up until new data arrives, but that's an issue we can "fix". Once that has been fixed we now are having the problem where occasionally single byte transfers aren't showing up in the RX buffer, until another byte is transferred. We have verified that the byte is travelling across the USB interface, but it doesn't seem to show up when reading the port until after another byte is transferred. I'm beginning to wonder if the WaitCommEvent isn't waking up like it should.
I think this all may be related to the issue with WaitCommEvent, does anyone know of any troubles when setting up a Com event that only wakes on Receiving new characters? We are currently only waiting on EV_RXCHAR, are there other events we should be waiting on?
The low level driver seems to work fine when using actual physical serial ports, we only seem to have these issues when we use the USB virtual com port.
Here's a little snippet of how the com port is being setup for reference:
sprintf(temp, "\\\\.\\COM%d", port);
idComDev = CreateFile(temp, GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL);
if (idComDev != (HANDLE)-1)
{
SetCommMask(idComDev, EV_RXCHAR);
...
}
And this is how we wait on it:
dwEvtMask = 0;
dwRVal = WaitCommEvent(idComDev, &dwEvtMask, NULL);