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

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

?? serialport.cpp

?? 用c++編寫的云臺控制程序,可以實現(xiàn)云臺的基本動作.
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
BOOL CSerialPort::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 CSerialPort::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 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->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 CSerialPort::ReceiveChar(CSerialPort* 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 CSerialPort::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 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;
}


//Extension: not tested
BYTE* CSerialPort::ReadBlock(CSerialPort *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;
		}
		else
		{
			BytesToRead= nPackSize+2 > comstat.cbInQue ? comstat.cbInQue : nPackSize+2;
			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;

		// notify parent that a byte was received
//		::SendMessage((port->m_pOwner)->m_hWnd, WM_COMM_RXCHAR, (WPARAM)pRec, (LPARAM) BytesRead);

}

void CSerialPort::ClosePort()
{
	if (m_bThreadAlive)
	{
		do
		{
			SetEvent(m_hShutdownEvent);
		} while (m_bThreadAlive);
		TRACE("Thread ended\n");
	}

	if (m_hComm != NULL)
	{
		CloseHandle(m_hComm);
		m_hComm = NULL;
	}
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品电影院| 国产成人在线视频网址| 国产一区在线看| 91久久精品一区二区二区| 精品国产乱码久久久久久夜甘婷婷 | 视频一区在线播放| 国产v日产∨综合v精品视频| 欧美日韩高清一区二区三区| 国产精品久久久一本精品 | 欧美日韩精品欧美日韩精品一| 久久精品日韩一区二区三区| 午夜欧美视频在线观看 | 依依成人综合视频| 丰满白嫩尤物一区二区| 久久五月婷婷丁香社区| 日本女优在线视频一区二区| 在线观看日韩高清av| 中文字幕在线不卡一区二区三区| 久久99久国产精品黄毛片色诱| 欧美吻胸吃奶大尺度电影| 亚洲欧美日韩在线播放| 成人三级伦理片| 中文av字幕一区| 国产馆精品极品| 国产网红主播福利一区二区| 国产美女主播视频一区| 精品国产在天天线2019| 麻豆成人91精品二区三区| 欧美欧美欧美欧美首页| 亚洲成av人**亚洲成av**| 欧美性极品少妇| 亚洲成人免费视| 欧美精品自拍偷拍动漫精品| 天天影视涩香欲综合网| 欧美老年两性高潮| 欧美aaaaa成人免费观看视频| 制服丝袜亚洲播放| 免费看欧美女人艹b| 91精品国产综合久久精品app | 在线不卡中文字幕播放| 日韩黄色一级片| 日韩欧美黄色影院| 黄色精品一二区| 国产亚洲成年网址在线观看| 成人性生交大片免费看中文| 国产精品嫩草99a| 一本久道中文字幕精品亚洲嫩| 亚洲另类春色国产| 欧美午夜精品一区二区三区| 人人爽香蕉精品| 欧美精品一区二区三区蜜桃 | 国产精品久久二区二区| 色综合一区二区| 视频在线观看91| 国产午夜亚洲精品不卡| 91丨九色porny丨蝌蚪| 一区二区三区欧美在线观看| 4438成人网| 国产伦精品一区二区三区视频青涩| 国产婷婷色一区二区三区四区| 99久久99久久免费精品蜜臀| 亚洲午夜电影在线| 亚洲精品一区二区三区香蕉 | 亚洲另类在线视频| 日韩亚洲国产中文字幕欧美| 成人激情av网| 丝袜脚交一区二区| 欧美国产精品劲爆| 欧美高清一级片在线| 国产福利91精品| 亚洲成人动漫在线免费观看| 日韩欧美国产不卡| 91丨porny丨首页| 久久精品国产色蜜蜜麻豆| 1024成人网| 精品三级在线看| 在线观看成人小视频| 国产成人精品1024| 日本欧洲一区二区| 亚洲另类在线一区| 欧美国产综合色视频| 欧美剧情片在线观看| 成人18视频日本| 久久精品国产一区二区三| 亚洲女同一区二区| 国产喷白浆一区二区三区| 欧美乱熟臀69xxxxxx| 91小宝寻花一区二区三区| 国产精品伊人色| 日韩激情视频网站| 亚洲久本草在线中文字幕| 日韩精品一区二区三区swag | 国产日韩精品一区二区浪潮av | 美女视频网站黄色亚洲| 一区二区视频在线看| 中文字幕欧美日韩一区| 久久久久久亚洲综合| 日韩一级片网站| 欧美日韩一区二区在线观看| 色老头久久综合| 99精品偷自拍| av日韩在线网站| 国产91精品露脸国语对白| 久久国产精品99精品国产| 日韩高清在线不卡| 一二三四区精品视频| 亚洲精品国产视频| 亚洲免费在线电影| 中文字幕一区二区三区视频| 国产精品素人一区二区| 久久综合九色综合97婷婷| 精品国产伦一区二区三区免费 | 国产一区视频在线看| 麻豆国产91在线播放| 久久精品国产亚洲一区二区三区 | 欧美精品一区视频| 26uuu另类欧美| 国产亚洲1区2区3区| 国产日韩av一区| 国产精品成人午夜| 亚洲欧美激情插| 午夜a成v人精品| 蜜桃视频一区二区三区| 精品一区二区免费在线观看| 国产在线一区观看| 成人精品一区二区三区四区| 99久久久久免费精品国产| 一本大道综合伊人精品热热| 在线视频观看一区| 欧美肥妇bbw| 久久日韩粉嫩一区二区三区| 国产精品免费人成网站| 一区二区在线看| 日韩av在线发布| 国产成人av一区二区三区在线 | 国产精品1区2区3区在线观看| 国产在线一区二区综合免费视频| 国产成人免费在线| 在线精品视频小说1| 欧美一区二区三区在线观看| 久久一区二区视频| 综合av第一页| 视频一区在线视频| 国产精品12区| 精品视频123区在线观看| 欧美变态tickling挠脚心| 日本一区二区三区四区| 一区二区三区在线免费| 欧美aⅴ一区二区三区视频| 成人听书哪个软件好| 欧美三级一区二区| 国产亚洲精品7777| 图片区小说区区亚洲影院| 国产精品一区二区在线播放| 一本大道av一区二区在线播放 | 国内精品在线播放| 91丨国产丨九色丨pron| 精品久久久久久久久久久院品网 | 久久久精品2019中文字幕之3| 欧美久久一区二区| 精品国产成人在线影院 | 日韩一区二区三区电影在线观看 | 日韩欧美高清一区| 亚洲欧洲成人精品av97| 全国精品久久少妇| 色综合色狠狠综合色| www国产精品av| 五月婷婷色综合| 99久久精品国产毛片| 久久新电视剧免费观看| 亚洲国产视频在线| 成人妖精视频yjsp地址| 欧美不卡在线视频| 日日夜夜精品视频免费| 91女厕偷拍女厕偷拍高清| 精品国产欧美一区二区| 日日摸夜夜添夜夜添亚洲女人| 99久久国产免费看| 国产午夜久久久久| 激情文学综合插| 日韩一级在线观看| 午夜天堂影视香蕉久久| 99精品欧美一区| 国产精品无遮挡| 国产精品一区二区男女羞羞无遮挡| 欧美日韩在线播放三区| 亚洲欧美一区二区久久| eeuss鲁片一区二区三区在线观看| 久久日韩精品一区二区五区| 午夜亚洲国产au精品一区二区| 在线欧美一区二区| 玉足女爽爽91| 在线观看日韩一区| 亚洲激情图片qvod| 91麻豆成人久久精品二区三区| 欧美高清在线精品一区| 国产黄色精品网站| 中文字幕欧美三区| 成人aaaa免费全部观看| 自拍av一区二区三区|