2,640
社区成员
发帖
与我相关
我的任务
分享
cto_main.ReadIntervalTimeout = 0;
cto_main.ReadTotalTimeoutMultiplier = 0;
cto_main.ReadTotalTimeoutConstant = 0;
cto_main.WriteTotalTimeoutMultiplier = 0;
cto_main.WriteTotalTimeoutConstant = 0;
SetCommTimeouts (hPort_main, &cto_main);//设定超时
if (hThread_main)
CloseHandle (hThread_main);
PurgeComm(hPort_main,PURGE_TXCLEAR|PURGE_RXCLEAR);
hPort_main=CreateFile(mainSerialPort+_T(":"), GENERIC_READ|GENERIC_WRITE,0, NULL, OPEN_EXISTING,0, NULL);
if(hPort_main==INVALID_HANDLE_VALUE)
{
AfxMessageBox(_T( "open com port error ! "));
}
GetCommState (hPort_main, &PortDCB_main);
PortDCB_main.BaudRate= CBR_115200; //配置串口
PortDCB_main.DCBlength= sizeof (DCB);
//PortDCB_main.BaudRate= CBR_9600;
PortDCB_main.fBinary = TRUE;
PortDCB_main.fParity= FALSE;
PortDCB_main.ByteSize= 8;
PortDCB_main.Parity= NOPARITY;
PortDCB_main.StopBits= ONESTOPBIT;
if(!SetCommState(hPort_main, &PortDCB_main))
{
AfxMessageBox(_T( "Set com port error ! "));
}
DWORD dwBytesWrite=nLen;
COMSTAT ComStat;
DWORD dwErrorFlags;
BOOL bWriteStat;
ClearCommError(hPort_main,&dwErrorFlags,&ComStat);
bWriteStat=WriteFile(hPort_main,pBuf,dwBytesWrite,& dwBytesWrite,NULL);
if(!bWriteStat)
{
AfxMessageBox(_T("写通信板串口失败!"));
}
PurgeComm(hPort_yt, PURGE_TXABORT|
PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR);