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

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

?? mcom.cpp

?? 串口通訊,采用異步方式,采用回調(diào)上傳數(shù)據(jù)
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
		// Main wait function.  This function will normally block the thread
		// until one of nine events occur that require action.
		Event = WaitForMultipleObjects(3, port->m_hEventArray, FALSE, INFINITE);

		switch (Event)
		{
		case 0:
			{
				// Shutdown event.  This is event zero so it will be
				// the higest priority and be serviced first.

			 	port->m_bThreadAlive = FALSE;
				
				// Kill this thread.  break is not needed, but makes me feel better.
				AfxEndThread(100);
				break;
			}
		case 1:	// read event
			{
				GetCommMask(port->m_hComm, &CommEvent);
				if ((CommEvent & EV_CTS)	&&(port->Com_Event)) port->Com_Event(port->m_hWnd,COMM_CTS_DETECTED,port->m_nPortNr,0);
				if ((CommEvent & EV_RXFLAG) &&(port->Com_Event)) port->Com_Event(port->m_hWnd,COMM_RXFLAG_DETECTED,port->m_nPortNr,0);
				if ((CommEvent & EV_BREAK)	&&(port->Com_Event)) port->Com_Event(port->m_hWnd,COMM_BREAK_DETECTED,port->m_nPortNr,0);
				if ((CommEvent & EV_ERR)	&&(port->Com_Event)) port->Com_Event(port->m_hWnd,COMM_ERR_DETECTED,port->m_nPortNr,0);
				if ((CommEvent & EV_RING)	&&(port->Com_Event)) port->Com_Event(port->m_hWnd,COMM_RING_DETECTED,port->m_nPortNr,0);
				if (CommEvent & EV_RXCHAR)	ReceiveChar(port, comstat);	// Receive character event from port.
				break;
			}  
		case 2: // write event
			{
				// Write character event from port
				WriteChar(port);
				break;
			}

		} // end switch

	} // close forever loop

	return 0;
}

//
// start comm watching
//
BOOL CSerialPort::StartMonitoring()
{
	if (!(m_Thread = AfxBeginThread(CommThread, this)))
		return FALSE;
	TRACE("串口通訊線程開始\n");
	return TRUE;	
}

//
// Restart the comm thread
//
BOOL CSerialPort::RestartMonitoring()
{
	TRACE("串口通訊線程重置\n");
	m_Thread->ResumeThread();
	return TRUE;	
}


//
// Suspend the comm thread
//
BOOL CSerialPort::StopMonitoring()
{
	TRACE("串口通訊暫停\n");
	m_Thread->SuspendThread(); 
	return TRUE;	
}


//
// If there is a error, give the right message
//
void CSerialPort::ProcessErrorMessage(char* ErrorText)
{
	char *Temp = new char[512];
	
	LPVOID lpMsgBuf;

	FormatMessage( 
		FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
		NULL,
		GetLastError(),
		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
		(LPTSTR) &lpMsgBuf,
		0,
		NULL 
	);

	sprintf(Temp, "警告:  %s 在下列地方產(chǎn)生錯誤: \n%s\nPort: %d\n", (char*)ErrorText, lpMsgBuf, m_nPortNr); 
	MessageBox(NULL, Temp, "程序錯誤", MB_ICONSTOP);

	LocalFree(lpMsgBuf);
	delete[] Temp;
}

//
// Write a character.
//
void CSerialPort::WriteChar(CSerialPort* port)
{
	BOOL bWrite = TRUE;
	BOOL bResult = TRUE;

	DWORD BytesSent = 0;

	ResetEvent(port->m_hWriteEvent);

	// Gain ownership of the critical section
	EnterCriticalSection(&port->m_csCommunicationSync);

	if (bWrite)
	{
		// Initailize variables
		port->m_ov.Offset = 0;
		port->m_ov.OffsetHigh = 0;

		// Clear buffer
		PurgeComm(port->m_hComm, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);

		bResult = WriteFile(port->m_hComm,			// Handle to COMM Port
							port->m_szWriteBuffer,	// Pointer to message buffer in calling finction
							port->iWriteLen,		// Length of message to send
							&BytesSent,				// Where to store the number of bytes sent
							&port->m_ov);			// Overlapped structure

		// deal with any error codes
		if (!bResult)  
		{
			DWORD dwError = GetLastError();
			switch (dwError)
			{
				case ERROR_IO_PENDING:
					{
						// continue to GetOverlappedResults()
						BytesSent = 0;
						bWrite = FALSE;
						break;
					}
				default:
					{
						// all other error codes
						port->ProcessErrorMessage("WriteFile()");
					}
			}
		} 
		else
		{
			LeaveCriticalSection(&port->m_csCommunicationSync);
		}
	} // end if(bWrite)

	if (!bWrite)
	{
		bWrite = TRUE;
	
		bResult = GetOverlappedResult(port->m_hComm,	// Handle to COMM port 
									  &port->m_ov,		// Overlapped structure
									  &BytesSent,		// Stores number of bytes sent
									  TRUE); 			// Wait flag

		LeaveCriticalSection(&port->m_csCommunicationSync);

		// deal with the error code 
		if (!bResult)  
		{
			port->ProcessErrorMessage("GetOverlappedResults() in WriteFile()");
		}	
	} // end if (!bWrite)

	// Verify that the data size send equals what we tried to send
	#ifdef _DEBUG
		if (BytesSent != DWORD(port->iWriteLen))
			TRACE("警告: WriteFile() 錯誤.. 向串口:%d 已發(fā)送字節(jié): %d; 信息長度: %d\n", port->m_nPortNr ,BytesSent, port->iWriteLen);
	//	else TRACE("向串口:%d 發(fā)送字節(jié):%d Byte\n",port->m_nPortNr ,BytesSent);
	#endif
}

//
// Character received. Inform the owner
//
void CSerialPort::ReceiveChar(CSerialPort* port, COMSTAT comstat)
{
	BOOL  bRead = TRUE; 
	BOOL  bResult = TRUE;
	DWORD dwError = 0;
	DWORD BytesRead = 0;
	unsigned char RXBuff;

	for (;;) 
	{ 
		// Gain ownership of the comm port critical section.
		// This process guarantees no other part of this program 
		// is using the port object. 
		
		EnterCriticalSection(&port->m_csCommunicationSync);

		// ClearCommError() will update the COMSTAT structure and
		// clear any other errors.
		
		bResult = ClearCommError(port->m_hComm, &dwError, &comstat);

		LeaveCriticalSection(&port->m_csCommunicationSync);

		// start forever loop.  I use this type of loop because I
		// do not know at runtime how many loops this will have to
		// run. My solution is to start a forever loop and to
		// break out of it when I have processed all of the
		// data available.  Be careful with this approach and
		// be sure your loop will exit.
		// My reasons for this are not as clear in this sample 
		// as it is in my production code, but I have found this 
		// solutiion to be the most efficient way to do this.
		
		if (comstat.cbInQue == 0)
		{
			// break out when all bytes have been read
			break;
		}
						
		EnterCriticalSection(&port->m_csCommunicationSync);

		if (bRead)
		{
			bResult = ReadFile(port->m_hComm,		// Handle to COMM port 
							   &RXBuff,				// RX Buffer Pointer
							   1,					// Read one byte
							   &BytesRead,			// Stores number of bytes read
							   &port->m_ov);		// pointer to the m_ov structure
			// deal with the error code 
			if (!bResult)  
			{ 
				switch (dwError = GetLastError()) 
				{ 
					case ERROR_IO_PENDING: 	
						{ 
							// asynchronous i/o is still in progress 
							// Proceed on to GetOverlappedResults();
							bRead = FALSE;
							break;
						}
					default:
						{
							// Another error has occured.  Process this error.
							port->ProcessErrorMessage("ReadFile()");
							break;
						} 
				}
			}
			else
			{
				// ReadFile() returned complete. It is not necessary to call GetOverlappedResults()
				bRead = TRUE;
			}
		}  // close if (bRead)

		if (!bRead)
		{
			bRead = TRUE;
			bResult = GetOverlappedResult(port->m_hComm,	// Handle to COMM port 
										  &port->m_ov,		// Overlapped structure
										  &BytesRead,		// Stores number of bytes read
										  TRUE); 			// Wait flag

			// deal with the error code 
			if (!bResult)  
			{
				port->ProcessErrorMessage("GetOverlappedResults() in ReadFile()");
			}	
		}  // close if (!bRead)
				
		LeaveCriticalSection(&port->m_csCommunicationSync);

		// notify parent that a byte was received
		if (port->Com_Event) port->Com_Event(port->m_hWnd,COMM_RXCHAR,port->m_nPortNr,RXBuff);
	} // end forever loop

}

//
// Write a string to the port
//
void CSerialPort::WriteToPort(PVOID string,int len)
{		
	assert(m_hComm != 0);
	iWriteLen=len;
	memset(m_szWriteBuffer, 0, m_nWriteBufferSize);
	memcpy(m_szWriteBuffer, string,len);

	// set event for write
	SetEvent(m_hWriteEvent);
}

//
// Return the device control block
//
DCB CSerialPort::GetDCB()
{
	return m_dcb;
}

//
// Return the communication event masks
//
DWORD CSerialPort::GetCommEvents()
{
	return m_dwCommEvents;
}

//
// Return the output buffer size
//
DWORD CSerialPort::GetWriteBufferSize()
{
	return m_nWriteBufferSize;
}


?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色视频成人在线观看免| 激情文学综合插| 色欧美乱欧美15图片| 一区二区三区在线免费观看| 在线观看亚洲精品| 免费一区二区视频| 久久久久久久久久久99999| 成人精品视频网站| 一区二区在线免费观看| 51精品久久久久久久蜜臀| 美国十次了思思久久精品导航| 日韩午夜精品视频| 国产成人精品免费在线| 亚洲精品亚洲人成人网在线播放| 欧美日韩精品福利| 国产一二三精品| 亚洲色图欧美激情| 91精品国产一区二区三区香蕉| 国产永久精品大片wwwapp| 国产精品久久久久四虎| 欧美日韩一区二区三区四区五区| 免费成人av资源网| 国产精品福利电影一区二区三区四区| 欧美视频一区在线| 国产不卡视频一区| 亚洲一二三四在线观看| 久久综合色之久久综合| 91在线视频官网| 毛片av中文字幕一区二区| 中文字幕第一区二区| 91麻豆精品91久久久久久清纯| 国产一区二区免费在线| 亚洲一区二区中文在线| 久久亚洲二区三区| 欧美日韩国产一二三| 国产成人午夜精品影院观看视频| 亚洲网友自拍偷拍| 国产精品私人影院| 精品免费国产一区二区三区四区| 色综合天天综合| 国产精品自拍av| 亚洲第一成年网| 亚洲欧洲一区二区三区| 精品成人a区在线观看| 欧美网站一区二区| 99久久伊人精品| 久久99国产精品尤物| 亚洲高清免费视频| 亚洲免费色视频| 久久精品夜色噜噜亚洲aⅴ| 欧美一区日本一区韩国一区| 91麻豆国产精品久久| 国产精品77777竹菊影视小说| 日本在线不卡一区| 亚洲老妇xxxxxx| 中文字幕av一区二区三区高| 精品久久久久久久久久久久包黑料 | 亚洲免费观看高清| 亚洲国产成人午夜在线一区| 欧美成人女星排名| 91精品欧美综合在线观看最新| 日本精品一级二级| 97精品电影院| 不卡影院免费观看| 粉嫩av一区二区三区在线播放| 久久99蜜桃精品| 久久精品国产999大香线蕉| 日本伊人色综合网| 艳妇臀荡乳欲伦亚洲一区| 亚洲欧美另类在线| 亚洲精品乱码久久久久久黑人 | 欧美性色黄大片| 在线免费精品视频| 欧美日韩一区二区电影| 欧美影视一区二区三区| 欧洲亚洲国产日韩| 欧美精品777| 8x8x8国产精品| 日韩午夜在线播放| 久久综合久久综合九色| 久久亚洲精华国产精华液| 久久精品一二三| 中文字幕精品—区二区四季| 中文字幕一区二区5566日韩| 亚洲婷婷综合色高清在线| 成人免费一区二区三区在线观看| 亚洲男人的天堂av| 亚洲一区二区三区影院| 天堂va蜜桃一区二区三区| 视频在线在亚洲| 黄页网站大全一区二区| 成人性生交大片免费| 91女厕偷拍女厕偷拍高清| 色婷婷亚洲精品| 欧美精品一级二级三级| 91精品国产色综合久久不卡电影| 精品对白一区国产伦| 国产精品婷婷午夜在线观看| 亚洲激情校园春色| 日本在线不卡一区| 国产精品 欧美精品| 色综合久久88色综合天天免费| 欧美一a一片一级一片| 91精品国产高清一区二区三区| 欧美一级日韩一级| 国产精品五月天| 亚洲国产另类av| 国产麻豆精品在线观看| 色94色欧美sute亚洲线路一久 | 亚洲精品欧美二区三区中文字幕| 午夜精品福利久久久| 国产乱码精品一区二区三| 97精品电影院| 日韩欧美123| 亚洲图片激情小说| 美女一区二区久久| 成人综合激情网| 欧美人与z0zoxxxx视频| 国产亚洲欧美日韩俺去了| 亚洲韩国一区二区三区| 国产成人免费视频网站| 欧美日韩中文另类| 中文字幕欧美国产| 日韩精品欧美精品| 成av人片一区二区| 欧美va亚洲va香蕉在线| 一区二区三区欧美日韩| 狠狠色丁香婷综合久久| 欧美色图免费看| 国产精品福利一区二区| 久久99精品视频| 欧美日韩在线精品一区二区三区激情 | 亚洲综合色婷婷| 粉嫩av亚洲一区二区图片| 91精品国产一区二区三区蜜臀| 综合色中文字幕| 国产一区二区三区免费观看| 欧美三级日韩三级| 日韩毛片精品高清免费| 国产高清一区日本| 日韩欧美一级在线播放| 亚洲国产精品综合小说图片区| 97精品视频在线观看自产线路二| 精品久久久久一区| 免费成人美女在线观看.| 欧美日韩专区在线| 亚洲一二三专区| 国产午夜精品福利| 日本亚洲三级在线| 日韩亚洲欧美一区二区三区| 国产日韩欧美高清| 久久av中文字幕片| 7777精品伊人久久久大香线蕉 | 日韩精品一级二级| 在线精品视频免费播放| 综合激情成人伊人| av亚洲产国偷v产偷v自拍| 久久久国产精华| 国内久久精品视频| 久久久不卡影院| 国产成人精品在线看| 国产丝袜美腿一区二区三区| 国内精品免费在线观看| 欧美一二三区精品| 精品一区二区在线看| 日韩欧美国产精品| 看片的网站亚洲| 一区二区三区在线观看视频| 99久久久无码国产精品| 亚洲色图欧洲色图婷婷| 色综合天天做天天爱| 亚洲视频一区二区免费在线观看 | 国产综合色视频| ww久久中文字幕| 国产成人免费在线观看不卡| 久久精品一二三| 97se亚洲国产综合自在线观| 亚洲美女屁股眼交| 欧美在线视频你懂得| 视频精品一区二区| 日韩欧美视频在线| 国产成人精品亚洲777人妖 | 精品视频一区 二区 三区| 天天射综合影视| 欧美成人a∨高清免费观看| 国产黑丝在线一区二区三区| 中文字幕在线观看一区二区| 在线一区二区三区四区五区| 午夜精品久久久久久久99水蜜桃 | 久久综合色天天久久综合图片| 国产精品1区2区3区| 亚洲色图在线看| 欧美日韩高清一区二区不卡| 久久精品国产精品青草| 欧美激情在线一区二区三区| 一本大道久久a久久精二百| 肉肉av福利一精品导航| 国产视频一区二区三区在线观看| 一本久久a久久精品亚洲| 麻豆精品一区二区三区|