摘要
针对串口通信中系统资源利用不足的问题,提出了一种基于多线程技术和事件驱动方式的串口通信方案。该方案在读取串口数据、对串口通信的错误及通信事件进行监视时,用OVERLAPPED结构体中的hEvent参数指定I/O操作完成后所触发的事件对象。然后,用等待函数检查事件对象的当前状态。最后,当事件对象为有信号状态时完成后续操作。在Win7操作系统的Visual C++开发平台下,结合Windows通信API控制串口的编程方法进行仿真测试。测试结果表明该方案能有效解决采用查询方式时因数据高速涌入造成数据丢失的问题。
This paper proposes a High Speed Serial Communication scheme,which is based on multithread technology and Event-driven mode.The scheme can solve the problem of the underutilization in serial communication.In our scheme,when reading serial data,monitoring the communication error and communication event,the hEvent parameter of the OVERLAPPED structure is used to specify the event object that is triggered by the I/O operation after it is finished.Then,this paper use the wait function to check the current state of the event object.Finally,all the remaining operations are run when the event object is signaling status.In Visual C++ development platform,this paper conduct the computer simulation experiment by exploiting the programming method of communication API in the environment of Win7 operation system.
出处
《工业控制计算机》
2014年第5期14-16,共3页
Industrial Control Computer
关键词
串口通信
多线程
异步操作
事件
high speed serial communication,multithread,asynchronous operation,event