我写了个以API的方式实现串口通讯的程序,可以正常通讯,但是经常性的打开和关闭串口,使串口通讯的速度变慢了许多。
    我的问题是:如何获得发送或接收数据结束的信号?这样就可以不浪费时间也不丢失数据。
    请各位高手多多指教,谢谢!

解决方案 »

  1.   

    BOOL GetCommMask(
      HANDLE hFile,      // handle to communications device
      LPDWORD lpEvtMask  // pointer to variable to get event mask
    );
     
    lpEvtMask 可以是:
    EV_RXCHAR  :A character was received and placed in the input buffer. (收到)
    EV_TXEMPTY :The last character in the output buffer was sent. (发送完)返回值:
    成功:非零nonzero.
    失败:零zero.
      

  2.   

    SetCommMask设置串口能够响应的事件WaitCommEvent 等待SetCommMask设置的事件,简单说在一个单独的线程(我们一般把它叫做监控线程)中用循环WaitCommEvent和sendmessage来实现串口的中断机制