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

📄 callerview.cpp

📁 串口的监控程序,提供了固定命令模式和
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		return ch-'A'+10;
	}
	else if((ch>='a')&&(ch<='f'))
	{
		return ch-'a'+10;
	}
	else 
	{
		return (-1);
	}

}


//
// 
//
int CCallerView::String2Hex(CString str, char senddata[24])//CByteArray &senddata)
{

	int hexdata,lowhexdata;
	int hexdatalen=0;
	int len=str.GetLength();
	char data[24];
	memset(data,0, sizeof(data));

	for(int i=0;i<len;)
	{
		char lstr,hstr=str[i];
		if(hstr==' ')
		{
			i++;
			continue;
		}
		i++;
		if(i>=len)
		{
			break;
		}

		lstr=str[i];
		hexdata=Char2Hex(hstr);
		lowhexdata=Char2Hex(lstr);

		if((hexdata==16)||(lowhexdata==16))
		{
			break;
		}
		else 
		{
			hexdata=hexdata*16+lowhexdata;
		}

		i++;
		data[hexdatalen]=(char)hexdata;
		hexdatalen++;
	}

	memcpy( senddata, data ,sizeof(data) );
	memset( data,0,sizeof(data));

	return hexdatalen;
}

//
// 
//
//##ModelId=3FFC8F3A02CE
void CCallerView::OnConfigClear() 
{
	// TODO: Add your command handler code here
	CRichEditCtrl &edit = GetRichEditCtrl();

	LONG temp = GetWindowTextLength();
//	GetLineFromChar( temp  );

	int a = edit.GetLineCount();
	edit.SetSel( 0,-1 );
	edit.Clear();
	


}


#define MAXBUFF 512

//
// 
//
//##ModelId=3FFC8F3A02C1
void CCallerView::OnFunc1Func1() 
{
	// TODO: Add your command handler code here
	CString str;

	CString strSend;
//	strSend.Format("This is Func1.func2");

	if ( m_CmdLine[0][0].m_bCmdLineEn )
	{
		strSend = m_CmdLine[0][0].m_strCmdLine + "\r\n"; 
	}
	else
	{
		strSend.Format("AT+CMGL\r");
	}

	str.Format( "f11 resquest:");
	SendFunctionCommand( strSend, str);
}

//
// 
//
//##ModelId=3FFC8F3A02D0
void CCallerView::OnFunc1Func2() 
{
	CString str;
	// TODO: Add your command handler code here
	char m_strTXData[] = "aBCde12345";
	CString strSend;
//	strSend.Format("This is Func1.func2");

	if ( m_CmdLine[0][1].m_bCmdLineEn )
	{
		strSend = m_CmdLine[0][1].m_strCmdLine + "\r\n"; 
	}
	else
	{
		strSend.Format("This is Func1.func3");
	}

	str.Format( "f12 resquest:");
	SendFunctionCommand( strSend, str);
}

//
// 
//
//##ModelId=3FFC8F3A02DE
void CCallerView::OnFunc1Func3() 
{
	CString str;
	CString strSend;
	// TODO: Add your command handler code here
	if ( m_CmdLine[0][2].m_bCmdLineEn )
	{
		strSend = m_CmdLine[0][2].m_strCmdLine + "\r\n"; 
	}
	else
	{
		strSend.Format("This is Func1.func3");
	}

	str.Format( "f13 resquest:");
	SendFunctionCommand( strSend, str);
}

//
// 
//
//##ModelId=3FFC8F3A02E0
void CCallerView::OnFunc2Func1() 
{
	CString str;
	CString strSend;
	// TODO: Add your command handler code here

	if ( m_CmdLine[1][0].m_bCmdLineEn )
	{
		strSend = m_CmdLine[1][0].m_strCmdLine + "\r\n"; 
	}
	else
	{
		strSend.Format("This is Func2.func1");
	}

	str.Format( "f21 resquest:");
	SendFunctionCommand( strSend, str);	
}

//
//
//
//##ModelId=3FFC8F3A02EE
void CCallerView::OnFunc2Func2() 
{
	CString str;
	CString strSend;
	// TODO: Add your command handler code here
	if ( m_CmdLine[1][1].m_bCmdLineEn )
	{
		strSend = m_CmdLine[1][1].m_strCmdLine + "\r\n"; 
	}
	else
	{
		strSend.Format("This is Func2.func2");
	}

	str.Format( "f22 resquest:");
	SendFunctionCommand( strSend, str);
}

//
//
//
//##ModelId=3FFC8F3A02F0
void CCallerView::OnFunc2Func3() 
{
	CString str;
	CString strSend;
	// TODO: Add your command handler code here
	if ( m_CmdLine[1][2].m_bCmdLineEn )
	{
		strSend = m_CmdLine[1][2].m_strCmdLine + "\r\n"; 
	}
	else
	{
		strSend.Format("This is Func2.func3");
	}

	str.Format( "f23 resquest:");
	SendFunctionCommand( strSend, str);
}

//
//
//
//##ModelId=3FFC8F3A02FD
void CCallerView::OnFunc2Func4() 
{
	CString str;
	CString strSend;
	// TODO: Add your command handler code here

	if ( m_CmdLine[1][3].m_bCmdLineEn )
	{
		strSend = m_CmdLine[1][3].m_strCmdLine + "\r\n"; 
	}
	else
	{
		strSend.Format("This is Func2.func4");
	}

	str.Format( "f24 resquest:");
	SendFunctionCommand( strSend, str);
}

//
//
//
//##ModelId=3FFC8F3A02FF
void CCallerView::OnFunc2Func5() 
{
	CString str;
	CString strSend;
	// TODO: Add your command handler code here
	if ( m_CmdLine[1][4].m_bCmdLineEn )
	{
		strSend = m_CmdLine[1][4].m_strCmdLine + "\r\n"; 
	}
	else
	{
		strSend.Format("This is Func2.func5");
	}

	str.Format( "f25 resquest:");
	SendFunctionCommand( strSend, str);	
}

//
//
//

//##ModelId=3FFC8F3A0251
void CCallerView::SendFunctionCommand(CString strComm,CString strCommId)
{
	if(m_bDataMode)
	{

		BYTE btData[128];
        RichCtrl.StrToHex( strComm, btData );

		m_ComPort.WriteToPort((char*)btData);			    
//		memset(hexdata, 0, sizeof(hexdata));

		strCommId += "( Hex )";
		PutMessage( strCommId );
	}
	else
	{
		char* p = strComm.GetBuffer(128);
		m_ComPort.WriteToPort(p);//m_strTXData); 

		strCommId += "( ASCII )";
		PutMessage( strCommId );
	}	

}


//##ModelId=3FFC8F3A0271
void CCallerView::PutMessage(CString strMessage)
{
    int nTextLength;
	CString str;
	CCallerDoc  *pDoc = GetDocument();
//    CEdit &e = GetEditCtrl(); 
	CRichEditCtrl& e=GetRichEditCtrl();

	// get the length of all text
	nTextLength = e.GetWindowTextLength();

	// set cursor to last position

	e.SetSel( nTextLength , nTextLength);

    e.ReplaceSel(  "\r\n");
	e.ReplaceSel(  "\r\n");

	e.ReplaceSel( strMessage );

	e.ReplaceSel(  "\r\n");
	
}

//##ModelId=3FFC8F3A030F
void CCallerView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default

        int a = GetLineIndex();
	int b = GetCursorCol();
	CRichEditView::OnKeyDown(nChar, nRepCnt, nFlags);
	LN_COL_MSG(MAKELPARAM(GetLineIndex(),GetCursorCol()))
}

//##ModelId=3FFC8F3A031F
void CCallerView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
    int a = GetLineIndex();
	int b = GetCursorCol();
//	CMainFrame::DrawLnCol( nLineIndex, ne-ns );
	CRichEditView::OnLButtonDown(nFlags, point);
	LN_COL_MSG(MAKELPARAM(GetLineIndex(),GetCursorCol()))
}


//##ModelId=3FFC8F3A0262
long CCallerView::GetLineStart(int nLineIndex)
{
	CRichEditCtrl &pe = GetRichEditCtrl();

	long l = pe.GetLineCount();
	nLineIndex = pe.LineFromChar(pe.LineIndex(-1));

	return pe.LineIndex(nLineIndex);
}

//##ModelId=3FFC8F3A0264
int CCallerView::GetCursorCol()
{
	CRichEditCtrl &pe = GetRichEditCtrl();

	long ns=0,ne=0;
	pe.GetSel(ns,ne);
	if(ns!=ne)
	{
		ns=pe.LineFromChar(ne);
		ns=GetLineStart(ns);
		return ne-ns;
	}
	return ne-pe.LineIndex(-1);
}


//##ModelId=3FFC8F3A0261
int CCallerView::GetLineIndex()
{
	CRichEditCtrl &pe = GetRichEditCtrl();
	long l = pe.GetLineCount();
	int nLineIndex=pe.LineFromChar(pe.LineIndex(-1));
    
	return nLineIndex;
}





//##ModelId=3FFC8F3A0242
void CCallerView::CheckCmdFormat()
{
		BOOL bError;

			for ( int i = 0; i < 2 ; i ++ )
			{
				for ( int j = 0; j < 5; j ++ )
				{
					if ( m_CmdLine[i][j].m_bCmdLineEn )
					{
						bError = RichCtrl.IsHexFormat( m_CmdLine[i][j].m_strCmdLine);
					
						if( !bError )
						{
							CString str;
							str.Format("命令行%d-%d格式错误!",i + 1,j +1 );
							MessageBox( str, "错误", MB_OK );
						}
					}
				}
			}

}

⌨️ 快捷键说明

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