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

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

?? serialcomm.asp

?? 在工業(yè)控制中
?? 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%">

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品超碰97尤物18| 香蕉av福利精品导航| 欧美日韩视频一区二区| 91国内精品野花午夜精品| 99久久夜色精品国产网站| 国v精品久久久网| 99国产精品国产精品毛片| 日本道色综合久久| 亚洲成av人影院| 欧美一区二区视频观看视频| 色婷婷亚洲精品| 欧美成人aa大片| 亚洲欧美一区二区三区久本道91| 亚洲图片欧美一区| 国产一区二区三区四区五区入口| 色狠狠色噜噜噜综合网| 精品成人免费观看| 亚洲一区在线看| 国产大陆精品国产| 欧美日韩国产一区二区三区地区| 国产亚洲va综合人人澡精品| 亚洲成人av一区二区| 春色校园综合激情亚洲| 91精品国产全国免费观看| 一区精品在线播放| 国产一区视频网站| 欧美高清性hdvideosex| 中文字幕中文字幕在线一区| 狂野欧美性猛交blacked| 91在线高清观看| 久久久久久免费网| 午夜亚洲福利老司机| 成人小视频免费在线观看| 欧美性高清videossexo| 久久久噜噜噜久久中文字幕色伊伊| 亚洲日本护士毛茸茸| 国产精品黄色在线观看| 另类成人小视频在线| 91在线观看污| 欧美精品一区二区久久婷婷| 一区二区三区小说| 韩国一区二区视频| 欧美日韩中文另类| 中文字幕一区二区三区不卡| 蜜臀av性久久久久蜜臀aⅴ四虎 | 国产精品二三区| 美女视频一区二区| 色哟哟日韩精品| 国产色一区二区| 欧美艳星brazzers| 久久久99久久精品欧美| 国产精品综合av一区二区国产馆| 欧美性感一区二区三区| ...av二区三区久久精品| 麻豆中文一区二区| 精品视频资源站| 亚洲午夜久久久久| 菠萝蜜视频在线观看一区| 亚洲国产综合色| 欧美亚洲高清一区二区三区不卡| 欧美一二三区在线观看| 亚洲蜜臀av乱码久久精品| 久久66热re国产| 欧美日韩性生活| 亚洲欧美欧美一区二区三区| 成人午夜短视频| 亚洲精品一区二区三区99| 日韩av一二三| 欧美女孩性生活视频| 亚洲激情在线播放| 99热99精品| 国产欧美视频一区二区| 久久不见久久见中文字幕免费| 欧美色老头old∨ideo| 亚洲欧美aⅴ...| 成人av网站免费| 国产亚洲一区二区三区四区| 国模少妇一区二区三区| 日韩精品一区二区三区视频在线观看| 性做久久久久久久免费看| 欧洲生活片亚洲生活在线观看| 国产精品无圣光一区二区| 国产成人午夜片在线观看高清观看| 欧美大片日本大片免费观看| 日韩高清不卡一区| 欧美丰满少妇xxxxx高潮对白| 亚洲一区二区三区四区在线免费观看| 91一区一区三区| 亚洲日本护士毛茸茸| 色综合久久九月婷婷色综合| 亚洲人成网站在线| 91麻豆精品秘密| 尤物av一区二区| 91一区一区三区| 亚洲色大成网站www久久九九| a在线欧美一区| 中文字幕日韩欧美一区二区三区| 成人h版在线观看| 亚洲丝袜自拍清纯另类| 色网综合在线观看| 亚洲一区二区视频在线观看| 欧美日韩一区二区三区在线看| 亚洲国产乱码最新视频| 欧美精品三级日韩久久| 毛片不卡一区二区| 国产欧美日韩麻豆91| 国产一区二区三区精品欧美日韩一区二区三区 | 麻豆国产精品一区二区三区 | 国产日产欧美一区| 欧美性受xxxx黑人xyx性爽| 国精产品一区一区三区mba桃花| 亚洲人成网站精品片在线观看| 中文字幕亚洲成人| 亚洲成人av一区| 99re这里只有精品视频首页| 一区二区三区四区视频精品免费 | 欧美一区二区三区爱爱| 久久国产精品色婷婷| 精品久久久久久综合日本欧美| 国产成人丝袜美腿| 亚洲色图欧美激情| 制服丝袜亚洲色图| 国产精品一二三四区| 国产精品国产三级国产| 91久久精品网| 三级欧美在线一区| 精品成人a区在线观看| 韩国三级电影一区二区| 国产精品天天摸av网| 99久久精品情趣| 日本在线不卡一区| 欧美高清在线一区| 欧美亚洲综合久久| 国产成人精品免费一区二区| 亚洲午夜国产一区99re久久| 欧美成人video| 色先锋aa成人| 久草热8精品视频在线观看| 中文字幕一区二区三区精华液| 欧美日韩国产成人在线免费| 国产成人精品亚洲日本在线桃色| 一区二区三区四区中文字幕| 久久久蜜臀国产一区二区| 91黄色免费网站| 国产精品一级黄| 午夜久久久影院| 国产欧美精品区一区二区三区| 色屁屁一区二区| 国产一区二区精品久久| 亚洲成在人线免费| 国产视频一区二区在线| 在线观看www91| 成人丝袜高跟foot| 久草中文综合在线| 亚洲国产精品久久一线不卡| 国产精品婷婷午夜在线观看| 日韩一二在线观看| 色综合一区二区| 国产精品自拍三区| 亚洲午夜影视影院在线观看| 国产精品卡一卡二| 精品国产污网站| 欧美乱妇15p| 丁香亚洲综合激情啪啪综合| 91成人免费在线| 亚洲国产精品影院| 91视频精品在这里| 精品福利av导航| 三级影片在线观看欧美日韩一区二区 | 国产精品日产欧美久久久久| 国产精品99久久久久久似苏梦涵| 欧美日韩高清一区二区三区| 韩国av一区二区三区四区| 国产亚洲综合在线| 日韩一区二区三区四区| 精品视频在线看| 色94色欧美sute亚洲线路一ni| 国产91精品一区二区麻豆亚洲| 九九九久久久精品| 日韩激情一区二区| 亚洲成人自拍网| 亚洲综合丁香婷婷六月香| 亚洲人吸女人奶水| 国产精品久久久久久久岛一牛影视 | 水野朝阳av一区二区三区| 亚洲欧美日韩在线播放| 国产精品传媒视频| 国产偷国产偷精品高清尤物| 精品国产一区二区三区久久久蜜月| 欧美精品久久一区二区三区| 欧美亚洲动漫精品| 欧美熟乱第一页| 91久久免费观看| 色欧美日韩亚洲| 日本韩国精品在线| 色94色欧美sute亚洲13| 色婷婷综合久久| 91福利国产精品| 欧美日韩一区中文字幕| 欧美日韩国产三级|