⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 深入浅出vc++串口编程之短信应用开发4.htm

📁 西门子公司的tc35t的串口编程实例还有AT指令列表
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0040)http://dev.yesky.com/399/2310399_3.shtml -->
<HTML lang=zh-CN xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>深入浅出VC++串口编程之短信应用开发</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META http-equiv=Content-Language content=zh-CN>
<META content=all name=robots>
<META content="index, follow" name=googlebot>
<META content="MSHTML 6.00.2900.2180" name=GENERATOR>
<META content="天极Yesky | 全球中文IT第一门户" name=author>
<META content="天极Yesky | 全球中文IT第一门户" name=Copyright>
<META content=串口开发教程和技巧,深入浅出VC++串口编程之短信应用开发 name=description></META>
<META content=串口,串口教程,串口通信,串口应用,串口设计,VC串口,硬件,软件,数码,游戏,e时代,下载,社区,评测,笔记本; 
name=keywords><LINK media=all href="深入浅出VC++串口编程之短信应用开发4.files/y_newcontent.css" 
type=text/css rel=stylesheet>
<SCRIPT language=JavaScript 
src="深入浅出VC++串口编程之短信应用开发4.files/newcontentjs.js"></SCRIPT>
</HEAD>
<BODY><!--头部--><!--顶部菜单开始-->
<DIV id=topmenubox>
<DIV class=smallmenubox><A class=white 
href="http://www.yesky.com/">Yesky首页</A></DIV>
<DIV class=smallmenubox3><A class=white 
href="http://product.yesky.com/">产品库</A></DIV>
<DIV class=smallmenubox2><A class=white 
href="http://cseek.yesky.com/">商情</A></DIV>
<DIV class=smallmenubox2><A class=white 
href="http://mobile.yesky.com/">手机</A></DIV>
<DIV class=smallmenubox2><A class=white 
href="http://digital.yesky.com/">数码</A></DIV>
<DIV class=smallmenubox3><A class=white 
href="http://notebook.yesky.com/">笔记本</A></DIV>
<DIV class=smallmenubox3><A class=white 
href="http://pc.yesky.com/">台式机</A></DIV>
<DIV class=smallmenubox4><A class=white 
href="http://diy.yesky.com/">DIY硬件</A></DIV>
<DIV class=smallmenubox2><A class=white href="http://oa.yesky.com/">外设</A></DIV>
<DIV class=smallmenubox2><A class=white 
href="http://net.yesky.com/">网络</A></DIV>
<DIV class=smallmenubox4><A class=white 
href="http://dh.yesky.com/">数字家庭</A></DIV>
<DIV class=smallmenubox2><A class=white 
href="http://lab.yesky.com/">评测</A></DIV>
<DIV class=smallmenubox2><A class=white 
href="http://soft.yesky.com/">软件</A></DIV>
<DIV class=smallmenubox3><A class=white href="http://e.yesky.com/">e时代</A></DIV>
<DIV class=smallmenubox2><A class=white 
href="http://game.yesky.com/">游戏</A></DIV>
<DIV class=smallmenubox2><A class=white 
href="http://pic.yesky.com/">图片</A></DIV>
<DIV class=smallmenubox2><A class=white 
href="http://desktop.yesky.com/">壁纸</A></DIV>
<DIV class=smallmenubox2><A class=white 
href="http://hot.yesky.com/">网摘</A></DIV>
<DIV class=smallmenubox2><A class=white href="http://my.yesky.com/">社区</A></DIV>
<DIV class=smallmenubox2><A class=white 
href="http://blog.yesky.com/">博客</A></DIV>
<DIV class=smallmenubox2><A class=white 
href="http://www.mydown.com/">下载</A></DIV></DIV><!--顶部菜单结束--><!--logo及广告开始-->
<DIV class=contentbox><!--LOGOstart-->
<DIV class=left style="MARGIN-RIGHT: 12px"><A href="http://www.yesky.com/"><IMG 
src="深入浅出VC++串口编程之短信应用开发4.files/yeskylogo.gif" border=0></DIV><!--LOGOend--><!--中间小通栏广告开始-->
<DIV class=left style="WIDTH: 500px"><SPAN id=ad1></SPAN></DIV><!--中间小通栏广告结束--><!--中间分站及搜索开始-->
<DIV id=search>
<DIV>
<FORM name=searchform action=http://search.chinabyte.com/search 
method=get><INPUT id=searchzz onmouseover=this.focus() onfocus=this.select() 
size=11 name=q><INPUT type=hidden value=GB2312 name=encoding><INPUT type=hidden 
value=connect name=dir> <INPUT type=hidden value=20002 name=cid><INPUT id=search_btn style="BORDER-RIGHT: #999999 1px solid; BORDER-TOP: #999999 1px solid; BORDER-LEFT: #999999 1px solid; PADDING-TOP: 1px; BORDER-BOTTOM: #999999 1px solid" type=submit value=天极搜索></FORM></DIV>
<DIV style="MARGIN-TOP: 3px; FLOAT: left; WIDTH: 146px">
<DIV class=rightarea><A href="http://bj.yesky.com/">北京</A> <A 
href="http://sh.yesky.com/">上海</A> <A href="http://gd.yesky.com/">广东</A><BR><A 
href="http://cq.yesky.com/">重庆</A> <A href="http://cd.yesky.com/">成都</A> <A 
href="http://sy.yesky.com/">沈阳</A></DIV>
<DIV class=rightarea_right><A href="http://my.yesky.com/">用户<BR>登录</A></DIV>
<DIV><A class=headgreen href="http://www.chinabyte.com/">Chinabyte.com</A><SPAN 
style="FONT-SIZE: 9px">|</SPAN><A class=headblue 
href="http://www.techtarget.com.cn/">Techtarget.com.cn</A></DIV></DIV></DIV><!--中间分站及搜索结束--><!--右部小button广告开始-->
<DIV class=left>
<SCRIPT language=JavaScript 
src="深入浅出VC++串口编程之短信应用开发4.files/newcheadrightad.js"></SCRIPT>
</DIV><!--右部小button广告结束--></DIV><!--logo及广告结束--><!--当前位置开始-->
<DIV id=currentposition><SPAN>您现在的位置:<A href="http://www.yesky.com/"> 
Yesky</A>&gt;<A href="http://soft.yesky.com/"> 软件</A>&gt;<A 
href="http://dev.yesky.com/"> 开发者网络</A> </SPAN><SPAN 
style="PADDING-LEFT: 240px"><SPAN id=ad2></SPAN></SPAN></DIV><!--当前位置结束--><!--正文开始-->
<DIV id=contentarea><!--左部开始-->
<DIV id=contentleft><!--左部的右部开始-->
<DIV id=contentright1><!--文章内容开始-->
<DIV class="left fontsize2">深入浅出VC++串口编程之短信应用开发</DIV>
<DIV class=fontclear></DIV><BR>
<DIV class=left><SPAN class=span>作者:宋宝华</SPAN><SPAN 
class=span>出处:天极开发</SPAN><SPAN class=span>责任编辑:<A title=向本编辑提问 
href="http://comments.yesky.com/t/·&frac12;&Ouml;&Ucirc;/6,324/2310399.shtml"> 方舟 </A></SPAN><SPAN 
class=span>[ 2006-02-21 13:56 ]</SPAN></DIV>
<DIV class=fontclear></DIV>
<DIV class="left fontsize3">本章将给出一个典型的应用实例:西门子短信服务模块TC35的串口控制。</DIV>
<DIV class=fontclear></DIV>
<HR class=hr1>

<DIV class="left fontsize4">
<DIV class=guanggao><SPAN id=ad3></SPAN></DIV>
<DIV class=guanggao><SPAN 
id=contentAdv></SPAN></DIV>  <B>删除短消息<BR></B><BR>  我们可以在读取完所有短信息后调用gsmDeleteMessage函数在GSM模块上删除那些已经被接收到PC上的短信息,它按照第1节阐述的GSM模块删除短消息的串口控制流程进行短信的删除:<BR><BR>
<TABLE borderColor=#cccccc width="90%" align=center bgColor=#e3e3e3 border=1>
  <TBODY>
  <TR>
    <TD>// index: 短消息序号,从1开始<BR>BOOL gsmDeleteMessage(const int 
      index)<BR>{<BR> int nLength; // 串口收到的数据长度<BR> char cmd[16]; // 
      命令串<BR> char ans[128]; // 应答串<BR><BR> sprintf(cmd, "AT+CMGD=%d\r", index); 
      // 生成命令<BR><BR> // 输出命令串<BR> WriteComm(cmd, strlen(cmd));<BR><BR> // 
      读应答数据<BR> nLength = ReadComm(ans, 128);<BR><BR> // 根据能否找到"+CMS 
      ERROR"决定成功与否<BR> if (nLength &gt; 0 &amp;&amp; strncmp(ans, "+CMS ERROR", 
      10) != 0)<BR> {<BR>  return TRUE;<BR> }<BR> return 
  FALSE;<BR>}</TD></TR></TBODY></TABLE><BR>  在PC控制软件的短信列表框中删除所有短消息的"清空"按钮函数为:<BR><BR>
<TABLE borderColor=#cccccc width="90%" align=center bgColor=#e3e3e3 border=1>
  <TBODY>
  <TR>
    <TD>void CSMSControlDlg::OnDeleteallButton() <BR>{<BR> // TODO: Add your 
      control notification handler code 
    here<BR> m_recvlist.ResetContent();<BR>}</TD></TR></TBODY></TABLE><BR>  <STRONG>设置/读/写串口</STRONG><BR><BR>  在应用程序启动与退出及gsmSendMessage、gsmReadMessage和gsmDeleteMessage函数中广泛使用的串口相关函数用WIN32 
API实现:<BR><BR>
<TABLE borderColor=#cccccc width="90%" align=center bgColor=#e3e3e3 border=1>
  <TBODY>
  <TR>
    <TD>// 串口设备句柄<BR>HANDLE hComm;<BR><BR>// 打开串口<BR>// pPort: 
      串口名称或设备路径,可用"COM1"或"\\.\COM1"两种方式,建议用后者<BR>// nBaudRate: 波特率<BR>// 
      nParity: 奇偶校验<BR>// nByteSize: 数据字节宽度<BR>// nStopBits: 停止位<BR>BOOL 
      OpenComm(const char *pPort, int nBaudRate, int nParity, int nByteSize, 
      int<BR>nStopBits)<BR>{<BR> DCB dcb; // 串口控制块<BR> COMMTIMEOUTS timeouts 
      =<BR> {<BR>  // 串口超时控制参数<BR>  100, // 读字符间隔超时时间: 100 ms<BR>  1, // 
      读操作时每字符的时间: 1 ms (n个字符总共为n ms)<BR>  500, // 基本的(额外的)读超时时间: 500 ms<BR>  1, 
      // 写操作时每字符的时间: 1 ms (n个字符总共为n ms)<BR>  100<BR> }; // 基本的(额外的)写超时时间: 100 
      ms<BR><BR> hComm = CreateFile(pPort, // 串口名称或设备路径<BR>  GENERIC_READ | 
      GENERIC_WRITE, // 读写方式<BR>  0, // 共享方式:独占<BR>  NULL, // 
      默认的安全描述符<BR>  OPEN_EXISTING, // 创建方式<BR>  0, // 不需设置文件属性<BR>  NULL); // 
      不需参照模板文件<BR><BR> if (hComm == INVALID_HANDLE_VALUE)<BR>  return 
      FALSE;<BR> // 打开串口失败<BR><BR> GetCommState(hComm, &amp;dcb); // 
      取DCB<BR> dcb.BaudRate = nBaudRate;<BR> dcb.ByteSize = 
      nByteSize;<BR> dcb.Parity = nParity;<BR> dcb.StopBits = 
      nStopBits;<BR><BR> SetCommState(hComm, &amp;dcb); // 
      设置DCB<BR> <BR> SetupComm(hComm, 4096, 1024); // 
      设置输入输出缓冲区大小<BR><BR> SetCommTimeouts(hComm, &amp;timeouts); // 
      设置超时<BR> return TRUE;<BR>}<BR><BR>// 关闭串口<BR>BOOL 
      CloseComm()<BR>{<BR> return CloseHandle(hComm);<BR>}<BR><BR>// 写串口<BR>// 
      pData: 待写的数据缓冲区指针<BR>// nLength: 待写的数据长度<BR>void WriteComm(void *pData, 
      int nLength)<BR>{<BR> DWORD dwNumWrite; // 串口发出的数据长度<BR> WriteFile(hComm, 
      pData, (DWORD)nLength, &amp;dwNumWrite, NULL);<BR>}<BR><BR>// 读串口<BR>// 
      pData: 待读的数据缓冲区指针<BR>// nLength: 待读的最大数据长度<BR>// 返回: 实际读入的数据长度<BR>int 
      ReadComm(void *pData, int nLength)<BR>{<BR> DWORD dwNumRead; // 
      串口收到的数据长度<BR> ReadFile(hComm, pData, (DWORD)nLength, &amp;dwNumRead, 
      NULL);<BR> return (int)dwNumRead;<BR>}</TD></TR></TBODY></TABLE><BR>
<DIV class=right>共5页。 <A class=page 
href="http://dev.yesky.com/399/2310399.shtml" target=_self><FONT 
face=Webdings>9</FONT></A> <A class=page 
href="http://dev.yesky.com/399/2310399_2.shtml" target=_self><FONT 
face=Webdings>7</FONT></A> <A class=page 
href="http://dev.yesky.com/399/2310399.shtml" target=_self><B>1</B></A> <A 
class=page href="http://dev.yesky.com/399/2310399_1.shtml" 
target=_self><B>2</B></A> <A class=page 
href="http://dev.yesky.com/399/2310399_2.shtml" target=_self><B>3</B></A> <A 
class=page href="http://dev.yesky.com/399/2310399_3.shtml" target=_self><FONT 
color=#666666><B>4</B></FONT></A> <A class=page 
href="http://dev.yesky.com/399/2310399_4.shtml" target=_self><B>5</B></A> <A 
class=page href="http://dev.yesky.com/399/2310399_4.shtml" target=_self><FONT 
face=Webdings>8</FONT></A> <A class=page 
href="http://dev.yesky.com/399/2310399_4.shtml" target=_self><FONT 
face=Webdings>:</FONT></A></DIV></DIV>
<DIV class=fontclear></DIV>
<HR class=hr1>

<DIV class=left><SPAN id=ad7></SPAN></DIV>
<DIV class=fontclear></DIV>
<HR class=hr1>
<!--文章内容结束--><!--文章评论开始--><A name=tlwb></A>
<SCRIPT language=JavaScript>
<!--
var aid = 2310399;
var channelid = 324;
var tagname = "串口";
//-->
</SCRIPT>

<SCRIPT language=JavaScript>
<!--
function getTagId(tName) {
	tName = tName.replace(/(^[\s ]*)|([\s ]*$)/g, "");
	var tagid = 0;
	for(var ti = 0; ti < tName.length; ti++) {
		tagid += tName.charCodeAt(ti);
	}
	return tagid;
}function UrlEncode(str){   var i,temp,p,q;   var result="";   str = str.replace(/(^[\s ]*)|([\s ]*$)/g, "");   for(i=0;i<str.length;i++){      temp = str.charCodeAt(i);      if(temp>=0x4e00){         execScript("ascCode=hex(asc(\""+str.charAt(i)+"\"))", "vbscript");         result+=ascCode.replace(/(.{2})/g, "%$1");      }else{         result+=escape(str.charAt(i));      }   }   return result;}
if(typeof(channelid) == "undefined") channelid = 0;

//-->
</SCRIPT>

<DIV class=photobox id=Layer11>
<SCRIPT src="深入浅出VC++串口编程之短信应用开发4.files/uc.js" type=""></SCRIPT>

<TABLE 
style="BORDER-RIGHT: #606060 1px solid; BORDER-TOP: #606060 1px solid; BORDER-LEFT: #606060 1px solid; BORDER-BOTTOM: #606060 1px solid" 
cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
    <TD>
      <TABLE style="COLOR: #ffffff" height=30 cellSpacing=0 cellPadding=0 
      width="100%" background=深入浅出VC++串口编程之短信应用开发4.files/y_newcontent12.gif 
      border=0>
        <TBODY>
        <TR>
          <TD>发表评论:(Html:禁止,UBB:允许)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【查看关于<SPAN 
            style="COLOR: red">
            <SCRIPT language=JavaScript>
<!--
if(typeof(aid) != "undefined") {
	if(typeof(tagname) == "string" && tagname.length > 0) {	var tagnames = tagname.split(",");	for (var tagindex = 0; tagindex < tagnames.length; tagindex++) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -