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

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

?? serialcomm.asp

?? 一個串口通信的程序
?? ASP
?? 第 1 頁 / 共 3 頁
字號:
	TRACE ( "CSerialCommHelper : Failed to Set Comm State Reason: %d",GetLastError());
	return E_FAIL;
}
TRACE ( "CSerialCommHelper : Current Settings, (Baud Rate %d; Parity %d; Byte Size %d; Stop Bits %d", dcb.BaudRate, 
</font></pre>
    </td>
  </tr>
</table>
<p><font size="2" face="Verdana">Most of the time you won't need to change the
other fields of this structure. But if you need to change the structure you need
to be very careful about the fields as changing the fields will affect the
behavior of the serial communication and hence you should be very sure what you
want to change.&nbsp;<br>
<b><br>
Event Driven Approach<br>
</b>Coming back to our earlier problem with the reading of data. If we do not
want to&nbsp; keep polling the COM port for any data then we need to have some
kind of event mechanism available. Fortunately there is a way that you can ask
the system to notify you when certain events happen. The API to use is
</font></p>
<table border="0" cellspacing="1" width="100%" bgcolor="#C0C0C0">
  <tr>
    <td width="100%"><font size="2" face="Verdana">SetCommMask( HANDLE
      hHandle,DWORD dwEvtMask)</font></td>
  </tr>
</table>
<p><font size="2" face="Verdana">The first parameter is the handle to the open
COM port. The second parameter is used to specify a list of events which we are
interested in. <br>
The events that need to be specified in the mask depends upon the application
needs. For simplicity, lets say we are interested in getting&nbsp; notified
whenever a character arrives at the serial port, we would need to specify
EV_RXCHAR as the event mask. Similarly if we are interested to know when all the
data has been sent, we need to specify EV_TXEMPTY flag also. So out call would
look like this:
</font></p>
<table border="0" cellspacing="1" width="100%" bgcolor="#DADADA">
  <tr>
    <td width="100%"><font size="2" face="Verdana">SetCommMask(
      m_hCommPort,EV_TXTEMPTY|EV_RXCHAR);</font></td>
  </tr>
</table>
<p><font size="2" face="Verdana">&nbsp; The interesting thing here is that
although we told system about the events of our interest, we did not however
told system what to do when these events occur. Like how would system let us
know that a particular event occurred. An obvious thing seems to be a callback
mechanism. But there is not such mechanism available. Here is when things get a
little tricky. In order for system to let us know about the communication event
occurrence, we need to call <b>WaitCommEvent</b> This function waits for the
events specified in SetCommMask. But if your think a little more, it sounds like
we are turning a notification mechanism back to polling mechanism. Actually its
even worse that than . WaitCommEvent blocks till an event occurs. So whats the
use of WaitCommEvent ? Well , the answer lies in overlapped IO.<br>
If you look at the WaitCommEvent signature it looks like this:
</font></p>
<table border="0" cellspacing="1" width="100%" bgcolor="#DADADA">
  <tr>
    <td width="100%"><font face="Verdana" size="2">BOOL</font><font face="Verdana" size="2" color="#0000FF">
      WaitCommEvent</font><font face="Verdana" size="2">(HANDLE hCommPort,
      LPDWORD dwEvtMask,LPOVERLAPPED lpOverlapped);</font></td>
  </tr>
</table>
<p><font size="2" face="Verdana">&nbsp;&nbsp;&nbsp; The third parameter is the
key here.&nbsp;<br>
Think of overlapped IO as asynchronous IO. Whenever a function makes a call and
specifies the overlapped IO structure, it means that try to do the current
operation but if you are not able to complete it immediately let me know when
you are done with this IO. The way system lets you know about the completion is
by setting an kernel event object that is part of the lpOverlapped structure.
So, all you do is spawn a thread and make the thread wait for that event object
using one of the WaitForSingleObject() APIs.<br>
Lets look at the overlapped structure:<br>
</font></p>
<table border="0" cellspacing="1" width="100%" bgcolor="#DADADA">
  <tr>
    <td width="100%">
      <pre><font size="2" face="Verdana"><font color="#0000FF">typedef struct </font>_OVERLAPPED {
DWORD Internal;
DWORD InternalHigh;
DWORD Offset;
DWORD OffsetHigh;
<b>HANDLE hEvent</b>;
} OVERLAPPED, *LPOVERLAPPED;</font></pre>
    </td>
  </tr>
</table>
<p><font size="2" face="Verdana">The last parameter is the event handle that you
need to create . This event is generally a manual reset event. When you make a
call like WaitCommEvent () passing overlapped structure as the last parameter,
and the system could not complete call meaning it did not see any characters at
the port, it would return immediately but would return FALSE. If you now make a
call to GetLastError() you would get ERROR_IO_PENDING which means that the call
has been accepted but no characters have yet arrived at the COM port. Also it
means whenever the characters will arrive, the system will set the hEvent of the
overlapped structure that you passed in. So if your thread would wait for single
object on hEvent and you pass INFINITE, then whenever your Wait fn. returns
WAIT_OBJECT_0 it means some character has arrived&nbsp; or all the data in the
output buffer has been sent.<br>
In our current case since we are interested in more than one events we would
need to check what event did we get by making call to GetCommMask and checking
the dword against each event.Following&nbsp; pseudo code will explain it:</font></p>
<p><font size="2" face="Verdana">&nbsp;You can read the data from the com port
and reset the event and make the call to WaitCommEvent again and so on.
</font></p>
<table border="0" cellspacing="1" width="100%" bgcolor="#EEE8EE">
  <tr>
    <td width="100%">
      <pre><font face="Verdana" size="2" color="#417194">unsigned __stdcall CSerialCommHelper::ThreadFn(void*pvParam)
{
	OVERLAPPED ov;
	memset(&amp;ov,0,sizeof(ov));
	ov.hEvent = CreateEvent( 0,true,0,0);
	HANDLE arHandles[2];
	arHandles[0] = apThis-&gt;m_hThreadTerm;

	DWORD dwWait;
	SetEvent(apThis-&gt;m_hThreadStarted);
	while (  abContinue )
	{
		
</font><font face="Verdana" size="2">		BOOL abRet = ::WaitCommEvent(apThis-&gt;m_hCommPort,&amp;dwEventMask, &amp;ov) ;
</font><font face="Verdana" size="2" color="#417194">		if ( !abRet )
		{
			
			ASSERT( GetLastError () == ERROR_IO_PENDING);
		}

		
		arHandles[1] = ov.hEvent ;
		
		dwWait = WaitForMultipleObjects (2,arHandles,FALSE,INFINITE);
		switch ( dwWait )
		{
		case WAIT_OBJECT_0:
			{
				_endthreadex(1);
			}
			break;
		case WAIT_OBJECT_0 + 1:
			{
				</font><font face="Verdana" size="2">DWORD dwMask;
				if (GetCommMask(apThis-&gt;m_hCommPort,&amp;dwMask) )
				{
				   if ( dwMask &amp; EV_TXEMPTY )
				   TRACE(&quot;Data sent&quot;);
				   ResetEvent ( ov.hEvent );
				   continue;
				}<font color="#417194">
				</font>else  
				{
				   //read data here and reset ov.hEvent
				}
</font><font color="#417194"><font face="Verdana" size="2">			}
		}//switch
	}//while
return 0;
}</font></font></pre>
    </td>
  </tr>
</table>
<p><font size="2" face="Verdana">&nbsp;If you understood the above code , you
will understand the whole of this article and the source code provided.<br>
&nbsp;The above piece of code is simple using the overlapped IO method to do its
job.<br>
Once we have received the indication that the data has arrived we need to read
the data. Important thing to note here is that the when data arrives at the
serial port, it is copied over to system buffer.&nbsp; The data is removed from
the system buffer only when you have read the data using API such as ReadFile.&nbsp;
Like any buffer, system buffer has a limited size. So if you do not read the
data from the buffers quick enough the system buffers can be become full if more
data is arriving. What happens to further data depends upon the configuration
that you have set in the device configuration block (in call to SetCommState ).
Usually the applications do some kind of handshaking at the application level
but you can also make configurations such that the com port does not accept any
further data upon buffer-full events. But all that is beyond the scope of this
discussion. If possible its always better to have applications themselves
implementing some kind of handshaking&nbsp; - like do not send next block of
data until you get okay for the first block. Generally this kind of handshaking
is implemented using some sort of ACK / NAK&nbsp; and ENQ protocol.<br>
<br>
In order for us to read data we need to use ReadFile() API. ReadFile API has to
specify how much data to read. Lets say we are monitoring character arrivals and
10 characters arrive at the port. As soon as first character arrives at the port
the system will set the overlapped structure's event object and out
WaitSingleObject will return. Next we would need to read the data. So how much
data should we read? Should we read 1 byte or&nbsp; 10 bytes? That is a good
question.&nbsp;&nbsp; The way it works is as follows (Note:this
is not documented anywhere but this is what I have found by research on
Win2K,NT4.0)&nbsp; :<br>
When one (or more) characters arrive at the port, the event object associated with the
overlapped structure set once. Now lets say that you made a call to read and you
read 1 character. After reading 1 character , you would finally Reset the
overlapped structure's event object. Now you would go back to the WaitCommEvent
but it would return false since no &quot;new&quot; character has arrived. So you
will not be able to read any more characters.&nbsp; Now when another character
arrives, system will set the overlapped event and you would read one more
character but this time it will be the character that had arrived earlier and
you never read. This clearly is a&nbsp; problem.<br>
So what is the solution? The easiest solution is that as soon as you got the
event object indicating the arrival of a character, you should read all the
characters that are present in the port. (<i>If you are familiar with win API
MsgWaitForMultipleObjects you can draw a analogy here.</i>) </font></p>
<p><font size="2" face="Verdana">So again the question remains how many
characters to read. The answer is read all the characters in a loop using
ReadFile().
<br>
Here is the pseudo code</font></p>
<table border="0" cellspacing="1" width="100%" bgcolor="#DADADA">
  <tr>
    <td width="100%">

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲一区二区三区四区的| 午夜电影网一区| 成人av资源在线| 亚洲国产成人私人影院tom| 精品制服美女久久| 亚洲一区电影777| 91蜜桃免费观看视频| 亚洲精品ww久久久久久p站| 欧美在线免费播放| 免费三级欧美电影| 亚洲精品一区二区三区蜜桃下载| 韩国一区二区视频| 精品国产一区二区三区忘忧草| 久久国产生活片100| 国产欧美一区二区精品性色| 不卡的av中国片| 午夜影视日本亚洲欧洲精品| 欧美精品一区二区三区在线播放| 顶级嫩模精品视频在线看| 亚洲啪啪综合av一区二区三区| 欧美日韩国产天堂| 国产精品一区免费在线观看| 日韩理论片一区二区| 欧美videos大乳护士334| 国产成人亚洲精品狼色在线 | 欧美日韩中文一区| 日韩欧美国产麻豆| 91香蕉视频在线| 九九九精品视频| 亚洲一区二区三区四区在线观看| 欧美刺激脚交jootjob| 91麻豆精东视频| 国产一区二区看久久| 免费高清不卡av| 亚洲超碰97人人做人人爱| 国产精品久久久久久久久免费丝袜 | 亚洲黄色免费网站| 久久久精品黄色| 91精品国产福利| 欧美性做爰猛烈叫床潮| 成+人+亚洲+综合天堂| 国产精品996| 国产精品中文字幕一区二区三区| 秋霞国产午夜精品免费视频| 亚洲精品国产无套在线观| 国产精品久久免费看| 国产精品嫩草久久久久| 欧美v国产在线一区二区三区| 青青草97国产精品免费观看 | 国产精品免费丝袜| 久久蜜臀中文字幕| 亚洲伊人色欲综合网| 欧美一区日本一区韩国一区| 在线看国产一区二区| 色视频成人在线观看免| 91久久国产综合久久| 91极品视觉盛宴| 欧美羞羞免费网站| 欧美一区二区久久| 成人免费毛片app| 欧美aaaaaa午夜精品| 免费av成人在线| 国产成人在线视频免费播放| 国产成人免费视频一区| 国产.欧美.日韩| 欧美嫩在线观看| 国产免费成人在线视频| 亚洲综合一区在线| 国产精品资源网| 欧美性xxxxx极品少妇| 久久久久久99久久久精品网站| 亚洲精品国产一区二区精华液 | 日本一区二区高清| 午夜精品一区二区三区电影天堂 | 日韩精品成人一区二区三区| 国产suv精品一区二区6| 欧美日韩国产精品成人| 中文一区二区在线观看| 男男视频亚洲欧美| 99久久99久久精品免费观看| 精品久久久久99| 视频精品一区二区| 欧美丝袜丝nylons| 亚洲日本在线a| 国产69精品久久777的优势| 久久精品在这里| 日韩中文字幕91| 欧美写真视频网站| 亚洲精品欧美二区三区中文字幕| 激情亚洲综合在线| 精品国产乱码久久| 裸体歌舞表演一区二区| 宅男噜噜噜66一区二区66| 亚洲香蕉伊在人在线观| 欧美日韩中文字幕精品| 欧美电视剧免费观看| 欧美成人aa大片| 免费在线观看一区| 欧美影院午夜播放| 亚洲视频一区二区免费在线观看 | 丝袜美腿亚洲综合| 欧美电影在线免费观看| 日韩av一区二区在线影视| 日韩写真欧美这视频| 国产精品一二三四区| 中文字幕色av一区二区三区| 91丨porny丨国产| 亚洲国产欧美日韩另类综合| 欧美高清激情brazzers| 免费成人在线视频观看| 久久久久久免费网| 成人性生交大合| 亚洲不卡在线观看| 久久蜜桃av一区二区天堂| 91在线观看一区二区| 亚洲成人免费看| 国产欧美日韩三级| 欧美男女性生活在线直播观看| 九九九精品视频| 亚洲夂夂婷婷色拍ww47| 2024国产精品视频| 欧美精品在线视频| 成人小视频在线观看| 蜜臀91精品一区二区三区| 一区二区视频免费在线观看| 日韩精品一区国产麻豆| 一本到不卡免费一区二区| 久久国产精品一区二区| 亚洲一区二区影院| 成人欧美一区二区三区白人| 日韩亚洲欧美在线| 欧美一区二区三区小说| 678五月天丁香亚洲综合网| 日韩欧美精品在线| 亚洲v中文字幕| 日本一区二区三区在线不卡| 欧美精品日韩一区| 色综合欧美在线视频区| 亚洲成人第一页| 亚洲男人的天堂一区二区| 自拍偷拍国产精品| 久久综合丝袜日本网| 欧美一级欧美一级在线播放| 91精品久久久久久久91蜜桃| 亚洲乱码一区二区三区在线观看| 成人av电影免费在线播放| 婷婷丁香久久五月婷婷| 自拍偷拍欧美精品| 精品视频999| av电影在线观看不卡| 日本韩国精品在线| 在线精品视频一区二区| 一本色道久久综合亚洲aⅴ蜜桃 | 中文字幕不卡在线播放| 欧美大片日本大片免费观看| 日韩一区二区三免费高清| 欧美一区二区三区在线| 精品国产露脸精彩对白| 久久精品视频一区二区| 最近日韩中文字幕| 一区二区三区在线观看欧美| 亚洲成av人片在线观看无码| 日韩影视精彩在线| 成人激情午夜影院| 欧美三级午夜理伦三级中视频| 欧美性受xxxx黑人xyx性爽| 欧美一区二区三区四区视频 | 久久精品免费在线观看| 亚洲一卡二卡三卡四卡| 国产精品一品二品| 色屁屁一区二区| 日韩精品一区二区三区视频| 亚洲精品乱码久久久久久| 国产自产视频一区二区三区| 色又黄又爽网站www久久| 国产欧美一区二区三区沐欲| 日韩精品成人一区二区在线| 成人一道本在线| 欧美成人综合网站| 国产日产亚洲精品系列| 久久久综合视频| 美国十次了思思久久精品导航| 国产成人免费在线观看不卡| 日韩欧美色综合网站| 午夜精品福利在线| 91豆麻精品91久久久久久| 亚洲亚洲精品在线观看| 在线一区二区三区| 一区二区三区在线视频播放| 国产二区国产一区在线观看| 精品成人一区二区| 国产麻豆精品在线| 中文字幕av在线一区二区三区| 婷婷一区二区三区| 欧美色偷偷大香| 亚洲第一精品在线| 欧美色区777第一页| 亚洲综合一区二区三区| 色哟哟一区二区三区| 一区二区三区日韩在线观看|