文章分类 | 推荐文章 | 最新文章 | 热点文章 | 最新软件 | 精品软件 | 下载排行 | 推荐下载 | 免费看大片 | WPS | 杀毒软件
清风网络
首 页 软件下载 网络学院 数码学院
QQ 电脑入门 游戏 操作系统 图形处理 办公软件 媒体动画 精文荟萃 工具软件 网络编程 程序开发 网络技术 认证考试 网站建设 文章专栏
当前位置:清风网络学院程序开发C/C++深入浅出Win32多线程程序设计之综合实例
精品推荐
特别推荐
·C语言编程易犯毛病集合
·C语言编程常见问题解答(目录)
·C#程序开发中的常用函数汇总
·C/C++笔试、面试题目大汇总
·Beej的网络socket编程指南
·socket编程原理
·C语言的常用库函数使用方法分析及用途
·在C语言中如何处理时间和日期
·C++设计模式之Singleton
·VC++动态链接库编程之MFC扩展 DLL
热点TOP10
·进程和线程编程
·C语言编程易犯毛病集合
·打字游戏
·Awk 基础入门:Awk 实例编程
·asp.net中调用javascript函数实现多功能日期控件示例
·C语言编程常见问题解答之常用函数的包含文件(1)
·C# GridView 排序及分页
·C #中的几个线程同步对象方法
·无废话C#设计模式之三:Abstract Factory
·C# DataGridView隔行显示不同的颜色

深入浅出Win32多线程程序设计之综合实例

日期:2008年6月6日 作者: 查看:[大字体 中字体 小字体]



 return TRUE;
}

  3.3.3核心函数:串口线程控制函数

  串口线程处理函数是整个类中最核心的部分,它主要完成两类工作:

  (1)利用WaitCommEvent函数对串口上发生的事件进行获取并根据事件的不同类型进行相应的处理;

  (2)利用WaitForMultipleObjects函数对串口相关的用户控制事件进行等待并做相应处理。

UINT CSerialPort::CommThread(LPVOID pParam)
{
 // Cast the void pointer passed to the thread back to
 // a pointer of CSerialPort class
 CSerialPort *port = (CSerialPort*)pParam;

 // Set the status variable in the dialog class to
 // TRUE to indicate the thread is running.
 port->m_bThreadAlive = TRUE;

 // Misc. variables
 DWORD BytesTransfered = 0;
 DWORD Event = 0;
 DWORD CommEvent = 0;
 DWORD dwError = 0;
 COMSTAT comstat;
 BOOL bResult = TRUE;

 // Clear comm buffers at startup
 if (port->m_hComm)
  // check if the port is opened
  PurgeComm(port->m_hComm, PURGE_RXCLEAR PURGE_TXCLEAR PURGE_RXABORT PURGE_TXABORT);

  // begin forever loop. This loop will run as long as the thread is alive.
  for (;;)
  {
   // Make a call to WaitCommEvent(). This call will return immediatly
   // because our port was created as an async port (FILE_FLAG_OVERLAPPED
   // and an m_OverlappedStructerlapped structure specified). This call will cause the
   // m_OverlappedStructerlapped element m_OverlappedStruct.hEvent, which is part of the m_hEventArray to
   // be placed in a non-signeled state if there are no bytes available to be read,
   // or to a signeled state if there are bytes available. If this event handle
   // is set to the non-signeled state, it will be set to signeled when a
   // character arrives at the port.

   // we do this for each port!

   bResult = WaitCommEvent(port->m_hComm, &Event, &port->m_ov);

   if (!bResult)
   {
    // If WaitCommEvent() returns FALSE, process the last error to determin
    // the reason..
    switch (dwError = GetLastError())
    {
     case ERROR_IO_PENDING:
     {
      // This is a normal return value if there are no bytes
      // to read at the port.
      // Do nothing and continue
      break;
     }
     case 87:
     {
      // Under Windows NT, this value is returned for some reason.
      // I have not investigated why, but it is also a valid reply
      // Also do nothing and continue.
      break;
     }
     default:
     {
      // All other error codes indicate a serious error has

上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] 下一页 




上一篇:C++箴言:理解typename的两个含义

下一篇:C++箴言:谨慎使用多继承

相关文章:
·Photoshop CS3合成实例:人间天堂
·DataList嵌套实例
·Photoshop实例:制作超酷影片画面场景
·综合实例:PS洗衣粉包装设计印刷全攻略
·Photoshop精细抠像实例
·PS初学者实例教程 烫金字的制作
·进程和线程编程
·[综合交流]母矿、矿石、魔法石、召唤石的出处
·[综合]《武林外传》内测账号密码修改指南
·Flash动画制作实例:小野人玩摇滚
相关软件:
·C语言程序设计
·中文版Excel 2003实例与技巧
·CorelDraw12 入门与实例(图文教程 菜鸟先飞系列教材)
·AutoCAD2002入门与实例详解
·Windows环境下32位汇编语言程序设计
·Flash MX 动画制作实例教程
·注册表实例应用视频教程swf
·英语自考-综合英语(一)上册 - 第01讲(全16讲)
·PhotoShop7 设计百例 + 经典实例教程 + 滤镜教学
·AUTOCAD 2002机械设计应用与实例

特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
[打印本页] [关闭窗口] 转载请注明来源:http://www.viphot.com
| 帮助(?) | 版权声明 | 友情连接 | 关于我们 | 信息发布
Copyright 2007 www.viphot.com All Rights Reserved. 鄂ICP备05000083号Powered by:viphot