在开发串行通讯的Delphi程序时,遇到如下问题!
在Win98下用API函数编写串行通讯函数,对此通讯函数的要求是做同步处理
即在用函数API ReadFile进行读串口操作时,系统处于阻塞状态,
等待函数返回结果,并不象通讯控件所用的多线程处理!
例如:ReadFile(hcom,read_buffer,cbrNum,readnumber,nil)
再用这个函数时,用一个While(ture)循环来判断一个时间标志,只要时间
标志没有超出要求,就循环调用ReadFilehcom,read_buffer,cbrNum,readnumber,nil)
来读取串口数据
ReadFile这个函数在98下可以返回成功!
但在2000下通用的处理过程,却返回失败
望各位高手帮助解决!

解决方案 »

  1.   

    WWW.GOOGLE.COM
    搜索 串口通讯
    就可以找到一个很好的网站。
      

  2.   

    我也遇到这个问题,你的判断另外一个错误
    if ( ! ReadFile(FhCom,RDBuffer,bytes, &bytesrw,&rOverLapped) )  {
          if (GetLastError() == ERROR_IO_PENDING)  {
            // We have to wait for read to complete.
            // This function will timeout according to the
            // CommTimeOuts.ReadTotalTimeoutConstant variable
            // Every time it times out, check for port errors
            while( !GetOverlappedResult(FhCom,&rOverLapped, &bytesrw,TRUE ) )  {
              if ( GetLastError() != ERROR_IO_INCOMPLETE )  {
                // an error occurred, try to recover
                ResetBytes();
                if ( FOnReceiveEvent != NULL )
                  FOnReceiveEvent( RDBuffer, bytesrw );
                return bytesrw;
              }
            }
            ResetBytes();
          }