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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? serialport.cpp

?? 串口雙機互連代碼
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
		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
void CSerialPortEx::WriteToPort(CString str)
{
	
	char *buffer=new char[m_nWriteBufferSize];
	memset(buffer,0,m_nWriteBufferSize);
	int nMaxLength=(str.GetLength()+1 > m_nWriteBufferSize) ? str.GetLength()+1 : m_nWriteBufferSize;
	char *temp=str.GetBuffer(nMaxLength);
	memcpy(buffer,temp,str.GetLength());
	str.ReleaseBuffer();
	WriteToPort((BYTE*)buffer,str.GetLength());
}

//Extension: not tested
//DEL int CSerialPortEx::ReadCommBlock(LPSTR lpszBlock, int nMaxLength)
//DEL {
//DEL    BOOL       fReadStat ;
//DEL    COMSTAT    ComStat ;
//DEL    DWORD      dwErrorFlags;
//DEL    DWORD      dwLength;
//DEL    DWORD      dwError;
//DEL 
//DEL    // only try to read number of bytes in queue
//DEL    BOOL ok=ClearCommError( m_hComm, &dwErrorFlags, &ComStat ) ;
//DEL    dwLength = min( (DWORD) nMaxLength, ComStat.cbInQue ) ;
//DEL 
//DEL    if (dwLength > 0)
//DEL    {
//DEL 	  fReadStat = ::ReadFile(m_hComm,lpszBlock,dwLength,&dwLength,&m_ov) ;
//DEL       if (!fReadStat)
//DEL       {
//DEL          if ((dwError=GetLastError()) == ERROR_IO_PENDING)
//DEL          {
//DEL 
//DEL             while(!GetOverlappedResult( m_hComm,
//DEL                &m_ov, &dwLength, TRUE ))
//DEL             {
//DEL                dwError = GetLastError();
//DEL                if(dwError == ERROR_IO_INCOMPLETE)
//DEL                   // normal result if not finished
//DEL                   continue;
//DEL                else
//DEL                {
//DEL                   // an error occurred, try to recover
//DEL                  ClearCommError( m_hComm, &dwErrorFlags, &ComStat ) ;
//DEL                   break;
//DEL                }
//DEL             }
//DEL 	      }
//DEL          else
//DEL          {
//DEL             // some other error occurred
//DEL             dwLength = 0 ;
//DEL             ClearCommError( m_hComm, &dwErrorFlags, &ComStat ) ;
//DEL           }
//DEL       }
//DEL    }
//DEL    return dwLength ;
//DEL }

//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=readLen;
	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= BytesToRead+2 > comstat.cbInQue ? comstat.cbInQue : BytesToRead+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);

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩免费电影| 国产一级精品在线| 在线播放欧美女士性生活| 色综合 综合色| 91在线免费看| 91精品国产入口在线| 日韩国产在线一| 日韩一区二区免费视频| 久久99精品国产麻豆不卡| 久久亚洲一区二区三区四区| 欧美视频一区二区三区| 亚洲v中文字幕| 精品国产伦一区二区三区观看方式 | 亚洲女与黑人做爰| 在线观看视频欧美| 久久成人免费电影| 国产精品国产a| 69久久夜色精品国产69蝌蚪网| 日韩综合小视频| 在线视频中文字幕一区二区| 久久精品亚洲乱码伦伦中文| 精品一区在线看| 中文字幕不卡在线| 欧美伦理电影网| 国产高清久久久| 亚洲电影在线免费观看| 精品嫩草影院久久| 色综合天天综合网天天狠天天| 午夜国产精品影院在线观看| 精品日韩99亚洲| 91黄色小视频| 国产大陆精品国产| 亚洲第一av色| 国产精品久久久久天堂| 6080午夜不卡| 99久久99久久精品国产片果冻 | 日韩欧美一区在线| 99re亚洲国产精品| 韩国v欧美v亚洲v日本v| 亚洲综合激情小说| 国产精品妹子av| 日韩一级成人av| 91福利国产精品| 国产99一区视频免费| 日本欧美肥老太交大片| 亚洲精品高清视频在线观看| 久久精品男人的天堂| 欧美丰满一区二区免费视频| 色综合天天性综合| 国产精品主播直播| 久久99热这里只有精品| 午夜成人免费电影| 中文字幕日韩精品一区| 久久久久久久久久久黄色| 欧美视频自拍偷拍| 色综合婷婷久久| 不卡区在线中文字幕| 国产一区二区三区电影在线观看| 亚洲成人激情社区| 亚洲国产精品精华液网站 | 亚洲美女淫视频| 国产精品视频看| 国产偷v国产偷v亚洲高清| 国产精品久久久99| 亚洲精品在线免费播放| 欧美一区二区黄色| 欧美男女性生活在线直播观看| av在线不卡网| 9人人澡人人爽人人精品| 国产91精品一区二区麻豆亚洲| 美女脱光内衣内裤视频久久网站| 亚洲国产中文字幕| 亚洲大片在线观看| 亚洲chinese男男1069| 亚洲成人午夜电影| 婷婷亚洲久悠悠色悠在线播放| 亚洲国产精品久久艾草纯爱| 亚洲午夜成aⅴ人片| 亚洲sss视频在线视频| 香蕉影视欧美成人| 热久久国产精品| 男女男精品视频网| 国产一区不卡在线| 懂色av一区二区三区蜜臀| 成人性色生活片免费看爆迷你毛片| 国产一区二区导航在线播放| 国产成人三级在线观看| 国产999精品久久久久久绿帽| 国产成人综合亚洲91猫咪| 国产成人久久精品77777最新版本| 国产精品小仙女| 99久久久精品| 欧美日本在线看| 精品久久一区二区三区| 欧美国产禁国产网站cc| 亚洲欧洲中文日韩久久av乱码| 樱花草国产18久久久久| 青青青伊人色综合久久| 国产一区二区三区美女| 91婷婷韩国欧美一区二区| 欧美三级视频在线观看| 精品蜜桃在线看| 久久99精品久久久| 国产成人免费视频网站| 色噜噜狠狠色综合中国| 欧美乱熟臀69xxxxxx| 久久免费精品国产久精品久久久久| 国产精品黄色在线观看| 性欧美疯狂xxxxbbbb| 国产成人av影院| 91成人在线精品| 日韩欧美一区中文| 亚洲欧洲一区二区三区| 日韩av高清在线观看| 高清不卡在线观看av| 欧美日韩国产精选| 国产欧美精品一区二区三区四区| 一区二区三区中文字幕精品精品 | 亚洲午夜影视影院在线观看| 久久爱www久久做| 色诱亚洲精品久久久久久| 欧美一区二区精品久久911| 国产精品久久久久aaaa樱花 | 午夜视频在线观看一区| 粉嫩欧美一区二区三区高清影视| 欧美日韩精品一区二区天天拍小说 | 国产精品第一页第二页第三页| 午夜一区二区三区视频| 成人app软件下载大全免费| 制服丝袜国产精品| 亚洲品质自拍视频| 大桥未久av一区二区三区中文| 欧美日韩综合一区| 亚洲免费伊人电影| 国产老妇另类xxxxx| 欧美丝袜自拍制服另类| 亚洲欧美在线观看| 51久久夜色精品国产麻豆| 日韩1区2区日韩1区2区| 亚洲成人av一区二区三区| 日韩av网站免费在线| 色综合久久中文字幕| 国产精品色眯眯| 久久精品国产精品亚洲红杏 | 4438x亚洲最大成人网| 国产亚洲精品精华液| 日韩成人一区二区| 欧美中文字幕不卡| 亚洲精品久久7777| 91视频免费看| 国产精品美女久久久久aⅴ国产馆 国产精品美女久久久久av爽李琼 国产精品美女久久久久高潮 | 制服视频三区第一页精品| 亚洲免费伊人电影| 一本大道久久a久久精品综合| 国产精品三级av在线播放| 国产河南妇女毛片精品久久久 | 亚洲国产精品99久久久久久久久| 国产呦萝稀缺另类资源| 日韩欧美一区二区久久婷婷| 亚洲香肠在线观看| 欧美性生活久久| 一级中文字幕一区二区| 色婷婷国产精品综合在线观看| 亚洲色图欧洲色图婷婷| 91啪亚洲精品| 一二三区精品视频| 欧美在线综合视频| 亚洲大片一区二区三区| 欧美久久久久久久久| 无吗不卡中文字幕| 69久久99精品久久久久婷婷| 日韩福利电影在线观看| 欧美tk—视频vk| 国产丶欧美丶日本不卡视频| 亚洲国产精品成人久久综合一区| 波多野结衣中文一区| 亚洲欧美日韩国产综合在线| 色婷婷国产精品| 污片在线观看一区二区| 精品噜噜噜噜久久久久久久久试看 | 久久久国产一区二区三区四区小说 | 色诱视频网站一区| 亚洲bt欧美bt精品777| 日韩午夜电影在线观看| 国产经典欧美精品| 亚洲欧美福利一区二区| 精品1区2区3区| 韩国精品久久久| 国产精品久久久久久久久免费桃花 | 国产精品护士白丝一区av| 欧美专区亚洲专区| 麻豆免费看一区二区三区| 久久久99精品久久| 91女神在线视频| 蜜芽一区二区三区| 国产精品污www在线观看| 欧美日韩一区不卡| 国产精品自拍在线| 亚洲香蕉伊在人在线观| 欧美精品一区视频|