亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? serialcomm.asp

?? Visual+C++網(wǎng)絡(luò)通信協(xié)議分析
?? ASP
?? 第 1 頁(yè) / 共 3 頁(yè)
字號(hào):
<%@ Language=VBScript %>
<!-- #include file="../../ArticleAccess.asp" -->
<!-- #include file="../../GetAccessCount.asp" -->
<%
 PrintArticleAccessCount 45
 AccessArticle  45
 %>
 <html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title> Serial Communication in Windows </title>
</head>

<body>

<p align="center">&nbsp;</p>
<p align="center"><font face="Verdana" size="2"><b>[<u> </u></b></font><font size="2" face="Verdana"><b><u>Serial Communication in Windows</u></b></font><font face="Verdana" size="2"><b><u>
</u>]<br>
</b><a href="mailto:ashishdhar@hotmail.com"><i>ashish dhar</i></a></font></p>
<table borderColor="#ffffff" height="4318" cellSpacing="0" borderColorDark="#ffffff" width="99%" borderColorLight="#ffffff" border="1">
  <tbody>
    <tr>
      <td vAlign="top" width="11%" bgColor="#538ab3" height="4314">
        <div align="justify">
          <table borderColor="#538ab3" height="4654" cellSpacing="4" borderColorDark="#000000" width="100%" borderColorLight="#538ab3" border="4">
            <tbody>
              <tr>
                <td vAlign="top" borderColorLight="#538ab3" width="100%" bgColor="#538ab3" borderColorDark="#538ab3" height="4650"><br>
                  <br>
                  <br>
                  <br>
                  <br>
                  <br>
                  <br>
                  <br>
                  <br>
                  <br>
                  <br>
                  <br>
                  <br>
                  <br>
                  <br>
                  <br>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </td>
      <td vAlign="top" borderColorLight="#e8e9e2" width="69%" bgColor="#ffffff" borderColorDark="#f0f0f0" height="4314">&nbsp;

<p><font size="2" face="Verdana"><a href="../Source.zip">Source code</a><b><br>
<br>
</b>This article is meant to give you a jump start on doing serial communication
in Windows (NT family). The article will provide a class called
CSerialCommHelper which you can use directly to do serial communication in your
application. The class that is provided here with this article does uses
overlapped IO. You donot need to know much about serial communication or
overlapped IO for this article. However, you need to know some about the
synchronization objects like Events and some Windows APIs like
WaitForSingleObject and WaitForMultipleObject etc. Also some basic understanding
of windows threads is required - like thread creation and <i>termination</i>.</font></p>
<p><font size="2" face="Verdana"><b>Introduction<br>
</b>In order for your computer to be able to do serial communication, computer
has to have a serial port. Most of the computers have at least one serial port
also known as COM port ( communication port ) and are generally called COM1 COM2
etc. Then there are the device drivers for the serial ports. If you think it
over, all you that you need to do in serial communication is either send data or
receive data. In other words, you are doing input/output (IO) to the serial
port. The same IO is done with disk based files. Hence there is no surprise that
the APIs for reading and writing to a file apply to serial ports as well. When
you send data to the serial port its in terms of bytes but when it leaves the
serial port it is in the form of bits. Similarly, when the data arrives at the
serial port, its in bit format and when you get data you get it in bytes.&nbsp;<br>
Without any further discussion lets get started.<br>
<br>
<b>Opening the COM port<br>
</b>The first and the foremost step in doing a serial communication is to open
the desired port. Lets say you have your device hooked to COM1 you can open the
COM port using following API:</font></p>
<table border="0" cellspacing="1" width="100%" bgcolor="#EEE8EE">
  <tr>
    <td width="100%">
      <pre><font size="2">HANDLE m_hCommPort = ::<font color="#0000FF">CreateFile</font>(	szPortName,
					GENERIC_READ|GENERIC_WRITE,//access ( read and write)
					0,	//(share) 0:cannot share the COM port						
					0,	//security  (None)				
					OPEN_EXISTING,// creation : open_existing
					FILE_FLAG_OVERLAPPED,// we want overlapped operation
					0// no templates file for COM port...
					);</font></pre>
    </td>
  </tr>
</table>
<p><font size="2" face="Verdana">The third fifth and seventh parameters have to be what they
are in the above example by law. We want to open the file ( the COM port ) in an
overlapped fashion - that's why the sixth param is FILE_FLAG_OVERLAPPED. We will
get into the details of overlapped IO a bit later. As you must have guessed from
the name , CreateFile() API can be used to create a file (disk based) and also
it can be used to open an existing file.&nbsp;<br>
To Windows a serial port or a disk based file both are IO devices . So, in order
to open an existing file ( serial port ) all we need to know the name of the
device ( COM1) and pass the creation flags as OPEN_EXISTING.<br>
If a COM port is opened successfully, the API returns handle to the com port
just like a handle to a file. However, if the system could not open the COM
port, it would return INVALID_HANDLE_VALUE . And you can get the reason by
calling GetLastError(). One of the common errors while opening a COM port is
that the COM port is already opened by some other application and in that case
you would get ERROR_ACCESS_DENIED (5). Similarly if you by mistake opened a COM
port that doesnot exist , you would get ERROR_FILE_NOT_FOUND&nbsp; as the last
error.<br>
<u>Note: Remember not to do make any function calls (like ASSERT) before calling
GetLastError() or you would get 0</u>.<u><br>
</u>Once you have opened the com port all you need to do now is to start using
it.<br>
<br>
<b>Reading and Writing<br>
</b>Now, once you have a com port open, you may want to send&nbsp; some data to
the connected device. For example, lets say you want to send &quot;Hello&quot;
to the device(e.g., another PC). When you want to send the data across the
serial port, you need to write to the serial port just like you would write to a
file. You would use following API:<br>
</font></p>
<table border="0" cellspacing="1" width="100%">
  <tr>
    <td width="100%" bgcolor="#C0C0C0"><font size="2" face="Verdana">iRet = WriteFile (m_hCommPort,data,dwSize,&amp;dwBytesWritten  ,&amp;ov);&nbsp;&nbsp;&nbsp;&nbsp;</font></td>
  </tr>
</table>
<p><font size="2" face="Verdana">where data contains &quot;Hello&quot; .&nbsp;<br>
Lets say in response to your &quot;Hello&quot; , the device sends you
&quot;Hi&quot; . So you need to read the data. Again ,you would&nbsp; use
following API:</font></p>
<table border="0" cellspacing="1" width="100%">
  <tr>
    <td width="100%" bgcolor="#C0C0C0"><font size="2" face="Verdana">abRet = ::ReadFile(m_hCommPort,szTmp
      ,sizeof(szTmp ),&amp;dwBytesRead,&amp;ovRead) ;</font></td>
  </tr>
</table>
<p><font size="2" face="Verdana"><i>For now do not try to understand everything.We will get to
all this later.<br>
</i>All this sounds very simple. Right? <br>
Now lets start digging into issues. </font></p>
<p><font size="2" face="Verdana"><b>Issues with serial communication</b><br>
Just now I said, in response to your &quot;Hello&quot;, the device may send you
&quot;Hi&quot; back and you would like to read that. But the problem here is
that you don't know when the device is going to respond? Or will it ever
respond? When should you start to read from the port. One option is that as soon
as you made call to WriteFile, you make call to ReadFile . If no data is there
you need to make read again later on. This leads to what is called polling. You
keep polling the port for data. This model does not really&nbsp; seem to be a
good one. It would be nice if somehow you were notified by the system when data
has arrived and only then would you make call to ReadFile. This is event driven
approach and fits well into Windows programming. And good news is that such a
model is possible . <br>
<br>
<br>
<br>
Another issue with the serial communication is that since it always occurs
between two devices, the two devices need to agree on how they talk to each
other. Each side needs to follow certain protocols to conduct business. Since
its the serial port that actually carries out the communication, we need to
configure the serial port. There is an API available for exact same purpose.
Following is the API:</font></p>
<table border="0" cellspacing="1" width="100%" bgcolor="#C0C0C0">
  <tr>
    <td width="100%"><font size="2" face="Verdana">SetCommState ( HANDLE hFile, LPDCB lpDCB)</font></td>
  </tr>
</table>
<p><font size="2" face="Verdana">The first parameter is the handle to COM port and the second
paramter is what is called device control block (DCB) . The DCB is a struct
defined in winbase.h and has 28 data members. For example, we need to specify
baud rate at which the COM port operates, you need to set the <b>BaudRate </b>member
of the struct . Baud rate is usual 9600 (bps) . But the two devices have to use
the same baud rate to conduct business. Similarly if you want to use parity you
need to set <b>Parity</b> member of the struct. Again the two devices have to
use same parity. Some of the data members are reserved and have to be 0. I have
found it easier to get the current DCB struct and then set those members which
we are interested in changing. Following code gets the current dcb and sets some
of the fields:<br>
<br>
</font></p>
<table border="0" cellspacing="1" width="100%" bgcolor="#EEE8EE">
  <tr>
    <td width="100%">
      <pre><font size="2" face="Verdana">DCB dcb = {0};
dcb.DCBlength = sizeof(DCB);

if (!::<font color="#0000FF">GetCommState </font>(m_hCommPort,&amp;dcb))
{
	TRACE ( &quot;CSerialCommHelper : Failed to Get Comm State Reason: %d&quot;,GetLastError());
	return E_FAIL;
}

dcb.BaudRate	= dwBaudRate;
dcb.ByteSize	= byByteSize;
dcb.Parity		= byParity;
if ( byStopBits == 1 )
	dcb.StopBits	= ONESTOPBIT;
else if (byStopBits == 2 ) 
	dcb.StopBits	= TWOSTOPBITS;
else 
	dcb.StopBits	= ONE5STOPBITS;


if (!::<font color="#0000FF">SetCommState</font> (m_hCommPort,&amp;dcb))
{
	ASSERT(0);

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲美女在线一区| 亚洲一区二区五区| 欧日韩精品视频| 久久99国产精品麻豆| 亚洲色图第一区| 欧美精品一区二区久久久| 日本韩国欧美三级| 国内不卡的二区三区中文字幕| 亚洲精品一二三| 久久久精品免费网站| 欧美精品粉嫩高潮一区二区| 国产99久久久精品| 美女性感视频久久| 一区二区三区四区视频精品免费| 久久青草国产手机看片福利盒子| 色哟哟国产精品| 国产成a人亚洲| 久久国产精品无码网站| 亚洲午夜国产一区99re久久| 欧美激情一区二区| 久久只精品国产| 欧美一级二级在线观看| 欧美性大战久久| 99在线精品视频| 丰满白嫩尤物一区二区| 激情综合色综合久久综合| 午夜电影网一区| 亚洲一区中文在线| 一区二区激情视频| 亚洲特黄一级片| 亚洲天堂久久久久久久| 国产欧美综合色| 国产人成亚洲第一网站在线播放| 欧美成人精品二区三区99精品| 欧美日本国产视频| 精品视频在线免费| 精品视频1区2区| 欧美日韩一区视频| 欧美日韩免费一区二区三区视频 | 精品一区中文字幕| 日韩精品亚洲一区二区三区免费| 一区二区三区四区在线播放| 亚洲少妇30p| 亚洲色图20p| 一区二区三区在线视频观看58 | 粉嫩av一区二区三区粉嫩| 国产综合色在线| 国产成人免费在线观看| 国产aⅴ精品一区二区三区色成熟| 国产又粗又猛又爽又黄91精品| 黄色精品一二区| 精品亚洲欧美一区| 国产福利一区在线观看| 国产福利一区在线| 99久久99久久精品免费观看| 99在线精品视频| 欧美综合色免费| 欧美高清视频在线高清观看mv色露露十八 | 欧美羞羞免费网站| 欧美日韩精品三区| 欧美一区二区三区白人| 精品久久国产字幕高潮| 国产亚洲成av人在线观看导航| 欧美国产日韩在线观看| 日韩一区有码在线| 亚洲国产精品自拍| 麻豆国产欧美一区二区三区| 黄色资源网久久资源365| 成人中文字幕电影| 色天天综合色天天久久| 91精品国产高清一区二区三区蜜臀| 欧美一区二区在线免费观看| 久久久久久亚洲综合影院红桃| 国产精品超碰97尤物18| 亚洲大片精品永久免费| 国产一区二区三区av电影| 成人高清视频免费观看| 欧美日韩成人综合天天影院 | 在线区一区二视频| 欧美伦理电影网| 26uuu国产一区二区三区| 国产精品成人一区二区艾草| 亚洲123区在线观看| 国产一区二区精品久久99| 色天天综合久久久久综合片| 欧美一级精品大片| 亚洲欧洲日韩综合一区二区| 日韩和欧美一区二区三区| 成人免费毛片高清视频| 欧美日韩精品电影| 亚洲国产精品99久久久久久久久| 亚洲综合久久av| 国产麻豆精品久久一二三| 91黄色免费版| 国产亚洲综合在线| 亚州成人在线电影| 不卡欧美aaaaa| 日韩欧美色电影| 一区二区三区国产精华| 国产麻豆成人精品| 91精品国产一区二区人妖| 国产精品美女久久福利网站| 日韩av中文字幕一区二区三区| 99久久精品99国产精品| 精品理论电影在线| 亚洲bt欧美bt精品| 91一区在线观看| 国产日韩成人精品| 轻轻草成人在线| 欧美优质美女网站| 国产精品成人网| 国产成人免费9x9x人网站视频| 91精品久久久久久久91蜜桃| 亚洲精品日产精品乱码不卡| 国产精品99久久久久久似苏梦涵 | 极品尤物av久久免费看| 欧美午夜精品久久久| 中文字幕一区二区三区精华液| 精品一区二区综合| 欧美一卡2卡3卡4卡| 亚洲一区二区欧美日韩| 色94色欧美sute亚洲线路一久| 国产片一区二区三区| 久久精品国产免费| 国产精品免费视频网站| 韩国三级中文字幕hd久久精品| 7777精品伊人久久久大香线蕉完整版 | 久久99精品国产.久久久久久 | 国产成人a级片| 精品国产一区二区国模嫣然| 日韩精品电影在线| 欧美精品乱码久久久久久按摩| 亚洲一区二区在线免费看| 色婷婷亚洲精品| 樱花草国产18久久久久| 91在线观看一区二区| 中文字幕中文字幕一区二区| 顶级嫩模精品视频在线看| 国产日韩精品久久久| 国产成人免费网站| 国产精品理伦片| 成人免费观看视频| 中文字幕一区在线观看视频| 成人av网址在线| 亚洲国产精品v| 91老司机福利 在线| 亚洲天堂精品视频| 欧美综合久久久| 亚洲成年人影院| 欧美一区二区三区播放老司机| 麻豆91免费观看| 久久精品视频在线免费观看| 国产成人啪免费观看软件| 国产精品你懂的在线欣赏| av一区二区久久| 亚洲国产精品麻豆| 欧美mv日韩mv亚洲| 粉嫩一区二区三区在线看| 国产精品美女www爽爽爽| 色丁香久综合在线久综合在线观看| 伊人开心综合网| 欧美一区二区三区影视| 国产激情偷乱视频一区二区三区| 中文字幕精品一区 | 精品剧情在线观看| 国产99一区视频免费| 亚洲免费观看高清| 337p亚洲精品色噜噜| 国产精品一线二线三线精华| 国产精品免费网站在线观看| 欧美亚男人的天堂| 精品一区二区三区欧美| 中文字幕一区二区日韩精品绯色| 一本到一区二区三区| 热久久久久久久| 中文字幕第一区综合| 在线观看成人小视频| 蜜臀91精品一区二区三区| 中文字幕精品一区| 欧美狂野另类xxxxoooo| 国产91清纯白嫩初高中在线观看| 一级精品视频在线观看宜春院| 日韩三级精品电影久久久| 成人国产在线观看| 日本中文字幕一区二区视频| 久久精品免费在线观看| 欧美天堂一区二区三区| 经典三级在线一区| 亚洲午夜一二三区视频| 久久众筹精品私拍模特| 欧洲人成人精品| 国产福利视频一区二区三区| 亚洲自拍与偷拍| 中文字幕乱码日本亚洲一区二区 | 亚洲综合自拍偷拍| 久久久久久久久久电影| 欧美老肥妇做.爰bbww| 成人av资源下载| 久久精品国产一区二区| 亚洲制服丝袜av|