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

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

?? serialcomm.asp

?? 在工業(yè)控制中
?? ASP
?? 第 1 頁(yè) / 共 3 頁(yè)
字號(hào):
      <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 

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品女主播av| 色综合久久精品| 国产成人啪午夜精品网站男同| 成人一级片在线观看| 国产一区二区毛片| 从欧美一区二区三区| 91国产免费看| 欧美一区二区三区男人的天堂| 91精品婷婷国产综合久久性色| 久久久久国产精品厨房| 欧美国产成人在线| 亚洲男人天堂av| 欧美国产一区视频在线观看| 亚洲欧美另类图片小说| 亚洲综合在线免费观看| 日韩在线观看一区二区| 国产黄色91视频| 91麻豆swag| 欧美日韩1234| 91精品国产免费| 久久久久久久久久电影| 日韩一区中文字幕| 首页国产欧美日韩丝袜| 成人黄页毛片网站| 欧美视频一区二区三区四区| 午夜精品福利一区二区三区av | 国产精品沙发午睡系列990531| 中文字幕日本不卡| 日韩激情在线观看| 国产精品99久| 欧美久久久影院| 欧美激情综合网| 亚洲国产精品人人做人人爽| 国产九色精品成人porny| 色狠狠av一区二区三区| 日韩一区二区电影网| 亚洲美女屁股眼交| 久久精品免费观看| 91免费精品国自产拍在线不卡| 日韩欧美在线1卡| √…a在线天堂一区| 免费观看日韩av| 色婷婷av一区二区三区大白胸| 日韩一卡二卡三卡四卡| 亚洲欧美日韩在线播放| 日韩精品国产欧美| 色偷偷88欧美精品久久久| 欧美精品一区二区高清在线观看| 亚洲色图一区二区| 懂色中文一区二区在线播放| 欧美伊人久久久久久久久影院 | 亚洲午夜久久久久久久久电影网| 国产精品乡下勾搭老头1| 欧美日韩高清在线播放| 国产精品系列在线| 日本三级亚洲精品| 色噜噜夜夜夜综合网| 久久网站最新地址| 日韩精品国产精品| 欧美日韩综合在线| 亚洲色图在线视频| 久久影院视频免费| 奇米精品一区二区三区在线观看一| 不卡大黄网站免费看| 久久美女高清视频| 亚洲高清三级视频| 91日韩在线专区| 国产精品午夜久久| 国产乱对白刺激视频不卡| 欧美日韩成人综合在线一区二区| 最新欧美精品一区二区三区| 精品一区二区三区在线观看国产| 91精品蜜臀在线一区尤物| 中文字幕五月欧美| 激情综合色综合久久| 欧美一区二区三区视频在线观看| 亚洲狼人国产精品| 色av综合在线| 亚洲欧美色综合| 日本道色综合久久| 中文字幕一区二区三区在线观看| 成人黄色电影在线| 国产精品污www在线观看| 国产高清在线精品| 国产精品久久久爽爽爽麻豆色哟哟| 极品少妇xxxx偷拍精品少妇| 日韩一区二区在线观看视频| 亚洲va欧美va天堂v国产综合| 成人avav影音| 亚洲国产成人午夜在线一区 | 56国语精品自产拍在线观看| 天堂在线亚洲视频| 欧美久久久一区| 亚洲夂夂婷婷色拍ww47| 欧美视频在线播放| 亚洲第一在线综合网站| 在线视频一区二区免费| 亚洲成人三级小说| 欧美丰满少妇xxxxx高潮对白| 一区二区三区四区国产精品| 91黄视频在线| 亚洲va欧美va人人爽| 欧美久久高跟鞋激| 麻豆成人在线观看| 久久一日本道色综合| 岛国精品在线播放| 亚洲人成亚洲人成在线观看图片| 国产日韩欧美电影| 99riav久久精品riav| 亚洲午夜一区二区| 精品粉嫩aⅴ一区二区三区四区| 国产乱人伦精品一区二区在线观看 | 亚洲成av人片一区二区| 4438成人网| 国产精品自产自拍| 亚洲精品菠萝久久久久久久| 欧美午夜免费电影| 国产在线视视频有精品| 国产精品久久久久精k8| 欧美久久久久久久久| 国产精品一区一区| 亚洲一区二区在线观看视频| 日韩欧美高清一区| 99精品欧美一区| 日本强好片久久久久久aaa| 日本一区二区三区四区| 欧美日韩国产精品自在自线| 亚洲高清不卡在线| 亚洲精品一线二线三线无人区| 成人午夜在线播放| 一区二区免费视频| 欧美成人一区二区| 99久久99久久精品免费观看| 亚洲欧洲av色图| 欧美电影在哪看比较好| 国产一区二区三区四| 亚洲精品ww久久久久久p站| 日韩欧美综合在线| 成人app下载| 日韩精品久久理论片| 日本一区二区视频在线| 欧美日本国产一区| 国产成人精品影视| 婷婷亚洲久悠悠色悠在线播放| 久久免费视频一区| 欧美亚洲自拍偷拍| 国产成人精品一区二区三区四区| 97久久超碰精品国产| 亚洲v日本v欧美v久久精品| 久久精品男人的天堂| 欧美巨大另类极品videosbest| 成人午夜视频网站| 亚洲国产精品嫩草影院| 亚洲欧洲精品一区二区精品久久久 | 琪琪久久久久日韩精品| 亚洲欧美综合在线精品| 欧美一级欧美三级| 一本高清dvd不卡在线观看| 国产成人午夜精品5599| 日韩vs国产vs欧美| 一区二区中文字幕在线| 精品国产成人在线影院| 91久久人澡人人添人人爽欧美| 成人久久视频在线观看| 美女视频一区在线观看| 亚洲444eee在线观看| 亚洲少妇最新在线视频| 久久久国产综合精品女国产盗摄| 欧美日韩在线精品一区二区三区激情 | 国产精品初高中害羞小美女文| 欧美一区二区三区日韩| 欧美伦理视频网站| 欧美日韩一卡二卡| 欧洲亚洲国产日韩| 色婷婷狠狠综合| 成人av在线播放网址| 成人黄色av电影| 成人免费视频视频在线观看免费 | 欧美三级蜜桃2在线观看| 99精品欧美一区二区蜜桃免费 | 中文字幕高清一区| 欧美电影免费观看完整版| 欧美午夜精品理论片a级按摩| 欧美一三区三区四区免费在线看 | 欧美激情一区二区三区在线| 欧美视频你懂的| 97精品电影院| 国产精品国产三级国产普通话99| 精品国产91洋老外米糕| 在线综合视频播放| 欧美一级黄色大片| 欧美日韩一区二区三区在线| 欧美色综合影院| 色美美综合视频| 国精产品一区一区三区mba视频 | 欧美视频一区二区三区四区| av电影在线观看不卡 | 国产三级精品三级在线专区| 日韩免费看网站| 日韩欧美国产不卡|