?? mscomm控件使用詳解-.htm
字號(hào):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0056)http://www.51kaifa.com/zxyd/read_z.php?ID=951&BigClass=6 -->
<HTML><HEAD><TITLE>MSComm控件使用詳解- 無(wú)憂(yōu)電子開(kāi)發(fā)網(wǎng)-在線(xiàn)閱讀</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="" name=Keywords><LINK href="MSComm控件使用詳解-_files/css.css"
type=text/css rel=stylesheet>
<SCRIPT language=JavaScript>function fontzoom(size){ document.getElementById('fontzoom').style.fontSize=size+'px'}</SCRIPT>
<SCRIPT language=Javascript>document.oncontextmenu=new Function("event.returnValue=false");document.onselectstart=new Function("event.returnValue=false");</SCRIPT>
<!-- 限制右鍵復(fù)制 -->
<META content="MSHTML 6.00.3790.1830" name=GENERATOR></HEAD>
<BODY topMargin=10 marginheight="10" marginwidth="10">
<TABLE cellSpacing=0 cellPadding=0 width=760 align=center border=0>
<TBODY>
<TR>
<TD width="100%">
<TABLE height=2 cellSpacing=0 cellPadding=0 width="100%" bgColor=#808080
border=0>
<TBODY>
<TR>
<TD width="100%"></TD></TR></TBODY></TABLE>
<TABLE height=80 cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD align=middle width=186><A href="http://www.51kaifa.com/"><IMG
height=65 src="MSComm控件使用詳解-_files/logo.jpg" width=186
border=0></A></TD>
<TD align=middle width=574>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD vAlign=bottom width=120><A
href="http://www.51kaifa.com/zxyd/"><IMG height=67
src="MSComm控件使用詳解-_files/logo_zxyd.gif" width=120
border=0></A></TD>
<TD width=454>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD align=middle width="100%" colSpan=3 height=19>
<TABLE cellSpacing=0 cellPadding=0 width="100%"
border=0>
<TBODY>
<TR>
<TD class=xyzx_top align=middle width="100%"
height=19><A
href="http://www.51kaifa.com/hyxw">綜合資訊</A> <A
href="http://www.51kaifa.com/jswz">技術(shù)文章</A> <A
href="http://www.51kaifa.com/yyfa">原文閱讀</A> <A
href="http://www.51kaifa.com/shop">在線(xiàn)商城</A> <A
href="http://www.51kaifa.com/zxxz">下載專(zhuān)區(qū)</A> <A
href="http://www.51kaifa.com/datasheet">DATASHEET</A>
<A href="http://www.51kaifa.com/bbs">技術(shù)論壇</A> <A
href="http://www.51kaifa.com/MenberInfo">商務(wù)頻道</A>
</TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD width=47
background=MSComm控件使用詳解-_files/R_list_3.gif><IMG
height=54 src="MSComm控件使用詳解-_files/R_list_2.gif"
width=48 border=0></TD>
<TD class=xyzx_top_shadow width=402
background=MSComm控件使用詳解-_files/R_list_3.gif>
<P style="LINE-HEIGHT: 150%"><A class=xyzx_top2
href="http://www.51kaifa.com/zxyd/list.php?BigClass=2">電子書(shū)籍</A><FONT
color=#ffffff> | </FONT><A class=xyzx_top2
href="http://www.51kaifa.com/zxyd/list.php?BigClass=4">網(wǎng)絡(luò)文庫(kù)</A><FONT
color=#ffffff> | </FONT><A class=xyzx_top2
href="http://www.51kaifa.com/zxyd/list.php?BigClass=3">技術(shù)資料</A><FONT
color=#ffffff> | </FONT><A class=xyzx_top2
href="http://www.51kaifa.com/zxyd/list.php?BigClass=11">嵌入式系統(tǒng)</A><FONT
color=#ffffff> | </FONT><A class=xyzx_top2
href="http://www.51kaifa.com/zxyd/list.php?BigClass=6">單片機(jī)專(zhuān)題</A><BR><A
class=xyzx_top2
href="http://www.51kaifa.com/zxyd/list.php?BigClass=10">DSP專(zhuān)題</A><FONT
color=#ffffff> | </FONT><A class=xyzx_top2
href="http://www.51kaifa.com/zxyd/list.php?BigClass=8">EDA/PLD專(zhuān)題</A><FONT
color=#ffffff> | </FONT><A class=xyzx_top2
href="http://www.51kaifa.com/zxyd/list.php?BigClass=7">電子制作專(zhuān)題</A><FONT
color=#ffffff> | </FONT><A class=xyzx_top2
href="http://www.51kaifa.com/zxyd/list.php?BigClass=12">電源技術(shù)專(zhuān)題</A><FONT
color=#ffffff> | </FONT></P></TD>
<TD width=5><IMG height=54 src="" width=5
border=0></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE height=4 cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD width="100%"></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="98%" align=center border=0>
<TBODY>
<TR>
<TD align=middle width="5%" height=25><IMG
src="MSComm控件使用詳解-_files/R_url.jpg"></TD>
<TD width="95%">所在的位置:<A href="http://www.51kaifa.com/">首頁(yè)</A></A> →
<A href="http://www.51kaifa.com/zxyd/">在線(xiàn)閱讀</A></A> → <A
href="http://www.51kaifa.com/zxyd/list.php?BigClass=6">單片機(jī)專(zhuān)題</A> →
<A href="http://www.51kaifa.com/zxyd/read.php?ID=166">串口通信專(zhuān)輯</A> →
<FONT color=#ff9900>正文</FONT> </TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=760 align=center border=0>
<TBODY>
<TR>
<TD width="100%" bgColor=#808080 colSpan=3 height=1></TD></TR>
<TR>
<TD vAlign=top width=590>
<TABLE cellSpacing=0 cellPadding=0 width="94%" align=center
border=0>
<TBODY>
<TR>
<TD align=middle width="100%"><FONT
color=#05006c><B>MSComm控件使用詳解</B></FONT></TD></TR>
<TR>
<TD width="100%" height=6></TD></TR>
<TR>
<TD align=middle width="100%" height=18>
<TABLE style="BORDER-TOP: #666666 1px solid" height=2
cellSpacing=1 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD align=middle width="100%"
bgColor=#dce9fc></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD width="100%" height=6></TD></TR>
<TR>
<TD class=p16 id=fontzoom style="LINE-HEIGHT: 1.5" vAlign=top
width="100%" height=300><BR><!--畫(huà)中畫(huà)廣告開(kāi)始-->
<TABLE cellSpacing=0 cellPadding=0 align=left border=0>
<TBODY>
<TR>
<TD><!-- 廣告位 -->
<TABLE cellSpacing=0 cellPadding=0 width="99%"
align=center background="" border=0>
<TBODY>
<TR>
<TD vAlign=top align=middle><A
href="http://www.51kaifa.com/upload/do_page/1119369847.html"
target=_blank><IMG height=50
src="MSComm控件使用詳解-_files/1119368683.gif" width=100
border=0></A></TD></TD></TR></TBODY></TABLE><!-- $sign哪個(gè)頁(yè)面$digit位置$way等h不循環(huán)TR;X循環(huán)TR;$num顯示個(gè)數(shù) --></TD></TR></TBODY></TABLE><!--畫(huà)中畫(huà)廣告結(jié)束-->MSComm
控件通過(guò)串行端口傳輸和接收數(shù)據(jù),為應(yīng)用程序提供串行通訊功能。MSComm控件在串口編程時(shí)非常方便,程序員不必去花時(shí)間去了解較為復(fù)雜的API函數(shù),而且在VC、VB、Delphi等語(yǔ)言中均可使用。
Microsoft Communications
Control(以下簡(jiǎn)稱(chēng)MSComm)是Microsoft公司提供的簡(jiǎn)化Windows下串行通信編程的ActiveX控件,它為應(yīng)用程序提供了通過(guò)串行接口收發(fā)數(shù)據(jù)的簡(jiǎn)便方法。具體的來(lái)說(shuō),它提供了兩種處理通信問(wèn)題的方法:一是事件驅(qū)動(dòng)(Event-driven)方法,一是查詢(xún)法。
<P class=style27 align=left><A>1.MSComm控件兩種處理通訊的方式 </A></P>
<P class=style27
align=left> MSComm控件提供下列兩種處理通訊的方式:事件驅(qū)動(dòng)方式和查詢(xún)方式。<BR><BR> 1.1
事件驅(qū)動(dòng)方式 </P>
<P class=style27
align=left> 事件驅(qū)動(dòng)通訊是處理串行端口交互作用的一種非常有效的方法。在許多情況下,在事件發(fā)生時(shí)需要得到通知,例如,在串口接收緩沖區(qū)中有字符,或者
Carrier Detect (CD) 或 Request To Send (RTS)
線(xiàn)上一個(gè)字符到達(dá)或一個(gè)變化發(fā)生時(shí)。在這些情況下,可以利用 MSComm 控件的 OnComm
事件捕獲并處理這些通訊事件。OnComm 事件還可以檢查和處理通訊錯(cuò)誤。所有通訊事件和通訊錯(cuò)誤的列表,參閱
CommEvent
屬性。在編程過(guò)程中,就可以在OnComm事件處理函數(shù)中加入自己的處理代碼。這種方法的優(yōu)點(diǎn)是程序響應(yīng)及時(shí),可靠性高。每個(gè)MSComm
控件對(duì)應(yīng)著一個(gè)串行端口。如果應(yīng)用程序需要訪(fǎng)問(wèn)多個(gè)串行端口,必須使用多個(gè) MSComm 控件。 </P>
<P class=style27 align=left>1.2 查詢(xún)方式 </P>
<P class=style27
align=left> 查詢(xún)方式實(shí)質(zhì)上還是事件驅(qū)動(dòng),但在有些情況下,這種方式顯得更為便捷。在程序的每個(gè)關(guān)鍵功能之后,可以通過(guò)檢查
CommEvent
屬性的值來(lái)查詢(xún)事件和錯(cuò)誤。如果應(yīng)用程序較小,并且是自保持的,這種方法可能是更可取的。例如,如果寫(xiě)一個(gè)簡(jiǎn)單的電話(huà)撥號(hào)程序,則沒(méi)有必要對(duì)每接收一個(gè)字符都產(chǎn)生事件,因?yàn)槲ㄒ坏却邮盏淖址钦{(diào)制解調(diào)器的“確定”響應(yīng)。
</P>
<P class=style27 align=left>2.MSComm 控件的常用屬性 <BR><BR>MSComm
控件有很多重要的屬性,但首先必須熟悉幾個(gè)屬性。 <BR><BR>CommPort 設(shè)置并返回通訊端口號(hào)。
<BR><BR>Settings 以字符串的形式設(shè)置并返回波特率、奇偶校驗(yàn)、數(shù)據(jù)位、停止位。
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -