typedef struct _COMMTIMEOUTS {  
    DWORD ReadIntervalTimeout; 
    DWORD ReadTotalTimeoutMultiplier; 
    DWORD ReadTotalTimeoutConstant; 
    DWORD WriteTotalTimeoutMultiplier; 
    DWORD WriteTotalTimeoutConstant; 
} COMMTIMEOUTS,*LPCOMMTIMEOUTS; 
它的每个成员都有何作用
同时,同步通信和异步通信是怎么回事

解决方案 »

  1.   

    从英文单词应该能猜到
    关于读写时间
    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
      

  2.   

    // set the timeout values
    m_CommTimeouts.ReadIntervalTimeout = 1000;
    m_CommTimeouts.ReadTotalTimeoutMultiplier = 1000;
    m_CommTimeouts.ReadTotalTimeoutConstant = 1000;
    m_CommTimeouts.WriteTotalTimeoutMultiplier = 1000;
    m_CommTimeouts.WriteTotalTimeoutConstant = 1000;
      

  3.   

    ref: Platform SDK: Files and I/O
      

  4.   

    This is a module from my code for setting Timeouts.  I am passing the
    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;
    }
      

  5.   

    maybe you can consult this:
    http://netcity1.web.hinet.net/UserData/vega6385/uart1.htm
      

  6.   

    DWORD ReadIntervalTimeout; //接收字符之间的最大时间间隔 一般为0   DWORD ReadTotalTimeoutMultiplier; 
     DWORD ReadTotalTimeoutConstant; 
    //ReadTotalTimeoutMultiplier * 接收字符个数 + ReadTotalTimeoutConstant为你设置的总的超时时间,
    比如你如果希望串口在规定时间里接收到指定数量的字符就可以使用这种
    超时方式,下面的写操作相同。
     
    DWORD WriteTotalTimeoutMultiplier; 
     DWORD WriteTotalTimeoutConstant;
    ================================================================曾经有一碗热辣辣的烧猪手面放在我面前,我没有珍惜,等到晾凉了之后才后悔莫及。
      

  7.   

    在用ReadFile和WriteFile读写串行口时,需要考虑超时问题。如果在指定的时间内没有读出或写入指定数量的字符,那么ReadFile或WriteFile的操作就会结束。要查询当前的超时设置应调用GetCommTimeouts函数,该函数会填充一个COMMTIMEOUTS结构。调用SetCommTimeouts可以用某一个COMMTIMEOUTS结构的内容来设置超时。有两种超时:间隔超时和总超时。间隔超时是指在接收时两个字符之间的最大时延,总超时是指读写操作总共花费的最大时间。写操作只支持总超时,而读操作两种超时均支持。用COMMTIMEOUTS结构可以规定读/写操作的超时,该结构的定义为:typedef struct _COMMTIMEOUTS { DWORD ReadIntervalTimeout; // 读间隔超时DWORD ReadTotalTimeoutMultiplier; // 读时间系数DWORD ReadTotalTimeoutConstant; // 读时间常量DWORD WriteTotalTimeoutMultiplier; // 写时间系数DWORD WriteTotalTimeoutConstant; // 写时间常量} COMMTIMEOUTS,*LPCOMMTIMEOUTS;COMMTIMEOUTS结构的成员都以毫秒为单位。总超时的计算公式是:总超时=时间系数×要求读/写的字符数 + 时间常量例如,如果要读入10个字符,那么读操作的总超时的计算公式为:读总超时=ReadTotalTimeoutMultiplier×10 + ReadTotalTimeoutConstant可以看出,间隔超时和总超时的设置是不相关的,这可以方便通信程序灵活地设置各种超时。如果所有写超时参数均为0,那么就不使用写超时。如果ReadIntervalTimeout为0,那么就不使用读间隔超时,如果ReadTotalTimeoutMultiplier和ReadTotalTimeoutConstant都为0,则不使用读总超时。如果读间隔超时被设置成MAXDWORD并且两个读总超时为0,那么在读一次输入缓冲区中的内容后读操作就立即完成,而不管是否读入了要求的字符。在用重叠方式读写串行口时,虽然ReadFile和WriteFile在完成操作以前就可能返回,但超时仍然是起作用的。在这种情况下,超时规定的是操作的完成时间,而不是ReadFile和WriteFile的返回时间。