文章分类 | 推荐文章 | 最新文章 | 热点文章 | 最新软件 | 精品软件 | 下载排行 | 推荐下载 | 免费看大片 | WPS | 杀毒软件
清风网络
首 页 软件下载 网络学院 数码学院
QQ 电脑入门 游戏 操作系统 图形处理 办公软件 媒体动画 精文荟萃 工具软件 网络编程 程序开发 网络技术 认证考试 网站建设 文章专栏
当前位置:清风网络学院程序开发C++Builder用Builder C++设计串行口COM1或COM2的读写操作
精品推荐
特别推荐
·菜鸟入门 认识C#中的委托和事件
·WINDOWS下的动态鼠标光标控制
热点TOP10
·C++ Builder下数据库报表Master/Detail关系功能的实现
·用Builder C++设计串行口COM1或COM2的读写操作
·无废话C#设计模式之四:Factory Method
·菜鸟入门 认识C#中的委托和事件
·C#动态生成树型结构的Web程序设计
·QuickReport基本知识
·获得文件的版本信息
·C++Builder IDE使用技巧与快捷键
·C++Builder注册表编程实例详解
·在bcb里实现像Winamp那样具有吸附效果的磁性窗口

用Builder C++设计串行口COM1或COM2的读写操作

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


// This process guarantees no other part of this program
// is using the port object.

EnterCriticalSection(&port->m_csCommunicationSync);

// ClearCommError() will update the COMSTAT structure and
// clear any other errors.

bResult = ClearCommError(port->m_hComm, &dwError, &comstat);

LeaveCriticalSection(&port->m_csCommunicationSync);

// start forever loop. I use this type of loop because I
// do not know at runtime how many loops this will have to
// run. My solution is to start a forever loop and to
// break out of it when I have processed all of the
// data available. Be careful with this approach and
// be sure your loop will exit.
// My reasons for this are not as clear in this sample
// as it is in my production code, but I have found this
// solutiion to be the most efficient way to do this.

if (comstat.cbInQue == 0)
{
// break out when all bytes have been read
break;
}

EnterCriticalSection(&port->m_csCommunicationSync);

if (bRead)
{
bResult = ReadFile(port->m_hComm, // Handl
to COMM port
&RXBuff,
/ RX Buffer Pointer
1,
/ Read one byte
&BytesRead,
/ Stores number of bytes read
&port->m_ov);
/ pointer to the m_ov structure
// deal with the error code
if (!bResult)
{
switch (dwError = GetLastError())
{
case ERROR_IO_PENDING:
{
// asynchronous i/o is s
ill in progress
// Proceed on to GetOver
appedResults();
bRead = false;
break;
}
default:
{
// Another error has occ
red. Process this error.
port->ProcessErrorMessag
("ReadFile()");
break;
}
}
}
else
{
// ReadFile() returned complete. It is not neces
ary to call GetOv
erlappedResults()
bRead = true;
}
} // close if (bRead)

if (!bRead)
{
bRead = true;
bResult = GetOverlappedResult(port->m_hComm, // Handl
to COMM port


&port->m_ov, // Overlapped structure

&BytesRead, // Stores number of bytes read

true); // Wait flag

// deal with the error code
if (!bResult)
{
port->ProcessErrorMessage("GetOverlappedResults(
in ReadFile()");

}
} // close if (!bRead)

LeaveCriticalSection(&port->m_csCommunicationSync);

// notify parent that a byte was received
::SendMessage((port->m_pOwner)->Handle, WM_COMM_RXCHAR, (WPARAM)

上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] 下一页 




上一篇:用C++Builder建立多线程COM服务器

下一篇:在BCB中使用DirectX

相关文章:
·如何建立一个网站?规划、设计、目的、原则、宣传
·综合实例:PS洗衣粉包装设计印刷全攻略
·3DsMAX教程 设计叶片上的精致三维蜻蜓
·几何图形英文字体创意设计及应用作品欣赏
·英文字体创意设计及应用作品欣赏
·3DMAX设计制作两只花瓣上的美丽蝴蝶
·如何使设计作品获得最佳菲林输出?
·在线设计:轻松获取个性篆刻印章
·美工LOGO设计进阶
·用 CorelDRAW 设计制作商务名片
相关软件:
·C语言程序设计
·Dreamweaver 网页设计
·powerbuilder10.0中文版
·美工设计教程
·Photoshop CS经典创意设计200例
·Photoshop CS中文版平面设计师标准案例教程
·Windows环境下32位汇编语言程序设计
·颐家IDO在线互动设计软件
·Photoshop 7.0 平面 广告 装帧设计100例
·超级DIY设计器V7.0 build 2143 特别版

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