typedef struct _COMMTIMEOUTS {
DWORD ReadIntervalTimeout;
DWORD ReadTotalTimeoutMultiplier;
DWORD ReadTotalTimeoutConstant;
DWORD WriteTotalTimeoutMultiplier;
DWORD WriteTotalTimeoutConstant;
} COMMTIMEOUTS,*LPCOMMTIMEOUTS;
它的每个成员都有何作用
同时,同步通信和异步通信是怎么回事
DWORD ReadIntervalTimeout;
DWORD ReadTotalTimeoutMultiplier;
DWORD ReadTotalTimeoutConstant;
DWORD WriteTotalTimeoutMultiplier;
DWORD WriteTotalTimeoutConstant;
} COMMTIMEOUTS,*LPCOMMTIMEOUTS;
它的每个成员都有何作用
同时,同步通信和异步通信是怎么回事
关于读写时间
m_hComm = CreateFile(szPort, // communication port string (COMX)
GENERIC_READ | GENERIC_WRITE, // read/write types
0, // comm devices must be opened with exclusive access
NULL, // no security attributes
OPEN_EXISTING, // comm devices must use OPEN_EXISTING
FILE_FLAG_OVERLAPPED, // Async I/O
0); // template must be 0 for comm devices
m_CommTimeouts.ReadIntervalTimeout = 1000;
m_CommTimeouts.ReadTotalTimeoutMultiplier = 1000;
m_CommTimeouts.ReadTotalTimeoutConstant = 1000;
m_CommTimeouts.WriteTotalTimeoutMultiplier = 1000;
m_CommTimeouts.WriteTotalTimeoutConstant = 1000;
function 5 CStrings from a dialogbox interface. Yep, there are other ways
to do it, but this works for me. Hope it helps you...// Set the COMMTIMEOUTS based on the parameters passed, if the port supports
them.
//
BOOL CCommTimeOuts::SetCommTimeOuts(HANDLE hComm,
CString lpstrData1,
CString lpstrData2,
CString lpstrData3,
CString lpstrData4,
CString lpstrData5)
{
COMMPROP commprop;
COMMTIMEOUTS commtimeouts;
DWORD dwData1, dwData2, dwData3, dwData4, dwData5;GetCommProperties(hComm, &commprop);
GetCommTimeouts(hComm, &commtimeouts);dwData1 = atol(lpstrData1);
dwData2 = atol(lpstrData2);
dwData3 = atol(lpstrData3);
dwData4 = atol(lpstrData4);
dwData5 = atol(lpstrData5);// See if the Comm Properties support the use of timeouts.
//
if (FALSE == commprop.dwProvCapabilities) {
CErrorHandler pErrorHandler;
DWORD dwLastError = 0;
dwLastError = GetLastError();
pErrorHandler.ShowSystemMsg("CCommTimeOuts::SetCommTimeOuts()",
dwLastError);
return FALSE;
}// Timeouts are supported, make the changes.
//
commtimeouts.ReadIntervalTimeout = dwData1;
commtimeouts.ReadTotalTimeoutMultiplier = dwData2;
commtimeouts.ReadTotalTimeoutConstant = dwData3;
commtimeouts.WriteTotalTimeoutMultiplier = dwData4;
commtimeouts.WriteTotalTimeoutConstant = dwData5;SetCommTimeouts(hComm, &commtimeouts);
return TRUE;
}
http://netcity1.web.hinet.net/UserData/vega6385/uart1.htm
DWORD ReadTotalTimeoutConstant;
//ReadTotalTimeoutMultiplier * 接收字符个数 + ReadTotalTimeoutConstant为你设置的总的超时时间,
比如你如果希望串口在规定时间里接收到指定数量的字符就可以使用这种
超时方式,下面的写操作相同。
DWORD WriteTotalTimeoutMultiplier;
DWORD WriteTotalTimeoutConstant;
================================================================曾经有一碗热辣辣的烧猪手面放在我面前,我没有珍惜,等到晾凉了之后才后悔莫及。