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

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

?? serialport.cpp

?? 功能主要是串口通信和網(wǎng)絡(luò)通信方面的
?? CPP
?? 第 1 頁(yè) / 共 2 頁(yè)
字號(hào):
//
BOOL CSerialPort::StartMonitoring()
{
	if (!(m_Thread = AfxBeginThread(CommThread, this)))
		return FALSE;
	TRACE("Thread started\n");
	return TRUE;	
}

//
// Restart the comm thread
//
BOOL CSerialPort::RestartMonitoring()
{
	TRACE("Thread resumed\n");
	m_Thread->ResumeThread();
	return TRUE;	
}


//
// Suspend the comm thread
//
BOOL CSerialPort::StopMonitoring()
{
	TRACE("Thread suspended\n");
	m_Thread->SuspendThread(); 
	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
//							strlen((char*)port->m_szWriteBuffer),	// Length of message to send
							port->m_nWriteSize,	// 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 != (DWORD)port->m_nWriteSize)	// Length of message to send)
	{
		TRACE("WARNING: WriteFile() error.. Bytes Sent: %d; Message Length: %d\n", BytesSent, strlen((char*)port->m_szWriteBuffer));
	}
//	::SendMessage((port->m_pOwner)->m_hWnd, WM_COMM_TXEMPTY_DETECTED, (WPARAM) RXBuff, (LPARAM) port->m_nPortNr);
//	::SendMessage((port->m_pOwner)->m_hWnd, WM_COMM_TXEMPTY_DETECTED,0,(LPARAM) port->m_nPortNr);
}

//
// 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
		::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(char* string)
{		
	assert(m_hComm != 0);
	
	memset(m_szWriteBuffer, 0, sizeof(m_szWriteBuffer));
//	strcpy(m_szWriteBuffer, string);
	_mbscpy(m_szWriteBuffer, (BYTE*)string);
	m_nWriteSize=strlen(string);

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


void CSerialPort::WriteToPort(char* string,int n)
{		
	assert(m_hComm != 0);

	memset(m_szWriteBuffer, 0, sizeof(m_szWriteBuffer));
//	memset(m_szWriteBuffer, 0, n);
//	strncpy(m_szWriteBuffer, string, n);
	memcpy(m_szWriteBuffer, string, n);
	m_nWriteSize=n;

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

void CSerialPort::WriteToPort(LPCTSTR string)
{		
	assert(m_hComm != 0);

	memset(m_szWriteBuffer, 0, sizeof(m_szWriteBuffer));
//	strcpy(m_szWriteBuffer, string);
	_mbscpy(m_szWriteBuffer, (BYTE*)string);
	m_nWriteSize=strlen(string);

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

void CSerialPort::WriteToPort(LPCTSTR string,int n)
{		
	assert(m_hComm != 0);

	memset(m_szWriteBuffer, 0, sizeof(m_szWriteBuffer));
//	strncpy(m_szWriteBuffer, string, n);
	memcpy(m_szWriteBuffer, string, n);
	m_nWriteSize=n;
	// set event for write
	SetEvent(m_hWriteEvent);
}

void CSerialPort::WriteToPort(BYTE* string,int n)
{		
	assert(m_hComm != 0);
	
	memset(m_szWriteBuffer, 0, sizeof(m_szWriteBuffer));
	//	strncpy(m_szWriteBuffer, string, n);
	memcpy(m_szWriteBuffer, string, n);
	m_nWriteSize=n;
	// 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;
}


void CSerialPort::ClosePort()
{
		SetEvent(m_hShutdownEvent);
}

/*
void CSerialPort::ClosePort()
{
	do
	{
		SetEvent(m_hShutdownEvent);
	} while (m_bThreadAlive);

	
	// if the port is still opened: close it 
	if (m_hComm != NULL)
	{
		CloseHandle(m_hComm);
		m_hComm = NULL;
	}
	// Close Handles  
	if(m_hShutdownEvent!=NULL)
		CloseHandle( m_hShutdownEvent); 
	if(m_ov.hEvent!=NULL)
		CloseHandle( m_ov.hEvent ); 
	if(m_hWriteEvent!=NULL)
		CloseHandle( m_hWriteEvent ); 

	TRACE("Thread ended\n");
	delete [] m_szWriteBuffer;
}

*/

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲国产毛片aaaaa无费看| 欧美放荡的少妇| 亚洲国产成人av| 中文字幕免费在线观看视频一区| 欧美色欧美亚洲另类二区| 国产乱码精品一区二区三区av | 日韩欧美国产小视频| 成人毛片在线观看| 激情六月婷婷久久| 日韩中文字幕亚洲一区二区va在线| 亚洲欧洲精品成人久久奇米网| 欧美日韩精品系列| 日韩不卡一二三区| 亚洲综合免费观看高清完整版| 国产人成亚洲第一网站在线播放| 日韩欧美在线123| 欧美日韩在线播放三区四区| 99视频超级精品| 成人午夜在线播放| 韩国女主播一区| 麻豆国产精品777777在线| 亚洲国产美女搞黄色| 亚洲美女免费在线| 亚洲三级在线播放| 亚洲欧美怡红院| 亚洲欧洲色图综合| 国产精品国产自产拍在线| 中文字幕成人在线观看| 欧美激情综合网| 国产三级精品三级在线专区| 久久精品在线观看| 国产欧美日韩精品一区| 久久精品视频免费| 国产欧美精品区一区二区三区 | 精品少妇一区二区三区在线播放| 欧美三级在线看| 欧美主播一区二区三区| 欧美性色黄大片| 欧美精品视频www在线观看| 欧美老肥妇做.爰bbww| 欧美日韩高清影院| 欧美一区二区私人影院日本| 91精品国模一区二区三区| 欧美精品第一页| 欧美tickling挠脚心丨vk| xvideos.蜜桃一区二区| 久久综合成人精品亚洲另类欧美 | 欧美性一二三区| 欧美私模裸体表演在线观看| 精品视频999| 日韩午夜在线播放| 国产亚洲综合性久久久影院| 欧美—级在线免费片| 亚洲婷婷国产精品电影人久久| 亚洲欧洲制服丝袜| 午夜日韩在线电影| 激情六月婷婷久久| 成人高清在线视频| 欧美伊人久久大香线蕉综合69 | 欧美综合在线视频| 欧美精品vⅰdeose4hd| 精品国精品国产| 国产精品久久久久久久久免费桃花| 三级成人在线视频| 国产麻豆一精品一av一免费| 丁香婷婷综合色啪| 欧美亚洲国产怡红院影院| 欧美一级精品在线| 国产精品丝袜在线| 亚洲成人tv网| 国产在线不卡一区| 色94色欧美sute亚洲13| 精品日韩av一区二区| 亚洲欧美在线高清| 日本视频中文字幕一区二区三区| 国产91在线|亚洲| 欧美日韩一区二区在线观看视频| 欧美变态口味重另类| 亚洲视频一区在线| 激情成人午夜视频| 欧洲视频一区二区| 久久久久久久久久看片| 一区二区三区中文字幕| 国产麻豆成人传媒免费观看| 欧美在线视频你懂得| 久久久久成人黄色影片| 五月婷婷综合激情| 成人app网站| 日韩欧美国产一区二区三区 | 国产日韩欧美精品在线| 亚洲成人高清在线| av电影在线观看一区| 欧美sm极限捆绑bd| 午夜日韩在线观看| 99re热这里只有精品视频| 精品国产一区二区三区久久久蜜月 | 蜜臀久久久久久久| 不卡视频一二三四| 26uuu国产在线精品一区二区| 一区二区三区**美女毛片| 国产精品 欧美精品| 91精品在线麻豆| 亚洲影院在线观看| 成人黄色av网站在线| 精品国产一区二区亚洲人成毛片| 亚洲一线二线三线视频| 99视频精品免费视频| 国产亚洲一区二区在线观看| 蜜桃一区二区三区在线观看| 欧美日韩国产经典色站一区二区三区| 日韩一区有码在线| 高清国产午夜精品久久久久久| 日韩欧美国产电影| 日韩黄色一级片| 欧美理论片在线| 亚洲成av人片www| 在线精品视频一区二区| 日韩一区日韩二区| a美女胸又www黄视频久久| 欧美国产亚洲另类动漫| 国产精品一区二区三区99| 精品噜噜噜噜久久久久久久久试看| 日日摸夜夜添夜夜添国产精品 | 国产精品欧美一区二区三区| 韩国v欧美v日本v亚洲v| 精品国产免费人成电影在线观看四季| 日日噜噜夜夜狠狠视频欧美人| 精品1区2区3区| 亚洲成av人综合在线观看| 欧美三级中文字幕| 天堂va蜜桃一区二区三区漫画版| 欧亚一区二区三区| 亚洲成人av一区二区三区| 欧美日韩一区二区电影| 亚洲va欧美va人人爽| 欧美精品一二三四| 蜜桃av一区二区在线观看| 精品美女被调教视频大全网站| 久久se这里有精品| 国产清纯白嫩初高生在线观看91| 国产激情一区二区三区四区| 国产精品免费视频一区| 99久久久免费精品国产一区二区| 成人免费一区二区三区视频| 在线欧美日韩国产| 亚洲国产精品视频| 日韩一区二区三区精品视频| 国产揄拍国内精品对白| 国产日韩精品久久久| thepron国产精品| 亚洲制服欧美中文字幕中文字幕| 在线播放国产精品二区一二区四区 | 亚洲国产精品视频| 欧美一区二区三区四区视频| 精久久久久久久久久久| 国产精品嫩草影院av蜜臀| 91福利视频久久久久| 日本中文字幕一区二区视频| 亚洲精品一区二区三区蜜桃下载| 成人永久aaa| 亚洲大片免费看| 久久综合久久鬼色中文字| 不卡电影一区二区三区| 午夜精品在线看| 久久一二三国产| 色偷偷成人一区二区三区91| 日韩电影在线一区二区三区| 日本一区二区综合亚洲| 欧美日韩一区精品| 国产一区二区三区电影在线观看| 成人欧美一区二区三区在线播放| 欧美日韩亚洲综合一区二区三区| 韩国成人福利片在线播放| 亚洲精品自拍动漫在线| 日韩一区二区精品在线观看| 成人福利电影精品一区二区在线观看 | 欧美经典三级视频一区二区三区| 在线观看91视频| 国产精品羞羞答答xxdd| 亚洲影视资源网| 国产日韩成人精品| 欧美一区二区网站| 一本色道a无线码一区v| 精品亚洲欧美一区| 亚洲一二三四区不卡| 国产人成亚洲第一网站在线播放| 欧美日韩色综合| av中文字幕不卡| 精品亚洲成a人在线观看| 亚洲精品免费一二三区| 久久久亚洲国产美女国产盗摄| 欧美探花视频资源| www.久久精品| 国产毛片一区二区| 轻轻草成人在线| 亚洲一二三四区| 中文字幕一区二区三区av| 精品国产自在久精品国产| 欧美日韩aaaaa| 在线视频国产一区|