亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
亚洲国产高清在线观看视频| 日韩一区和二区| 国产麻豆视频一区| 老司机精品视频导航| 日本少妇一区二区| 日韩精品五月天| 六月丁香婷婷色狠狠久久| 日韩国产欧美三级| av电影在线观看完整版一区二区| 国产盗摄视频一区二区三区| 国产精品1区2区| av一区二区三区四区| 成人国产一区二区三区精品| www.亚洲人| 国产成人精品免费一区二区| 国产成人在线电影| 91在线免费看| 欧美日本一区二区在线观看| 这里只有精品免费| 久久综合色8888| 中文字幕一区二区三区四区不卡| 中文字幕一区二区三区乱码在线| 亚洲激情图片一区| 婷婷丁香久久五月婷婷| 国内成人免费视频| 99精品在线免费| 91精选在线观看| 国产日韩av一区| 午夜影院久久久| 国内不卡的二区三区中文字幕| 丁香婷婷综合色啪| 欧美性受极品xxxx喷水| 欧美videossexotv100| 国产精品久久综合| 色久优优欧美色久优优| 欧美亚洲免费在线一区| 亚洲精品一区二区三区四区高清 | 91免费版在线| 这里只有精品电影| 亚洲国产岛国毛片在线| 亚洲自拍偷拍九九九| 久久99精品久久久久久动态图| 久久久影院官网| 日韩美女主播在线视频一区二区三区| 久久久久久一级片| 亚洲国产成人精品视频| 国产乱子伦一区二区三区国色天香| 成人av网站免费观看| 日韩免费成人网| 亚洲综合精品久久| 成人精品亚洲人成在线| 日韩一二三区视频| 一级中文字幕一区二区| 波多野结衣中文字幕一区二区三区| 欧美女孩性生活视频| 国产精品国产自产拍高清av王其| 色婷婷精品大在线视频| 精品国产一区久久| 日韩电影在线观看电影| 欧洲亚洲国产日韩| 亚洲裸体在线观看| 成人99免费视频| 久久久久久一二三区| 蜜芽一区二区三区| 欧美日韩精品福利| 亚洲一区免费在线观看| 在线亚洲高清视频| 亚洲视频综合在线| 色综合婷婷久久| 综合欧美一区二区三区| 99re这里只有精品首页| 国产精品久久久久久亚洲毛片 | 国产一区二区三区高清播放| 91精品婷婷国产综合久久 | 欧美亚洲日本国产| 久久久综合精品| 国产精品一区免费视频| 久久影视一区二区| 国产精品1024| 欧美高清在线一区| 99久久99久久久精品齐齐| 久久精品99久久久| 日韩一区二区三区电影在线观看| 天天综合天天综合色| 欧美一级生活片| 久久国产精品区| 亚洲国产高清在线| 色视频欧美一区二区三区| 亚洲一级片在线观看| 在线成人小视频| 精品在线播放午夜| 国产精品人人做人人爽人人添| 成人av综合在线| 亚洲一卡二卡三卡四卡五卡| 欧美日本在线观看| 国产一本一道久久香蕉| 国产精品欧美久久久久无广告 | 日韩欧美视频一区| 国产一区在线不卡| 亚洲四区在线观看| 91精品国产免费| 国产sm精品调教视频网站| 亚洲欧洲精品成人久久奇米网| 欧美最猛性xxxxx直播| 欧美在线视频你懂得| 视频一区在线播放| 国产亚洲欧美一级| 在线观看av一区| 国产剧情一区二区| 亚洲成人av中文| 国产日产欧美精品一区二区三区| 色噜噜狠狠成人网p站| 久久成人精品无人区| 亚洲天堂精品在线观看| 日韩精品一区二区三区三区免费| 成人一二三区视频| 人人爽香蕉精品| 亚洲三级免费电影| 久久影院午夜片一区| 欧美三区在线观看| www.亚洲在线| 国产精品自在欧美一区| 亚洲3atv精品一区二区三区| 国产欧美日本一区视频| 欧美剧在线免费观看网站| 99视频精品在线| 久久99久久久久久久久久久| 亚洲一区电影777| 亚洲欧洲在线观看av| 久久综合久久鬼色| 欧美一级免费大片| 在线观看区一区二| www.久久精品| 高清国产午夜精品久久久久久| 日韩和欧美一区二区三区| 成人免费看黄yyy456| 日韩高清不卡在线| 亚洲国产成人精品视频| 亚洲美女一区二区三区| 国产精品免费久久久久| 国产日产亚洲精品系列| wwwwxxxxx欧美| 欧美成人r级一区二区三区| 在线不卡a资源高清| 欧美乱妇15p| 欧美精品丝袜中出| 欧美美女激情18p| 欧美欧美欧美欧美| 7777女厕盗摄久久久| 在线播放视频一区| 欧美日韩精品一区二区三区四区| 欧美日韩午夜精品| 欧美浪妇xxxx高跟鞋交| 欧美精品亚洲二区| 欧美一级久久久| 日韩精品一区二区三区中文不卡 | 麻豆精品一区二区三区| 日本色综合中文字幕| 麻豆91在线播放免费| 久久精品国产免费| 国产白丝网站精品污在线入口| 国产黑丝在线一区二区三区| 国产凹凸在线观看一区二区| 国产成人鲁色资源国产91色综| 国产成人免费在线观看| av电影天堂一区二区在线观看| 色综合中文字幕| 欧美日韩在线播| 日韩免费观看高清完整版在线观看| 日韩精品一区二区在线| 国产人成一区二区三区影院| 中文字幕一区二区三区视频| 一区二区三区精品视频| 日韩精品电影一区亚洲| 精品一区二区三区欧美| 成人精品gif动图一区| 色噜噜狠狠成人网p站| 欧美一区二区大片| 国产精品五月天| 午夜精品久久久久久久蜜桃app| 免费观看成人鲁鲁鲁鲁鲁视频| 韩国成人福利片在线播放| 成人少妇影院yyyy| 欧美精品一卡二卡| 国产欧美日韩另类视频免费观看 | 欧美日韩成人激情| 精品国产1区二区| 亚洲精品视频一区| 精品一区二区三区在线观看国产| 不卡av在线免费观看| 91麻豆精品国产自产在线观看一区| 日韩影院免费视频| 国产精品一区二区三区乱码| 99视频在线观看一区三区| 欧美男人的天堂一二区| 国产精品国产三级国产aⅴ无密码| 视频一区在线播放| 色悠久久久久综合欧美99| 久久综合国产精品| 日日夜夜精品视频免费|