?? 串口助手程序編程過程2.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 + -