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

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

?? serialport.cpp

?? 接受GPGGA語句的VC程序
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
	TRACE("Thread resumed\n");
	m_Thread->ResumeThread();
	return TRUE;	
}


//
// Suspend the comm thread
//
BOOL CSerialPortEx::StopMonitoring()
{
	TRACE("Thread suspended\n");
	if(m_bThreadAlive)
	{
		m_Thread->SuspendThread(); 
		m_bThreadAlive=FALSE;
	}
	return TRUE;	
}


//
// If there is a error, give the right message
//
void CSerialPortEx::ProcessErrorMessage(char* ErrorText)
{
	char *Temp = new char[200];
	
	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, "WARNING:  %s Failed with the following error: \n%s\nPort: %d\n", (char*)ErrorText, lpMsgBuf, m_nPortNr); 
	MessageBox(NULL, Temp, "Application Error", MB_ICONSTOP);

	LocalFree(lpMsgBuf);
	delete[] Temp;
}

//
// Write a character.
//
void CSerialPortEx::WriteChar(CSerialPortEx* 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->m_nToSend,								// 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
	if (BytesSent != port->m_nToSend)
	{
		TRACE("WARNING: WriteFile() error.. Bytes Sent: %d; Message Length: %d\n", BytesSent, strlen((char*)port->m_szWriteBuffer));
	}
}

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

	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
		::SendMessage((port->m_pOwner)->m_hWnd, WM_COMM_RXCHAR, (WPARAM) RXBuff, (LPARAM) port->m_nPortNr);
	} // end forever loop

}

//
// Write a string to the port
//
void CSerialPortEx::WriteToPort(BYTE* string,int nLength)
{		
//	assert(m_hComm != 0);
	if(m_hComm==0) 
	{
		::AfxMessageBox("error strange");
		return;
	}
	
	memset(m_szWriteBuffer, 0, m_nWriteBufferSize);
	memcpy(m_szWriteBuffer, string,nLength);
	m_nToSend=nLength;

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

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

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

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


//Extension: not tested

BYTE* CSerialPortEx::ReadBlock(CSerialPortEx *port, int& readLen)
{

	COMSTAT comstat;
	BOOL  bRead = TRUE; 
	BOOL  bResult = TRUE;
	DWORD dwError = 0;
	DWORD BytesRead = 0;
	DWORD BytesToRead;
	BYTE* pRec;


		// 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
			readLen=0;
			return NULL;
		}

		BytesToRead= comstat.cbInQue;
		pRec=new BYTE[BytesToRead];

		EnterCriticalSection(&port->m_csCommunicationSync);

		if (bRead)
		{
			bResult = ReadFile(port->m_hComm,		// Handle to COMM port 
							   pRec,				// Reader Buffer Pointer
							   BytesToRead,			// to read bytes
							   &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);
		
		readLen=BytesRead;
		return pRec;

}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品国久久99热| 中文字幕五月欧美| 亚洲欧洲成人精品av97| 五月综合激情日本mⅴ| 99久久精品99国产精品| 日韩欧美在线综合网| 亚洲免费观看在线视频| 国产在线播放一区三区四| 欧美精品一二三| 亚洲精品成人在线| 成人91在线观看| 久久天堂av综合合色蜜桃网| 午夜久久久久久久久| 99精品国产一区二区三区不卡| 精品国产麻豆免费人成网站| 亚洲美女电影在线| 99久久婷婷国产| 欧美成人综合网站| 免费av网站大全久久| 欧美吻胸吃奶大尺度电影 | 日韩视频免费直播| 国产精品久久夜| 免费观看日韩电影| 欧美人妖巨大在线| 亚洲第一久久影院| 欧美日韩一区二区电影| 亚洲欧美另类小说视频| 成人午夜免费视频| 亚洲精品一区二区三区福利 | 国产网站一区二区| 精品亚洲国内自在自线福利| 欧美成人a在线| 久久丁香综合五月国产三级网站| 6080日韩午夜伦伦午夜伦| 午夜精品久久久久久久久| 精品视频在线免费| 日韩国产在线观看| 欧美成人乱码一区二区三区| 狂野欧美性猛交blacked| 精品伦理精品一区| 国产一区不卡精品| 综合欧美亚洲日本| 94-欧美-setu| 国产精品久久综合| 99国产精品99久久久久久| 欧美极品另类videosde| 99精品国产热久久91蜜凸| 综合电影一区二区三区| 国产91精品一区二区| 久久久久综合网| 国产寡妇亲子伦一区二区| 中文一区一区三区高中清不卡| 日韩一区在线看| 亚洲欧洲精品一区二区精品久久久| 亚洲综合在线电影| 国产成人自拍网| 制服丝袜亚洲色图| 麻豆国产精品视频| 久久综合九色综合欧美98| 亚洲第一福利视频在线| 91麻豆精品国产无毒不卡在线观看| 五月天一区二区三区| 欧洲日韩一区二区三区| 亚洲成人综合在线| 精品电影一区二区| 国产91丝袜在线播放九色| 中文字幕不卡在线播放| 91蜜桃免费观看视频| 日本色综合中文字幕| 久久精品一区八戒影视| 一本大道久久a久久综合婷婷| 亚洲一区视频在线| 5月丁香婷婷综合| 国产乱理伦片在线观看夜一区| 亚洲日本在线a| 日韩欧美国产一区二区在线播放| 波多野结衣中文字幕一区| 午夜影院在线观看欧美| 欧美zozo另类异族| 色综合天天做天天爱| 免费日韩伦理电影| 亚洲人精品午夜| 久久久99精品久久| 欧美精品一卡二卡| 91在线码无精品| 国产一二精品视频| 亚洲妇女屁股眼交7| 国产亚洲va综合人人澡精品| 日本道色综合久久| 国产**成人网毛片九色| 免费成人结看片| 午夜精品久久久久久| 成人欧美一区二区三区1314| 678五月天丁香亚洲综合网| 91黄视频在线观看| 国产不卡视频在线播放| 日韩在线一二三区| 一区二区三区在线观看欧美| 国产精品亲子伦对白| 日韩欧美色电影| 555www色欧美视频| 欧美日韩午夜在线| www.一区二区| 国产成人精品免费一区二区| 久久97超碰国产精品超碰| 婷婷成人综合网| 亚洲人成7777| 综合电影一区二区三区| 欧美国产日韩在线观看| 久久蜜臀中文字幕| 26uuu欧美日本| 日韩亚洲欧美中文三级| 日韩一区二区三区免费看| 欧美人妇做爰xxxⅹ性高电影| av电影一区二区| 国产成a人无v码亚洲福利| 国模娜娜一区二区三区| 国产真实乱偷精品视频免| 精品一区二区三区久久| 天涯成人国产亚洲精品一区av| 国产欧美视频在线观看| 久久久国产午夜精品| 久久影音资源网| 国产三区在线成人av| 国产亚洲精品aa| 国产精品午夜免费| 国产精品久久精品日日| 亚洲欧美日韩国产综合| 一区二区在线电影| 亚洲第一搞黄网站| 亚洲成av人影院| 麻豆成人综合网| 国产jizzjizz一区二区| av一区二区三区四区| 色综合久久久久综合体桃花网| 欧美三级视频在线| 日韩欧美精品三级| 中文字幕欧美激情一区| 亚洲激情五月婷婷| 日韩专区在线视频| 国产一区二区电影| 91麻豆文化传媒在线观看| 欧美久久久久久蜜桃| 精品国产91乱码一区二区三区 | 国产自产2019最新不卡| 国产成人精品一区二| 色婷婷综合久久| 欧美一区二区三区不卡| 国产精品免费观看视频| 亚洲国产欧美日韩另类综合 | 午夜精品123| 九一九一国产精品| 91在线你懂得| 精品毛片乱码1区2区3区| 日韩一区在线看| 蜜臀a∨国产成人精品| 成人免费看片app下载| 91九色最新地址| 日韩欧美一区二区久久婷婷| 久久网站最新地址| 亚洲午夜羞羞片| 国产精品一卡二| 欧美日韩大陆一区二区| 国产午夜久久久久| 亚洲v中文字幕| av成人动漫在线观看| 日韩一级片在线观看| 亚洲啪啪综合av一区二区三区| 奇米888四色在线精品| 色综合久久精品| 久久天天做天天爱综合色| 一区二区高清在线| 91在线观看高清| 精品国产一区二区三区忘忧草| 亚洲一区在线观看网站| 国产精品66部| 精品电影一区二区三区| 男人的j进女人的j一区| 色综合网站在线| 中文欧美字幕免费| 激情都市一区二区| 欧美乱妇15p| 亚洲美女淫视频| 国产98色在线|日韩| 精品日韩99亚洲| 奇米影视在线99精品| 99精品视频在线观看| 久久精品人人做人人爽人人| 麻豆国产欧美日韩综合精品二区 | 国产一区二区在线看| 在线观看精品一区| 亚洲欧美一区二区三区极速播放 | 欧美日本免费一区二区三区| 中文字幕免费不卡在线| 日韩高清一区二区| 欧美三级电影一区| 成人欧美一区二区三区视频网页| 国产成人综合视频| 中文字幕免费不卡| 不卡电影免费在线播放一区|