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

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

?? serialcomm.asp

?? 串口通信高級(jí)編程 visual c++
?? ASP
?? 第 1 頁(yè) / 共 3 頁(yè)
字號(hào):
	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%">

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一级黄色录像| 成人黄动漫网站免费app| 日本久久一区二区| 中文字幕av一区 二区| 蜜桃av一区二区在线观看 | 91亚洲资源网| 中文字幕制服丝袜一区二区三区| 色哟哟欧美精品| 91伊人久久大香线蕉| 久久美女艺术照精彩视频福利播放| 久久精品久久综合| 国产精品久久久久久久久果冻传媒 | 91蝌蚪porny成人天涯| 亚洲一线二线三线久久久| 日韩亚洲欧美成人一区| 国产伦精一区二区三区| 国产日韩欧美亚洲| 成人精品免费视频| 亚洲一区二区三区四区在线免费观看| 在线视频欧美精品| 五月婷婷综合激情| 欧美变态凌虐bdsm| 激情综合色播激情啊| 中文字幕av一区二区三区高| voyeur盗摄精品| 亚洲午夜久久久久| 精品伦理精品一区| www.欧美亚洲| 日韩精品乱码免费| 国产精品视频yy9299一区| 91精品福利在线| 九九九精品视频| 亚洲乱码国产乱码精品精可以看| 日本道精品一区二区三区 | 亚洲成人激情自拍| 欧美mv日韩mv亚洲| 色综合久久综合中文综合网| 图片区小说区区亚洲影院| 麻豆精品在线播放| 久久久91精品国产一区二区三区| 在线亚洲精品福利网址导航| 国产精品一级片在线观看| 亚洲国产视频a| 亚洲免费资源在线播放| 国产精品久久久久久久久图文区| 3751色影院一区二区三区| 91亚洲精品乱码久久久久久蜜桃| 麻豆中文一区二区| 亚洲午夜在线视频| 亚洲免费看黄网站| 国产女人aaa级久久久级| 欧美一区二区三区四区在线观看 | 成人黄色软件下载| 全部av―极品视觉盛宴亚洲| 亚洲另类春色校园小说| 久久精品亚洲乱码伦伦中文| 日韩三级在线免费观看| 欧美日韩一级片网站| 欧美性生活久久| 91九色02白丝porn| 91麻豆视频网站| 成人av综合一区| 丁香桃色午夜亚洲一区二区三区| 久久精品国产免费| 蜜臀av性久久久久蜜臀aⅴ | 亚洲国产va精品久久久不卡综合 | 欧美视频一区二区三区在线观看| 91精品国产综合久久久久| 久久久久97国产精华液好用吗| 中文无字幕一区二区三区 | 日韩一二三区视频| 亚洲视频小说图片| 亚洲国产视频在线| 日本在线播放一区二区三区| 六月丁香综合在线视频| 成人免费高清视频| 91网站最新网址| 4438x成人网最大色成网站| 欧美电影免费观看高清完整版在线| 久久久久久久久久看片| 亚洲日本va午夜在线影院| 亚洲一区二区美女| 久久不见久久见免费视频1 | 日韩欧美中文一区| 国产亚洲欧美日韩在线一区| 亚洲私人影院在线观看| 午夜av一区二区三区| 国产经典欧美精品| 色成人在线视频| 日韩欧美高清在线| 一区二区在线免费| 欧美α欧美αv大片| 777xxx欧美| 国产精品久久一卡二卡| 国产精品一品二品| 久久欧美中文字幕| 精品国精品自拍自在线| 亚洲精品一区二区三区四区高清| 亚洲黄色免费网站| jiyouzz国产精品久久| 国产三级欧美三级日产三级99| 日韩av一级片| 555www色欧美视频| 亚洲成人一二三| 欧美日韩一级黄| 亚洲一区二区综合| 欧美色精品在线视频| 亚洲综合男人的天堂| 欧洲激情一区二区| 亚洲sss视频在线视频| 欧美色男人天堂| 久久亚洲一级片| 亚洲精品菠萝久久久久久久| 伊人性伊人情综合网| 国产精品福利一区二区三区| 国产精品嫩草影院com| 亚洲成av人片在线观看| 国产一区二区三区电影在线观看| 国产寡妇亲子伦一区二区| 91蝌蚪porny九色| 国产亚洲人成网站| 婷婷成人激情在线网| 国产一区二区在线电影| 91黄色激情网站| 2024国产精品| 国产精品原创巨作av| 欧美日韩一级二级三级| 中文字幕色av一区二区三区| 青青国产91久久久久久| 欧美三级电影在线看| 国产精品天天看| 国产高清不卡一区二区| 日韩免费在线观看| 亚洲高清视频在线| 色综合久久天天综合网| 国产精品日产欧美久久久久| 久久国产精品色婷婷| 欧美私人免费视频| 一区二区在线免费| 欧美日韩精品一区二区三区四区| 精品久久一区二区三区| 国产传媒欧美日韩成人| 国产欧美日本一区视频| 久久99精品久久久久| 91在线视频在线| 久久精品免费在线观看| 日韩成人av影视| 欧美高清性hdvideosex| 亚洲mv在线观看| 国产精品短视频| 欧美国产视频在线| 精品视频免费看| 麻豆免费看一区二区三区| 亚洲成人你懂的| 亚洲午夜免费电影| 亚洲香肠在线观看| 午夜免费欧美电影| 午夜一区二区三区视频| 日韩经典中文字幕一区| 日韩激情在线观看| 久色婷婷小香蕉久久| 亚洲欧美区自拍先锋| 欧美亚洲国产bt| 人人狠狠综合久久亚洲| 久久色中文字幕| www.欧美色图| 蜜臀av国产精品久久久久| 久久综合99re88久久爱| 国产精品88av| 有码一区二区三区| 777a∨成人精品桃花网| 国产一区二区三区观看| 一区二区三区.www| 欧美成人乱码一区二区三区| 国产传媒日韩欧美成人| 一级精品视频在线观看宜春院 | 日本欧美一区二区| 欧美午夜视频网站| 久久99久国产精品黄毛片色诱| 国产精品青草综合久久久久99| 在线观看日韩高清av| 蜜桃av一区二区三区电影| 亚洲日穴在线视频| 久久人人超碰精品| 欧美日本在线播放| 欧美日本在线视频| 成人app网站| 日韩电影一区二区三区四区| 国产精品素人视频| 国产亚洲午夜高清国产拍精品 | 精品午夜久久福利影院| 日韩美女啊v在线免费观看| 色偷偷成人一区二区三区91 | 亚洲天堂网中文字| 五月婷婷色综合| 日韩av电影天堂| 国产一区不卡视频| 91丨porny丨首页| 91精品国产91久久久久久一区二区| 26uuu精品一区二区三区四区在线|