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

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

?? serialcomm.asp

?? 一個串口通信的程序
?? 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一区二区三区免费野_久草精品视频
亚洲成a人v欧美综合天堂| 中文字幕高清一区| 国产免费成人在线视频| 午夜精品在线视频一区| 丁香五精品蜜臀久久久久99网站 | 亚洲444eee在线观看| 激情深爱一区二区| 欧美日韩高清不卡| 亚洲欧洲av在线| 狠狠色狠狠色综合系列| 91精品麻豆日日躁夜夜躁| 亚洲天堂福利av| 岛国精品一区二区| 精品久久一区二区| 蜜臀精品久久久久久蜜臀| 91丝袜美女网| 国产精品午夜久久| 国产不卡免费视频| 久久久午夜精品| 国产精品一区久久久久| 日韩一区二区三区视频| 性做久久久久久| 欧美日韩一区二区三区在线| 夜夜精品浪潮av一区二区三区| 成人三级在线视频| 中文字幕av一区二区三区免费看| 国产老妇另类xxxxx| 久久精品视频免费| 国产一区美女在线| 国产人妖乱国产精品人妖| 狠狠色伊人亚洲综合成人| 亚洲精品一区二区三区精华液| 狠狠色丁香婷婷综合| 精品乱人伦一区二区三区| 韩国精品主播一区二区在线观看 | 亚洲精品乱码久久久久久久久| 国产 日韩 欧美大片| 国产精品久久久久久久久免费桃花| 国产a精品视频| 中文字幕中文乱码欧美一区二区| 成人性生交大片| 17c精品麻豆一区二区免费| 99re热这里只有精品视频| 亚洲视频小说图片| 在线欧美日韩精品| 日本三级韩国三级欧美三级| 日韩精品一区二区在线| 国产91精品在线观看| 亚洲天堂av一区| 欧美日韩国产在线播放网站| 久久国产福利国产秒拍| 国产午夜精品理论片a级大结局 | 色婷婷综合在线| 欧美一区二区成人6969| 亚洲网友自拍偷拍| 欧美三级中文字幕在线观看| 日日欢夜夜爽一区| 国产亚洲va综合人人澡精品| 不卡视频免费播放| 污片在线观看一区二区| 久久奇米777| 91久久精品日日躁夜夜躁欧美| 日韩高清中文字幕一区| 国产精品丝袜久久久久久app| 在线亚洲高清视频| 久久国产综合精品| 亚洲男人天堂一区| 精品久久久三级丝袜| 色综合天天狠狠| 九色porny丨国产精品| 亚洲美女视频在线观看| 欧美成人精品高清在线播放| 99久久综合狠狠综合久久| 日本色综合中文字幕| 亚洲欧美日韩国产一区二区三区| 欧美成人精品福利| 精品视频全国免费看| 岛国一区二区三区| 麻豆一区二区三| 亚洲精品乱码久久久久久黑人| 精品国产人成亚洲区| 欧美亚洲日本国产| zzijzzij亚洲日本少妇熟睡| 久久99久久99| 午夜精品福利一区二区三区av| 亚洲国产精品国自产拍av| 日韩一区二区三| 色婷婷av一区二区三区之一色屋| 国产传媒久久文化传媒| 麻豆久久一区二区| 日韩精品欧美精品| 亚洲国产精品久久一线不卡| 国产精品久久久久婷婷| 26uuu亚洲综合色欧美| 欧美另类videos死尸| 99re成人精品视频| 成人av综合一区| 国产ts人妖一区二区| 国产乱码精品一区二区三区av| 日本aⅴ亚洲精品中文乱码| 亚洲精品乱码久久久久久黑人 | 欧美一区二区三区色| 色先锋资源久久综合| av在线不卡电影| 成人精品视频一区| 成人午夜视频免费看| 国产激情91久久精品导航 | 美女精品一区二区| 青青草精品视频| 日本最新不卡在线| 亚洲线精品一区二区三区八戒| 最新久久zyz资源站| 亚洲欧美综合在线精品| 中文字幕一区二区视频| 国产精品免费人成网站| 亚洲欧美在线视频观看| 尤物在线观看一区| 香蕉成人啪国产精品视频综合网 | 欧美一级高清片| 日韩丝袜情趣美女图片| 精品捆绑美女sm三区| 久久日一线二线三线suv| 久久久影视传媒| 中文字幕欧美区| 亚洲日本在线a| 亚洲一区二区三区四区不卡| 午夜精品免费在线| 紧缚奴在线一区二区三区| 国模套图日韩精品一区二区| 国产精选一区二区三区| youjizz久久| 欧美三级在线视频| 精品美女在线观看| 国产精品久久久一本精品| 国产精品欧美一区喷水| 精品一区二区三区av| 久久国产精品99久久久久久老狼| 国产在线不卡一卡二卡三卡四卡| 成人毛片视频在线观看| 欧美中文一区二区三区| 日韩精品自拍偷拍| 国产精品国产三级国产三级人妇| 亚洲午夜日本在线观看| 久久精品72免费观看| 成人av一区二区三区| 欧美日韩激情在线| 国产性做久久久久久| 亚洲电影一级黄| 国产精品自拍一区| 欧美午夜影院一区| 久久久久久久久久久久久女国产乱| 最近日韩中文字幕| 精品一二三四区| 99riav一区二区三区| 日韩欧美在线网站| 亚洲人成人一区二区在线观看| 奇米影视7777精品一区二区| 成人丝袜高跟foot| 欧美一区二区三区不卡| 国产精品色哟哟| 精品一区二区三区av| 欧美色精品在线视频| 国产精品久久久久久久久久免费看 | 日韩免费电影一区| 亚洲精品伦理在线| 国产成人av福利| 欧美一区三区四区| 国产精品伦一区| 国产一区二区精品久久91| 欧美日韩国产高清一区| 中文字幕中文在线不卡住| 国产做a爰片久久毛片| 欧美日韩久久不卡| 亚洲欧美日韩久久精品| 国产91精品在线观看| 精品免费一区二区三区| 三级影片在线观看欧美日韩一区二区| 成人黄色综合网站| 亚洲色图欧美偷拍| 欧美视频日韩视频| 一区二区三区欧美日| 日韩一本二本av| 欧美高清dvd| 偷拍日韩校园综合在线| 欧美精品 日韩| 美女一区二区在线观看| **欧美大码日韩| 国产91清纯白嫩初高中在线观看| 欧美一区二区美女| 午夜精品成人在线视频| 欧美天天综合网| 亚洲最新视频在线观看| 91浏览器在线视频| 亚洲激情一二三区| 91高清在线观看| 亚洲国产日韩精品| 欧美日韩久久久一区| 首页综合国产亚洲丝袜| 欧美美女激情18p| 日韩福利视频导航|