⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dk20dieselizedynamotordlg.cpp

📁 485通讯接口模块的编程应用
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		{
			strData1.SetAt(iFind , '+') ; 
			iFind =  strData1.FindOneOf(_T("-")) ; 
		}

		iFind =  strData1.FindOneOf(_T("+")) ; 
		//if (-1 == iFind)
			//iFind =  strData1.FindOneOf(_T("-")) ; 
		int iCount = 0 ; //有几个数据

		while (iFind != -1&&iCount<4) 
		{
			CString strResult ; 
			bool bZ = 1 ;  //是否正数
			iFind =  strData1.FindOneOf(_T("+")) ; 
			if (-1 == iFind)
			{
				iFind =  strData1.FindOneOf(_T("-")) ; 
				bZ = 0 ; 
			}
			
			strData1 = strData1.Right(strData1.GetLength()-1) ; 
			int iFind2 =  strData1.FindOneOf(_T("+")) ; 
			if (-1 == iFind2)
				iFind2 =  strData1.FindOneOf(_T("-")) ; 
			
			if (iFind2 != -1)
			{
				strResult = strData1.Mid(iFind, iFind2 - iFind) ; 
			}
			else 
			{
				strResult= strData1 ; 
				iFind2 = 0; 
				iFind = -1 ; 
			}
			
			strData1 = strData1.Right(strData1.GetLength() - iFind2)  ; 
			float fValue = atof(strResult)  ; 
			if (!bZ)
				fValue = -fValue ; 
			
			if (iCount<3)
			{
				moudle[0].vcorValue[iCount].iCurrentvalue = fValue ; 
			}
			else
				fTEMP1 = fValue ;
			iCount++ ; 
		}
		strData1 = _T("")  ; 
	}
	else
		TRACE(_T("不正常1\r\n "))  ; 
}

void Send7015s()
{
	strData2="";
	ZeroMemory(byteArray2,20)   ; 
	byteArray2[0] ='#'  ; 
	byteArray2[1] ='0'  ; 
	byteArray2[2] ='1'  ; 
	byteArray2[3] =0x0D   ; 
	m_pSerial2->WritePort((char*)byteArray2 ,4) ; 
	//等待N秒 接收数据
 	strData2 = _T("")  ; 
	m_pSerial2->WaitForResponse(strData2 , WAITDELAY)  ; 

	//strData2=">+60+70+50+9999.9+9999.9+9999.9";
	//char a2='\r';
	//strData2+=(CString)a2;
	if (!strData2.IsEmpty() && strData2.Left(1)==_T(">") && 
		strData2.Right(1)==_T("\r"))
	{
		strData2 = strData2.Right(strData2.GetLength()-1) ;
		int iFind =  strData2.FindOneOf(_T("\r")) ; 
		strData2 = strData2.Left(iFind	) ; 
		//排除-号
		iFind =  strData2.FindOneOf(_T("-")) ; 
		while (iFind != -1)
		{
			strData2.SetAt(iFind , '+') ; 
			iFind =  strData2.FindOneOf(_T("-")) ; 
		}
		iFind =  strData2.FindOneOf(_T("+")) ; 
		if (-1 == iFind)
			iFind =  strData2.FindOneOf(_T("-")) ; 
		int iCount = 0 ; //有几个数据

		while (iFind != -1&&iCount<4) 
		{
			CString strResult ; 
			bool bZ = 1 ;  //是否正数
			iFind =  strData2.FindOneOf(_T("+")) ; 
			if (-1 == iFind)
			{
				iFind =  strData2.FindOneOf(_T("-")) ; 
				bZ = 0 ; 
			}
			
			strData2 = strData2.Right(strData2.GetLength()-1) ; 
			int iFind2 =  strData2.FindOneOf(_T("+")) ; 
			if (-1 == iFind2)
				iFind2 =  strData2.FindOneOf(_T("-")) ; 
			
			if (iFind2 != -1)
			{
				strResult = strData2.Mid(iFind, iFind2 - iFind) ; 
			}
			else 
			{
				strResult= strData2 ; 
				iFind2 = 0; 
				iFind = -1 ; 
			}
			
			strData2 = strData2.Right(strData2.GetLength() - iFind2)  ; 
			float fValue = atof(strResult)  ; 
			if (!bZ)
				fValue = -fValue ; 
			
			if (iCount<3)
			{
				moudle[5].vcorValue[iCount].iCurrentvalue = fValue ; 
			}
			else
				fTEMP2 = fValue ;
			iCount++ ; 
		}
		strData2 = _T("")  ; 
	}
	else
		TRACE(_T("不正常2\r\n "))  ; 
}

void Send7015t()
{
	strData3="";
	ZeroMemory(byteArray3,20)   ; 
	byteArray3[0] ='#'  ; 
	byteArray3[1] ='0'  ; 
	byteArray3[2] ='1'  ; 
	byteArray3[3] =0x0D   ; 
	m_pSerial3->WritePort((char*)byteArray3 ,4) ; 
	//等待N秒 接收数据
 	strData3 = _T("")  ; 
	m_pSerial3->WaitForResponse(strData3 , WAITDELAY)  ; 

	//strData3=">+50+60+70+9999.9+9999.9+9999.9"+(CString)'\r';
	if (!strData3.IsEmpty() && strData3.Left(1)==_T(">") && 
		strData3.Right(1)==_T("\r"))
	{
		strData3 = strData3.Right(strData3.GetLength()-1) ;
		int iFind =  strData3.FindOneOf(_T("\r")) ; 
		strData3 = strData3.Left(iFind	) ; 
		//排除-号
		iFind =  strData3.FindOneOf(_T("-")) ; 
		while (iFind != -1)
		{
			strData3.SetAt(iFind , '+') ; 
			iFind =  strData3.FindOneOf(_T("-")) ; 
		}
		iFind =  strData3.FindOneOf(_T("+")) ; 
		if (-1 == iFind)
			iFind =  strData3.FindOneOf(_T("-")) ; 
		int iCount = 0 ; //有几个数据

		while (iFind != -1&&iCount<4) 
		{
			CString strResult ; 
			bool bZ = 1 ;  //是否正数
			iFind =  strData3.FindOneOf(_T("+")) ; 
			if (-1 == iFind)
			{
				iFind =  strData3.FindOneOf(_T("-")) ; 
				bZ = 0 ; 
			}
			
			strData3 = strData3.Right(strData3.GetLength()-1) ; 
			int iFind2 =  strData3.FindOneOf(_T("+")) ; 
			if (-1 == iFind2)
				iFind2 =  strData3.FindOneOf(_T("-")) ; 
			
			if (iFind2 != -1)
			{
				strResult = strData3.Mid(iFind, iFind2 - iFind) ; 
			}
			else 
			{
				strResult= strData3 ; 
				iFind2 = 0; 
				iFind = -1 ; 
			}
			
			strData3 = strData3.Right(strData3.GetLength() - iFind2)  ; 
			float fValue = atof(strResult)  ; 
			if (!bZ)
				fValue = -fValue ; 
			
			if (iCount<3)
			{
				moudle[10].vcorValue[iCount].iCurrentvalue = fValue ; 
			}
			else
				fTEMP3 = fValue ;
			iCount++ ; 
		}
		strData3 = _T("")  ; 
	}
	else
		TRACE(_T("不正常3\r\n "))  ; 
}


//7017机组1
void Send7017f()
{
	//7017-1
	strData1 = "";
	ZeroMemory(byteArray1,20)   ; 
	
	byteArray1[0] ='#'  ; 
	byteArray1[1] ='0'  ; 
	byteArray1[2] ='2'  ; 
	byteArray1[3] =0x0D   ; 


	m_pSerial1->WritePort((char*)byteArray1 ,4) ; 
	//等待N秒 接收数据


  	m_pSerial1->WaitForResponse(strData1 , WAITDELAY)  ; 

	//strData1=">+10+15+12+17+18+19+20+11"+(CString)'\r';
	
	if (!strData1.IsEmpty() && strData1.Left(1)==_T(">") && 
		strData1.Right(1)==_T("\r"))
	{
		strData1 = strData1.Right(strData1.GetLength()-1) ;
		int iFind =  strData1.FindOneOf(_T("\r")) ; 
		strData1 = strData1.Left(iFind	) ; 


		//排除-号
		iFind =  strData1.FindOneOf(_T("-")) ; 
 		while (iFind != -1)
		{
			strData1.SetAt(iFind , '+') ; 
			iFind =  strData1.FindOneOf(_T("-")) ; 
		}
		
		iFind =  strData1.FindOneOf(_T("+")) ; 
		if (-1 == iFind)
		iFind =  strData1.FindOneOf(_T("-")) ; 
		
		int iCount = 0 ; //有几个数据
		while (iFind != -1 && iCount < 8)
		{
			CString strResult ; 
			bool bZ = 1 ;  //是否正数
			iFind =  strData1.FindOneOf(_T("+")) ; 
			if (-1 == iFind)
			{
				iFind =  strData1.FindOneOf(_T("-")) ; 
				bZ = 0 ; 
			} 
			
			strData1 = strData1.Right(strData1.GetLength()-1) ; 
			int iFind2 =  strData1.FindOneOf(_T("+")) ; 
			if (-1 == iFind2)
				iFind2 =  strData1.FindOneOf(_T("-")) ; 
			
			if (iFind2 != -1)
			{
				strResult = strData1.Mid(iFind, iFind2 - iFind) ; 
			}
			else 
			{
				strResult= strData1 ; 
				iFind2 = 0; 
				iFind = -1 ; 
			}
			
			strData1 = strData1.Right(strData1.GetLength() - iFind2)  ; 
			float fValue = atof(strResult)  ;
			if (!bZ)
				fValue = -fValue ; 
			
			if (fValue <=20&&fValue>=4) 
			{
 				switch(iCount ) 
				{
				case 0://5公斤
				case 5:
				case 4:
				case 6:
				case 7:
					fValue = fValue-1  ; 
					break;
				case 1://2公斤
					fValue = fValue - 1  ; 
					break;
				case 2:
				case 3: //10公斤
					fValue = fValue - 1  ; 
					break; 
				}
			}
			else
			{
				fValue=0;
			}
					
 			moudle[2].vcorValue[iCount].iCurrentvalue = fValue ; 
			iCount++ ; 
		}
		strData1 = _T("")  ; 
	}
	else
		TRACE(_T("不正常4\r\n "))  ; 


	//7017-2
	strData1 = "";
	ZeroMemory(byteArray1,20)   ; 
	
	byteArray1[0] ='#'  ; 
	byteArray1[1] ='0'  ; 
	byteArray1[2] ='3'  ; 
	byteArray1[3] =0x0D   ; 


	m_pSerial1->WritePort((char*)byteArray1 ,4) ; 
	//等待N秒 接收数据


  	m_pSerial1->WaitForResponse(strData1 , WAITDELAY)  ; 

	//strData1=">+10+15+12+17+18+19+20+11"+(CString)'\r';
	
	if (!strData1.IsEmpty() && strData1.Left(1)==_T(">") && 
		strData1.Right(1)==_T("\r"))
	{
		strData1 = strData1.Right(strData1.GetLength()-1) ;
		int iFind =  strData1.FindOneOf(_T("\r")) ; 
		strData1 = strData1.Left(iFind	) ; 


		//排除-号
		iFind =  strData1.FindOneOf(_T("-")) ; 
 		while (iFind != -1)
		{
			strData1.SetAt(iFind , '+') ; 
			iFind =  strData1.FindOneOf(_T("-")) ; 
		}
		
		iFind =  strData1.FindOneOf(_T("+")) ; 
		if (-1 == iFind)
		iFind =  strData1.FindOneOf(_T("-")) ; 
		
		int iCount = 0 ; //有几个数据
		while (iFind != -1 && iCount<6)
		{
			CString strResult ; 
			bool bZ = 1 ;  //是否正数
			iFind =  strData1.FindOneOf(_T("+")) ; 
			if (-1 == iFind)
			{
				iFind =  strData1.FindOneOf(_T("-")) ; 
				bZ = 0 ; 
			} 
			
			strData1 = strData1.Right(strData1.GetLength()-1) ; 
			int iFind2 =  strData1.FindOneOf(_T("+")) ; 
			if (-1 == iFind2)
				iFind2 =  strData1.FindOneOf(_T("-")) ; 
			
			if (iFind2 != -1)
			{
				strResult = strData1.Mid(iFind, iFind2 - iFind) ; 
			}
			else 
			{
				strResult= strData1 ; 
				iFind2 = 0; 
				iFind = -1 ; 
			}
			
			strData1 = strData1.Right(strData1.GetLength() - iFind2)  ; 
			float fValue = atof(strResult)  ;
			if (!bZ)
				fValue = -fValue ; 
			
			if (fValue <=20&&fValue>=4) 
			{
 				switch(iCount ) 
				{
				case 0://5公斤
				case 5:
				case 4:
					fValue = fValue-1 ; 
					break;
				case 1://2公斤
					fValue = fValue-1 ; 
					break;
				case 2:
				case 3: //10公斤
					fValue = fValue-1 ; 
					break; 
				}
			}
			else
			{
				fValue=0;
			}
					
 			moudle[3].vcorValue[iCount].iCurrentvalue = fValue ; 
			iCount++ ; 
		}
		strData1 = _T("")  ; 
	}
	else
		TRACE(_T("不正常5\r\n "))  ;
}


//7017-机组2
void Send7017s()
{
	//7017-1
	strData2 = "";
	ZeroMemory(byteArray2,20)   ; 
	
	byteArray2[0] ='#'  ; 
	byteArray2[1] ='0'  ; 
	byteArray2[2] ='2'  ; 
	byteArray2[3] =0x0D   ; 
	

	m_pSerial2->WritePort((char*)byteArray2 ,4) ; 
	//等待N秒 接收数据


  	m_pSerial2->WaitForResponse(strData2 , WAITDELAY)  ; 

	//strData2=">+10+15+12+17+18+19+20+11"+(CString)'\r';
	
	if (!strData2.IsEmpty() && strData2.Left(1)==_T(">") && 
		strData2.Right(1)==_T("\r"))
	{
		strData2 = strData2.Right(strData2.GetLength()-1) ;
		int iFind =  strData2.FindOneOf(_T("\r")) ; 
		strData2 = strData2.Left(iFind	) ; 


		//排除-号
		iFind =  strData2.FindOneOf(_T("-")) ; 
 		while (iFind != -1)
		{
			strData2.SetAt(iFind , '+') ; 
			iFind =  strData2.FindOneOf(_T("-")) ; 
		}
		
		iFind =  strData2.FindOneOf(_T("+")) ; 
		if (-1 == iFind)
		iFind =  strData2.FindOneOf(_T("-")) ; 
		
		int iCount = 0 ; //有几个数据
		while (iFind != -1 && iCount <8)
		{
			CString strResult ; 
			bool bZ = 1 ;  //是否正数
			iFind =  strData2.FindOneOf(_T("+")) ; 
			if (-1 == iFind)
			{
				iFind =  strData2.FindOneOf(_T("-")) ; 
				bZ = 0 ; 
			} 
			
			strData2 = strData2.Right(strData2.GetLength()-1) ; 
			int iFind2 =  strData2.FindOneOf(_T("+")) ; 
			if (-1 == iFind2)
				iFind2 =  strData2.FindOneOf(_T("-")) ; 
			
			if (iFind2 != -1)
			{
				strResult = strData2.Mid(iFind, iFind2 - iFind) ; 
			}
			else 
			{
				strResult= strData2 ; 
				iFind2 = 0; 
				iFind = -1 ; 
			}
			
			strData2 = strData2.Right(strData2.GetLength() - iFind2)  ; 
			float fValue = atof(strResult)  ;
			if (!bZ)
				fValue = -fValue ; 
			

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -