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

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

?? serialport.cpp

?? 能夠對串口進行讀寫
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
				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("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
							&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 != strlen((char*)port->m_szWriteBuffer))
	{
		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,char* RXbuff,DWORD ByteRead)
{
	BOOL  bRead = TRUE; 
	BOOL  bResult = TRUE;
	DWORD dwError = 0;
	//DWORD BytesRead = 0;
	//unsigned char RXBuff;
	char* buff;

	buff=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 
							   buff,				// RX Buffer Pointer
							   70,					// Read one byte
							   &ByteRead,			// 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;
							ByteRead=0;
							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
										  &ByteRead,		// 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)(* buff), (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);

	// 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;
}


//--------------------------------------------------------
//dataprocess connect with the database
void CSerialPort::DataProcess(char* RXbuff,DWORD ByteRead)
{
	int i; 
	char*  str=RXbuff;
	char a1[2];
	char a2[3];
	CData* m_pSet;

	switch (ByteRead)
	{
	case(60):
		{
			if(!m_pSet->IsBOF())
			{
				m_pSet->MoveLast();
				m_pSet->AddNew();
				for(i=0;i<2;i++)
				{
					a1[i]=(*str);
					str++;
				}
				m_pSet->m_Au_ID=atol(a1);
				for(i=0;i<3;i++)
				{
					a2[i]=(*str);
					str++;
				}
				m_pSet->m_Author=a2;
				m_pSet->Update();
				if(!m_pSet->Update())
					assert("cannot write to the database");


				//this is the normal data process
		};
	case(50):
		{
			//this is the quanlity data process
		}
	default:
		{
			ASSERT("THE BYTE'S NUMBER IS NOT WRIGHT");
			//something wrong with the data process
		}
	}
	}
}



?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久夜色精品国产噜噜av| 欧美精品第一页| 韩国午夜理伦三级不卡影院| 亚洲第一激情av| 亚洲.国产.中文慕字在线| 亚洲一区二区高清| 亚洲二区视频在线| 天天av天天翘天天综合网| 亚洲bdsm女犯bdsm网站| 奇米影视一区二区三区| 经典一区二区三区| 成人精品gif动图一区| 99riav一区二区三区| caoporn国产精品| 日本韩国视频一区二区| 欧美视频在线不卡| 日韩一区二区三免费高清| 精品国产一区二区三区不卡 | 9人人澡人人爽人人精品| 91免费在线视频观看| 精品视频1区2区| 日韩女优制服丝袜电影| 日本一区二区三级电影在线观看 | 欧美电视剧在线看免费| 精品国产乱码久久久久久老虎| 久久综合色鬼综合色| 国产精品不卡一区| 首页国产欧美日韩丝袜| 国产精品一二三四| 91黄视频在线观看| 精品国免费一区二区三区| 亚洲欧洲国产日韩| 亚洲成a人v欧美综合天堂下载| 久久国产三级精品| 91在线国产观看| 欧美一级在线视频| 成人免费在线视频观看| 麻豆精品一区二区av白丝在线| 国产98色在线|日韩| 欧美喷水一区二区| 国产精品无人区| 蜜臀av一级做a爰片久久| www.在线欧美| 精品国一区二区三区| 亚洲综合清纯丝袜自拍| 成人免费福利片| 日韩一区二区三区四区| 亚洲最大色网站| 成人一区二区三区视频在线观看 | 在线精品视频免费播放| 国产日韩在线不卡| 日本三级韩国三级欧美三级| 不卡的av中国片| 精品欧美久久久| 亚洲成av人片一区二区三区 | 色天使色偷偷av一区二区| 2020国产精品久久精品美国| 日韩精品一二三区| 色视频欧美一区二区三区| 国产精品免费av| 大白屁股一区二区视频| 精品对白一区国产伦| 奇米在线7777在线精品| 欧美日韩激情一区二区| 一区二区三区在线不卡| 99精品国产视频| 国产精品二区一区二区aⅴ污介绍| 国产麻豆精品久久一二三| 日韩欧美二区三区| 爽爽淫人综合网网站| 欧美日韩大陆在线| 亚洲国产色一区| 欧美日韩精品一区二区三区蜜桃 | www激情久久| 免费看日韩a级影片| 在线成人小视频| 日韩成人免费电影| 337p亚洲精品色噜噜| 天堂成人免费av电影一区| 4hu四虎永久在线影院成人| 日韩国产一二三区| 欧美电视剧在线观看完整版| 极品瑜伽女神91| 国产午夜精品福利| fc2成人免费人成在线观看播放 | 日韩高清不卡一区二区| 91麻豆精品国产综合久久久久久| 婷婷六月综合网| 日韩欧美色电影| 国产激情一区二区三区| 中文字幕亚洲区| 在线一区二区视频| 欧美a级一区二区| 国产午夜精品久久久久久免费视| 成人av午夜影院| 一区二区三区欧美亚洲| 欧美一级生活片| 国产寡妇亲子伦一区二区| 亚洲欧美乱综合| 91精品国产色综合久久ai换脸 | 国产精品久久久久久久久晋中| 成人小视频在线观看| 夜夜精品浪潮av一区二区三区| 91精品国产综合久久精品| 成人综合婷婷国产精品久久蜜臀| 亚洲精品高清在线观看| 欧美一级高清大全免费观看| 福利电影一区二区| 亚洲最新视频在线观看| 久久综合九色综合97婷婷女人| 成人福利电影精品一区二区在线观看| 亚洲一区二区三区激情| 久久蜜桃香蕉精品一区二区三区| 91性感美女视频| 激情综合色播五月| 亚洲精品高清在线观看| 久久久久国产成人精品亚洲午夜| 欧美综合色免费| 国产69精品久久777的优势| 亚洲第一综合色| 中文字幕在线观看一区| 精品免费日韩av| 欧美日韩一区二区欧美激情| www.亚洲国产| 精品制服美女丁香| 亚洲福利一二三区| 一区在线观看视频| 久久午夜免费电影| 7777女厕盗摄久久久| 色妞www精品视频| 国产成人精品影视| 韩国视频一区二区| 人人精品人人爱| 午夜欧美2019年伦理| 亚洲私人黄色宅男| 久久蜜桃一区二区| 精品福利一二区| 日韩欧美不卡一区| 91精品国产欧美一区二区| 欧美日韩亚洲国产综合| 色综合久久中文综合久久97| av在线播放成人| 99久久综合精品| 丁香一区二区三区| 从欧美一区二区三区| 成人自拍视频在线观看| 国产成人在线网站| 国产成人无遮挡在线视频| 国精品**一区二区三区在线蜜桃| 日韩国产欧美在线视频| 日韩精品欧美精品| 免费成人你懂的| 久久国产日韩欧美精品| 国产真实乱偷精品视频免| 国产毛片精品视频| 成人天堂资源www在线| 高清国产一区二区| 91污片在线观看| 91久久一区二区| 777欧美精品| 精品久久久久久综合日本欧美 | 91视视频在线观看入口直接观看www | 国产iv一区二区三区| 丁香婷婷综合网| www.成人在线| 在线免费观看日本一区| 欧美理论电影在线| 欧美日韩成人在线一区| 欧美大度的电影原声| 国产欧美日韩在线视频| 亚洲视频网在线直播| 亚洲综合图片区| 麻豆成人免费电影| 国产91丝袜在线播放0| 91亚洲精品一区二区乱码| 欧美日韩1区2区| 久久老女人爱爱| 亚洲精品成人在线| 日韩va欧美va亚洲va久久| 国产成人在线影院| 欧美在线播放高清精品| 精品国产欧美一区二区| 国产精品久久免费看| 亚洲成人高清在线| 国产呦萝稀缺另类资源| 91丨porny丨国产| 日韩欧美一级二级三级久久久| 国产精品国产精品国产专区不片| 亚洲国产精品一区二区久久| 国产乱子轮精品视频| 欧洲精品在线观看| 久久综合九色综合97婷婷女人 | 日韩欧美视频一区| 中文字幕一区视频| 日韩av在线发布| 色香色香欲天天天影视综合网 | 国产69精品久久99不卡| 欧美欧美午夜aⅴ在线观看| 国产精品狼人久久影院观看方式| 日韩成人精品在线|