|
void CommInit(CString IndexText,unsigned long Baudrate)
{
DCB dcb;
hSer = CreateFile( IndexText, GENERIC_READ | GENERIC_WRITE, 0,NULL,OPEN_EXISTING, 0, NULL );
if( hSer == INVALID_HANDLE_VALUE )
{
pm_Status->SetWindowText(TEXT("Cannot Open COM!"));
return;
}
pm_Status->SetWindowText(TEXT("COM Opened!"));
//set the DCB structure
dcb.DCBlength = sizeof( DCB );
GetCommState( hSer, &dcb );
dcb.fParity = FALSE;
dcb.fNull = FALSE;
dcb.StopBits = ONESTOPBIT;
dcb.Parity = NOPARITY;
dcb.BaudRate = Baudrate;
dcb.ByteSize = 8;
// BOOL bSetCommStat =
SetCommState( hSer, &dcb );
//Set the timeout
COMMTIMEOUTS CommTimeOuts;
CommTimeOuts.ReadIntervalTimeout = 0xFFFFFFFF;
CommTimeOuts.ReadTotalTimeoutMultiplier = 10;
CommTimeOuts.ReadTotalTimeoutConstant = 10;
CommTimeOuts.WriteTotalTimeoutMultiplier = 50;
CommTimeOuts.WriteTotalTimeoutConstant = 100;
SetCommTimeouts( hSer, &CommTimeOuts );
return;
}
这是我的串口初始化程序,我调试中发现只要执行到“SetCommState( hSer, &dcb ); ”就会出现上述打印信息 |
|