📄 scommassistantcode02.htm
字号:
<HTML><HEAD><TITLE>串口调试助手V1.0源程序详细编程过程(二)</TITLE>
<META content="Microsoft FrontPage 4.0" name=GENERATOR>
<meta name="keywords" content="roaringwind,roaringwind.best.163.com,啸峰工作室,龚建伟,串口调试助手,VC/C编程,移动机器人,matlab仿真">
<meta name="DESCRIPTION" content="串口、端口、网络通信技术,VC、C编程技术,轮式移动机器人控制相关技术,Matlab仿真及数据处理">
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<STYLE type=text/css>A:link {
COLOR: #006666; TEXT-DECORATION: none
}
A:visited {
COLOR: #006666; TEXT-DECORATION: none
}
A:active {
COLOR: #33cc00; TEXT-DECORATION: none
}
A:hover {
COLOR: #33cc00; TEXT-DECORATION: underline
}
BODY {
COLOR: #006666; FONT-FAMILY: 宋体; FONT-SIZE: 9pt
}
TABLE {
FONT-FAMILY: 宋体; FONT-SIZE: 9pt
}
.H1 {
FONT-SIZE: 9pt; LINE-HEIGHT: 9pt; align: center
}
TD {
FONT-FAMILY: "宋体", "Arial", "Times New Roman"; FONT-SIZE: 9pt
}
P {
FONT-FAMILY: "宋体", "Arial", "Times New Roman"; FONT-SIZE: 9pt
}
</STYLE>
<SCRIPT language=JavaScript>
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v3.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</SCRIPT>
<META content="Microsoft FrontPage 4.0" name=GENERATOR></HEAD>
<BODY leftMargin=0
topMargin=6 marginheight="0" marginwidth="0">
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 height=70 width=758 bgcolor="#33CCFF">
<TBODY>
<TR bgColor=#99cccc vAlign=center>
<TD align=middle height=60 width=151>
<p align="center"><a href="../index.htm"><img border="0" src="../picindex/roaringlogo.jpg" width="120" height="60"></a></p>
</TD>
<TD bgColor=#00CCFF height=60 width=475>
<p align="center"><img border="0" src="../picindex/coldfirexfs.gif" width="400" height="60">
<TD align=middle bgColor=#cbe4e4 height=60 width=132>
<DIV align=center>
<TABLE border=1
cellPadding=2 cellSpacing=2 height=60 width=68>
<TBODY>
<TR bgColor=#dfeeee>
<TD height=53 bgcolor="#33CCFF">
<DIV align=center>
<SCRIPT language=javascript>
<!---
today = new Date();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
function initArray(){
this.length=initArray.arguments.length
for(var i=0;i<this.length;i++)
this[i+1]=initArray.arguments[i] }
var d=new initArray("<font color=red>星期天","星期一","星期二","星期三","星期四","星期五","<font color=GREEN>星期六");
document.write(today.getYear(),"年","<br>",today.getMonth()+1,"月",today.getDate(),"日</FONT>","<br>",d[today.getDay()+1]," "); //-->
</SCRIPT>
</DIV></TD></TR></TBODY></TABLE></DIV></TD></TR></TBODY></TABLE>
<TABLE align=center background=../picindex/top.gif bgColor=#99cccc border=0
cellPadding=0 cellSpacing=0 height=22 width=758>
<TBODY>
<TR>
<TD height=23 width=25>
<DIV align=center></DIV></TD>
<TD height=23 width=74>
<DIV align=center>
<p align="center"><a href="../index.htm">首页</a></DIV></TD>
<TD height=23 width=18> </TD>
<TD height=23 width=73>
<p align="center"><a href="../article.htm" target="_blank">发表论文</a></TD>
<TD height=23 width=17> </TD>
<TD height=23 width=73>
<DIV align=center><a href="../myprogram.htm" target="_blank">自制软件</a></DIV></TD>
<TD height=23 width=17> </TD>
<TD height=23 width=74>
<DIV align=center><a href="../serialcomm.htm" target="_blank">串口通讯</a></DIV></TD>
<TD height=23 width=17> </TD>
<TD height=23 width=72>
<DIV align=center><a href="../vcandindex.htm" target="_blank">VC/C编程</a></DIV></TD>
<TD height=23 width=17> </TD>
<TD height=23 width=72>
<DIV align=center>网络通讯</DIV></TD>
<TD height=23 width=18> </TD>
<TD height=23 width=74>
<DIV align=center>机器人控制</DIV></TD>
<TD height=23 width=18> </TD>
<TD colSpan=2 height=23>
<DIV align=center><a href="../matlabindex.htm" target="_blank">MATLAB</a></DIV></TD>
<TD height=23 width=29> </TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#ffffff border=0 cellPadding=0 cellSpacing=0
width=758 height="443">
<TBODY>
<TR>
<TD align=middle bgColor=#cbe4e4 vAlign=top width=30 background="../picindex/bck_broad.gif" rowspan="2">
</TD>
<TD align=left vAlign=top
width=4 height="443" rowspan="2"> </TD>
<TD align=middle vAlign=top width=450 rowspan="2">
<TABLE border=0 cellPadding=1 cellSpacing=1 height=220 width=550>
<TBODY>
<tr>
<TD width=543>
<p align="center"><img border="0" src="../picindex/headline1.gif" width="480" height="3">
</TD>
</tr>
<tr>
<TD width=543>
<h1 align="center"><a name="串口调试助手源程序">串口调试助手源程序</a></h1>
<h1 align="center">及编程详细过程(二)</h1>
<p align="center">作者:<a href="mailto:xiaofengstudio@sina.com">龚建伟</a>
2001.8.25</p>
<p align="center">可以任意转载,但必须注明作者和说明来自<a href="http://roaringwind.best.163.com">http://roaringwind.best.163.com</a>,不得作为商用</p>
</TD>
</tr>
<tr>
<TD width="543">
<p align="center"><img border="0" src="../picindex/headline1.gif" width="480" height="3"></TD>
</tr>
<tr>
<TD width=100% valign="top">
<p align="center">目次:</p>
<p align="left" style="margin-top: 5; margin-bottom: 5"><b><font color="#C0C0C0">1.建立项目 </font></b></p>
<p align="left" style="margin-top: 5; margin-bottom: 5"><b><font color="#C0C0C0">2.在项目中插入MSComm控件</font></b><font color="#C0C0C0"><a href="#2.在项目中插入MSComm控件"> </a></font></p>
<p align="left" style="margin-top: 5; margin-bottom: 5"><b><font color="#C0C0C0">3.利用ClassWizard定义CMSComm类控制变量</font></b></p>
<p align="left" style="margin-top: 5; margin-bottom: 5"><b><font color="#C0C0C0">4.在对话框中添加控件 </font></b></p>
<p align="left" style="margin-top: 5; margin-bottom: 5"><b><font color="#C0C0C0">5.添加串口事件消息处理函数OnComm()</font></b></p>
<p align="left" style="margin-top: 5; margin-bottom: 5"><b><font color="#C0C0C0">6.打开和设置串口参数</font></b></p>
<p align="left" style="margin-top: 5; margin-bottom: 5"><b><font color="#C0C0C0">7.发送数据</font></b></p>
<p align="left" style="margin-top: 3; margin-bottom: 3"><a href="#8.发送十六进制字符">8.发送十六进制字符</a></p>
<p align="left" style="margin-top: 3; margin-bottom: 3"><a href="#9.在接收框中以十六进制显示">9.在接收框中以十六进制显示</a></p>
<p align="left" style="margin-top: 3; margin-bottom: 3"><a href="#10.如何设置自动发送">10.如何设置自动发送</a></p>
<p align="left" style="margin-top: 3; margin-bottom: 3"><a href="#11.什么是VARIANT数据类型?如何使用VARIANT数据类型?">11.什么是VARIANT数据类型?如何使用VARIANT数据类型?</a></p>
<p align="left" style="margin-top: 5; margin-bottom: 5"> </p>
<p align="left" style="margin-top: 5; margin-bottom: 5"><b>
</b></p>
<p align="left"><font color="#000000"> 这是<a href="scommassistantcode.htm">串口调试助手源程序及编程详细过程</a>(一)的续篇,首先谢谢朋友们的支持与鼓励。</font></p>
<p align="left"><b><font color="#000000">
这是更新后适合本文的源程序(2001.8.25制作),如果还没有下载源程序,又对本文有兴趣,请
</font>
</b><font color="#000000"><a href="../download/scommtest02.zip">立即下载
<img border="0" src="../pic/down.gif" width="16" height="16">
</a>(当然,你看完本文也可以自己做出来,这个程序是接着上一个做的,如果你没下载前面程序,则没必要再下载了,本程序全部包含)。</font></p>
<p align="left"> </p>
<p align="left" style="margin-top: 3; margin-bottom: 3"><a name="8.发送十六进制字符"><b><font color="#000000">8.发送十六进制字符</font></b></a></p>
<p align="left" style="margin-top: 3; margin-bottom: 3"><font color="#000000">
在主对话框中加入一个复选接钮,ID为IDC_CHECK_HEXSEND Caption: 十六进制发送,再利用ClassWizard为其添加控制变量:m_ctrlHexSend;</font></p>
<p align="left" style="margin-top: 3; margin-bottom: 3"><font color="#000000"> 在ClassView中为SCommTestDlg类添加以下两个PUBLIC成员函数,并输入相应代码;</font></p>
<p align="left" style="margin-top: 3; margin-bottom: 3"><font color="#000000"> </font></p>
<blockquote>
<blockquote>
<p align="left" style="margin-top: 3; margin-bottom: 3"><font color="#000000">//由于这个转换函数的格式限制,在发送框中的十六制字符应该每两个字符之间插入一个空隔<br>
//如:A1 23 45 0B 00 29<br>
//CByteArray是一个动态字节数组,可参看MSDN帮助<br>
int CSCommTestDlg::String2Hex(CString str, CByteArray &senddata)<br>
{<br>
int hexdata,lowhexdata;<br>
int hexdatalen=0;<br>
int len=str.GetLength();<br>
senddata.SetSize(len/2);<br>
for(int i=0;i<len;)<br>
{<br>
char lstr,hstr=str[i];<br>
if(hstr==' ')<br>
{<br>
i++;<br>
continue;<br>
}<br>
i++;<br>
if(i>=len)<br>
break;<br>
lstr=str[i];<br>
hexdata=ConvertHexChar(hstr);<br>
lowhexdata=ConvertHexChar(lstr);<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -