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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? serialcomm.asp

?? Visual+C++網絡通信協議分析
?? ASP
?? 第 1 頁 / 共 3 頁
字號:
      <pre>threadFn...

	WaitCommEvent(m_hCommPort,&amp;dwEventMask, &amp;ov) ;
	if ( WaitForSingleObject(ov.hEvent,INFINITE) == WAIT_OBJECT_0)
	{	
		char szBuf[100];
		memset(szBuf,0,sizeof(szBuf));
		do
		{
			ReadFile( hPort,szBuf,sizeof(szBuf),&amp;dwBytesRead,&amp;ov);
		}while (dwBytesRead &gt; 0 );	
	}	</pre>
    </td>
  </tr>
</table>
<p><font size="2" face="Verdana">ReadFile API has following signature:<br>
</font></p>
<table border="0" cellspacing="1" width="100%" bgcolor="#DADADA">
  <tr>
    <td width="100%">
      <pre><font face="Verdana" size="2">BOOL ReadFile( HANDLE<i> <a class="synParam" onclick="showTip(this)" href>hFile</a></i>, // handle to file 
</font>		<font face="Verdana" size="2">LPVOID<i> <a class="synParam" onclick="showTip(this)" href>lpBuffer</a></i>, // data buffer 
		DWORD<i> <a class="synParam" onclick="showTip(this)" href>nNumberOfBytesToRead</a></i>, // number of bytes to read 
		LPDWORD<i> <a class="synParam" onclick="showTip(this)" href>lpNumberOfBytesRead</a></i>, // number of bytes read 
		LPOVERLAPPED<i> <a class="synParam" onclick="showTip(this)" href>lpOverlapped</a></i> // overlapped buffer );</font></pre>
    </td>
  </tr>
</table>
<p><font size="2" face="Verdana"><br>
<br>
The first parameter is as usual the com port, the last parameter is the
overlapped structure. Again we need to create a manual reset event and pass the
overlapped structure to the ReadFile function. Again if you issue a read for say
10 bytes and there is no data available , ReadFile will return FALSE and
GetLastError() will return ERROR_IO_PENDING and the system will set the
overlapped event when the overlapped operation(read ) completes.&nbsp;<br>
As you can see ReadFile returns dwBytesRead which as is clear returns the number
of bytes read. If there are no bytes remaining, the dwBytesRead will return 0.
Lets say there are 11 bytes that have arrived and you read 10&nbsp; characters
in the first go in while loop. In the first go 10 characters will be returned in
dwBytesRead. In the second go with while loop, the dwBytesRead will return 1.
Now in the third go the dwBytesRead will return 0 and you will break out of the
while loop. This allows you to read all the data. In this approach ,if you
noticed,we never really took advantage of the overlapped structure that we
passed to the ReadFile function but we still need to pass it because we opened
the COM port in Overlapped manner.<br>
<br>
<br>
And finally when you want to send data to other device, you need to call
WriteFile. WriteFile is not even worth discussing.<br>
<br>
<br>
There is one more thing that needs to be taken into account before we move on
and that is communication <b>timeouts</b>. Its important to set the timeout to
proper values for things to work. The API to do so is:&nbsp;
</font></p>
<p><font size="2" face="Verdana">SetCommTimeouts ( HANDLE hCommPort,
LPCOMMTIMEOUTS lpCommTimeOuts)<br>
<br>
<br>
&nbsp;COMTIMEOUTS is a structure with following members:<br>
</font></p>
<table border="0" cellspacing="1" width="70%" bgcolor="#DADADA">
  <tr>
    <td width="100%">
      <pre class="syntax"><font face="Verdana" size="2">typedef struct _COMMTIMEOUTS {  
  DWORD <a class="synParam" onclick="showTip(this)" href>ReadIntervalTimeout</a>; 
  DWORD <a class="synParam" onclick="showTip(this)" href>ReadTotalTimeoutMultiplier</a>; 
  DWORD <a class="synParam" onclick="showTip(this)" href>ReadTotalTimeoutConstant</a>; 
  DWORD <a class="synParam" onclick="showTip(this)" href>WriteTotalTimeoutMultiplier</a>; 
  DWORD <a class="synParam" onclick="showTip(this)" href>WriteTotalTimeoutConstant</a>; 
} COMMTIMEOUTS,*LPCOMMTIMEOUTS; </font></pre>
    </td>
  </tr>
</table>
<p><font size="2" face="Verdana">&nbsp;&nbsp;
<br>
For a description of all these fields consult MSDN documentation. But one thing
I want to point out is this:&nbsp;<br>
&quot;...A value of MAXDWORD, combined with zero values for both the <b>ReadTotalTimeoutConstant</b>
and <b>ReadTotalTimeoutMultiplier</b> members, specifies that the read operation
is to return immediately with the characters that have already been received,
even if no characters have been received...&quot;<br>
This is exactly what we want . We do NOT want the ReadFile to get stuck if there
is no data available as we will know with WaitCommEvent() API.<br>
and also &quot;...A value of zero for both the <b>WriteTotalTimeoutMultiplier</b>
and <b>WriteTotalTimeoutConstant</b> members indicates that total time-outs are
not used for write operations...&quot; is what we want. In short we need to do
this:</font></p>
<table border="0" cellspacing="1" width="70%" bgcolor="#DADADA">
  <tr>
    <td width="100%">
      <pre>		COMMTIMEOUTS timeouts;
		timeouts.ReadIntervalTimeout		= MAXDWORD; 
		timeouts.ReadTotalTimeoutMultiplier	= 0;
		timeouts.ReadTotalTimeoutConstant	= 0;
		timeouts.WriteTotalTimeoutMultiplier	= 0;
		timeouts.WriteTotalTimeoutConstant	= 0;
		
		if (!SetCommTimeouts(m_hCommPort, &amp;timeouts))
		{
			ASSERT(0);
			TRACE ( &quot;CSerialCommHelper :  Error setting time-outs. %d&quot;,GetLastError());
			return E_FAIL;
		}
</pre>
    </td>
  </tr>
</table>
<p><font size="2" face="Verdana"><br>
Now we have discussed almost everything that needs to be discussed for the sake
of this article.<br>
<b><br>
Putting it all together&nbsp;<br>
</b>All this I have put together in a form of two classes:&nbsp;<br>
The main class is <b>CSerialCommHelper</b> - the main class that does performs
all the communication .<br>
The helper class called <b>CSerialBuffer</b> that is an internal buffer used by
the CSerialCommHelper.<br>
<br>
Here is the main API of the <b>CSerialCommHelper:<br>
</b></font></p>
<table border="0" cellspacing="1" width="70%" bgcolor="#DADADA">
  <tr>
    <td width="100%">
      <pre><font face="Verdana" size="2">inline bool IsInputAvailable()
inline bool IsConnection() {return m_abIsConnected ;}
inline void SetDataReadEvent() { SetEvent ( m_hDataRx ); }
HRESULT Read_N (std::string&amp; data,long alCount,long alTimeOut);
HRESULT Read_Upto (std::string&amp; data,char chTerminator ,long* alCount,long alTimeOut);
HRESULT ReadAvailable(std::string&amp; data);
HRESULT Write (const char* data,DWORD dwSize);
HRESULT Init(std::string szPortName, DWORD dwBaudRate,BYTE byParity,BYTE byStopBits,BYTE byByteSize);
HRESULT Start();
HRESULT Stop();
HRESULT UnInit();</font></pre>
    </td>
  </tr>
</table>
<p><font size="2" face="Verdana">and the interface for CSerialBuffer is :<br>
</font></p>
<table border="0" cellspacing="1" width="70%" bgcolor="#DADADA">
  <tr>
    <td width="100%">
      <pre><font size="2" face="Verdana">inline void LockBuffer(); 
inline void UnLockBuffer();
void AddData( char ch ) ;
void AddData( std::string&amp; szData ) ;
void AddData( std::string&amp; szData,int iLen ) ;
void AddData( char *strData,int iLen ) ;
std::string GetData() ;
void Flush();
long Read_N( std::string &amp;szData,long alCount,HANDLE&amp; hEventToReset);
bool Read_Upto( std::string &amp;szData,char chTerm,long &amp;alBytesRead ,HANDLE&amp; hEventToReset);
bool Read_Available( std::string &amp;szData,HANDLE &amp; hEventToReset);
inline long GetSize() ;
inline bool IsEmpty() ;</font></pre>
    </td>
  </tr>
</table>
<p><font size="2" face="Verdana">&nbsp;</font></p>
<p><font size="2" face="Verdana">Here is the logic and working behind the
classes:</font></p>
<p><font size="2" face="Verdana">First of let me show you how to use the class.
In your application create an object of CSerialCommHelper like this:</font></p>
<p><font size="2" face="Verdana">CSerialCommHelper m_theCommPort;<br>
<br>
Call m_theCommPort.Init() passing in the necessary information. If you want you
can use default values.<br>
Next call m_theCommPort.Start()&nbsp;</font></p>
<p><font size="2" face="Verdana">If you want to get notification about when the
some data is available you can get the kernel event object to wait on by
calling&nbsp; m_theCommPort.GetWaitForEvent().</font></p>
<p><font size="2" face="Verdana">What CSerialCommHelper does is that on call to
Init(), it opens the specified COM port and also starts a thread. The thread
starts &quot;listening&quot; for any incoming data and once the data has been
received it reads&nbsp; all the data into a local buffer which is of type
CSerialBuffer . Once its done reading all the data it sets the event in case you
want to get the notification. Now you have three options </font></p>
<ul>
  <li><font size="2" face="Verdana">read all the data by calling ReadAvailable()
    which reads all the data . </font></li>
  <li><font size="2" face="Verdana">read up to some character by calling
    Read_Upto and passing character upto which you want to read.</font></li>
  <li><font size="2" face="Verdana">read N character calling Read_N passing the
    numbers to be read. </font></li>
</ul>
<p><font size="2" face="Verdana">There is one more thing that needs to be paid
attention. If you want to read 10 characters&nbsp; but there are only 5
characters in the local buffer, the read_N makes a blocking call and waits for
the timeout passed as the last parameter .&nbsp; Same is true for Read_Upto.</font></p>
<p><font size="2" face="Verdana">One more thing. If there are 10 characters in
the local buffer but you made a call to Read_N() for 5 characters you will be
returned first 5 characters. If you made a next call Read_N() for 5 characters
again, it would returned next 5 characters.<br>
<br>
Thats all there is to it. </font></p>
<p><font size="2" face="Verdana">If you think I have left something please feel
free to email me at <a href="mailto:ashishdhar@hotmail.com">ashishdhar@hotmail.com</a>
<br>
<br>
&nbsp;</font></p>

      </td>
    </tr>
  </tbody>
</table>
<hr width="70%" color="#000000">
<p align="center"><font face="Verdana" size="1">copyright 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一区二区三区在线观看视频| 日韩免费高清视频| 国产精品中文字幕一区二区三区| 亚洲精品国产无套在线观| 欧美国产日韩亚洲一区| 国产亚洲人成网站| 中文字幕国产一区| 国产精品三级av在线播放| 中文字幕精品一区二区三区精品| 国产人妖乱国产精品人妖| 中文字幕不卡的av| 国产精品国产三级国产普通话蜜臀 | 国产精品入口麻豆九色| 国产日韩精品久久久| 国产精品午夜在线| 亚洲日本青草视频在线怡红院 | 亚洲一区二区高清| 亚州成人在线电影| 美女网站色91| 国产精品99久| 色综合色综合色综合| 色狠狠色噜噜噜综合网| 欧美日韩国产综合草草| 欧美一区二区三区日韩视频| 久久亚洲一区二区三区明星换脸| 久久久久久亚洲综合影院红桃 | 一区二区三区在线观看欧美| 午夜日韩在线观看| 国内精品免费在线观看| 99国产精品视频免费观看| 日本道精品一区二区三区| 欧美一区永久视频免费观看| wwwwxxxxx欧美| 伊人婷婷欧美激情| 麻豆精品在线播放| kk眼镜猥琐国模调教系列一区二区| 欧美亚洲国产一区二区三区va| 久久综合久色欧美综合狠狠| 国产欧美视频在线观看| 亚洲精品国久久99热| 麻豆国产一区二区| 色综合久久中文字幕| 日韩美女视频一区二区在线观看| 日本一区二区三区免费乱视频| 亚洲电影第三页| 成人免费福利片| 日韩一区二区免费高清| 亚洲男同性视频| 国产麻豆视频一区| 欧美一区二区三区在线电影| 国产精品乱码久久久久久 | 精品日韩一区二区三区| 亚洲日穴在线视频| 国产白丝精品91爽爽久久| 成人看片黄a免费看在线| 国产色一区二区| 亚洲丰满少妇videoshd| 成人国产在线观看| 久久新电视剧免费观看| 午夜视频一区二区三区| 99精品黄色片免费大全| 久久嫩草精品久久久精品| 偷拍日韩校园综合在线| 色老汉av一区二区三区| 亚洲国产电影在线观看| 精品一区二区三区在线播放| 欧美日韩久久久| 亚洲九九爱视频| 一本一本大道香蕉久在线精品 | 自拍偷拍国产亚洲| 懂色av中文字幕一区二区三区| 欧美电影免费观看高清完整版在| 午夜精品久久久久久久99水蜜桃| 日本精品视频一区二区| 一区二区三区精品视频在线| 91欧美一区二区| 国产精品传媒入口麻豆| 成人av网站在线观看免费| 欧美—级在线免费片| 国产999精品久久久久久绿帽| 久久综合久色欧美综合狠狠| 激情图区综合网| 337p日本欧洲亚洲大胆色噜噜| 国内久久精品视频| 国产精品女同一区二区三区| 成人午夜av在线| 亚洲人精品午夜| 在线看国产一区二区| 亚洲午夜久久久久| 91精品国产综合久久精品麻豆| 日本欧美大码aⅴ在线播放| 制服.丝袜.亚洲.另类.中文| 久久99精品久久久久婷婷| 精品国产凹凸成av人导航| 国产福利一区在线观看| 亚洲丝袜自拍清纯另类| 在线观看免费成人| 日韩精品视频网站| 久久亚洲综合色一区二区三区 | 亚洲色图视频网| 欧美日韩一级大片网址| 美国av一区二区| 欧美激情综合在线| 欧美性视频一区二区三区| 秋霞午夜鲁丝一区二区老狼| 久久综合久久99| av爱爱亚洲一区| 日本午夜一区二区| 中文字幕一区二区三区不卡| 欧美日韩国产精选| 国产盗摄精品一区二区三区在线| 亚洲欧美在线观看| 日韩一区二区三区电影| 成人精品视频一区| 日本v片在线高清不卡在线观看| 久久久影院官网| 精品视频1区2区| 国产超碰在线一区| 日本视频一区二区三区| 国产精品视频一区二区三区不卡| 欧美日韩一区成人| 国产91在线|亚洲| 日韩电影在线观看一区| 中文字幕亚洲成人| 精品成人一区二区| 欧美三级视频在线| av在线一区二区| 韩国av一区二区三区在线观看| 夜夜嗨av一区二区三区四季av| 久久久久久一二三区| 欧美日韩高清影院| 91美女片黄在线观看91美女| 国产一区在线观看视频| 亚洲无线码一区二区三区| 国产精品久久久久影院亚瑟| 精品国产91乱码一区二区三区| 欧美视频在线一区二区三区| 成人免费视频国产在线观看| 国产综合色精品一区二区三区| 婷婷综合五月天| 亚洲一区视频在线| 最新不卡av在线| 中文字幕精品三区| 国产丝袜在线精品| 精品国产乱码久久久久久浪潮| 91精品国产91综合久久蜜臀| 欧美性猛片xxxx免费看久爱| 91在线高清观看| 91在线观看污| 97久久精品人人做人人爽50路| 国产精品99久久久| 国产99久久久国产精品| 高清在线成人网| 国产精品系列在线播放| 国产盗摄女厕一区二区三区| 国产不卡在线视频| kk眼镜猥琐国模调教系列一区二区 | 欧美性一区二区| 91久久国产最好的精华液| 91高清在线观看| 欧美三级在线视频| 欧美一区二区视频免费观看| 日韩精品一区二区三区中文不卡| 日韩欧美在线网站| 26uuu欧美| 国产性做久久久久久| 国产精品色噜噜| 一区二区三区中文免费| 亚洲国产精品久久人人爱蜜臀| 亚洲国产乱码最新视频| 亚洲成人午夜电影| 免费在线一区观看| 国产成人精品免费| 99久久综合国产精品| 欧美视频三区在线播放| 欧美精品日日鲁夜夜添| 日韩精品一区二| 国产日韩精品视频一区| 一区二区在线看| 美腿丝袜亚洲一区| 国产.精品.日韩.另类.中文.在线.播放| 成人av电影在线网| 在线日韩一区二区| 欧美tk—视频vk| 亚洲三级电影网站| 欧美a级理论片| caoporm超碰国产精品| 欧美日韩精品综合在线| 久久精品人人做人人爽人人 | 欧美亚洲自拍偷拍| 精品久久久久久久久久久院品网| 国产精品麻豆视频| 亚洲高清久久久| 国产成人精品三级| 91麻豆精品国产91久久久使用方法 | 国产精品麻豆视频| 免费成人在线视频观看| av中文字幕亚洲| 精品国产污网站| 亚洲一线二线三线久久久|