Logic
The serial port not buffering any out going chars. Somebody(Logic or MS) is blocking my threads when I write to the port. I have put together a test app that if the serial port driver was interrupt driven and has a buffer should generate a pulsetrain with a period of 10mS - 11mS. It does not, I see the Writefile blocking until char is sent. I need to know why and how to fix this! My Windows image has all of latest drivers in it. Here is test my code:
int _tmain(int argc, _TCHAR* argv[])
{
DWORD dwBytesWritten;
char acTest[] = {0x00, 0x00};
HANDLE hSerialDriverCommPort;
DCB srSerialDriverDcb;
COMMTIMEOUTS srSerialDriverTimeout;
//Open the port
hSerialDriverCommPort = CreateFile(TEXT("COM2:"),
GENERIC_READ|GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
0);
//Setup the serial baud and other settings
memset(&srSerialDriverDcb, 0x00, sizeof(DCB));
srSerialDriverDcb.DCBlength = sizeof(DCB);
GetCommState (hSerialDriverCommPort,&srSerialDriverDcb);
srSerialDriverDcb.BaudRate = 2400;
srSerialDriverDcb.ByteSize = 8;
srSerialDriverDcb.Parity = NOPARITY;
srSerialDriverDcb.fBinary = TRUE;
srSerialDriverDcb.fParity = FALSE;
srSerialDriverDcb.StopBits = ONESTOPBIT;
srSerialDriverDcb.fAbortOnError = FALSE;
srSerialDriverDcb.fRtsControl = RTS_CONTROL_DISABLE;
SetCommState(hSerialDriverCommPort, &srSerialDriverDcb);
//Set the serial timeouts
srSerialDriverTimeout.ReadIntervalTimeout = 1;
srSerialDriverTimeout.ReadTotalTimeoutConstant = 1;
srSerialDriverTimeout.ReadTotalTimeoutMultiplier = 1;
srSerialDriverTimeout.WriteTotalTimeoutConstant = 10;
srSerialDriverTimeout.WriteTotalTimeoutMultiplier = 1;
SetCommTimeouts(hSerialDriverCommPort, &srSerialDriverTimeout);
CeSetThreadPriority(GetCurrentThread(), 0);
while(1)
{
Sleep(10); //10mS + (0uS to 1000uS), Timing is 10mS to 11mS
//Write char
WriteFile(hSerialDriverCommPort, acTest, 1, &dwBytesWritten, NULL); //This blocks for 4mS, why????????
}
return 0;