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

📄 portsenddlg.cpp

📁 用VC++开发的基于AVR单片机ATmega16的24路舵机控制器的上位机源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
lowhexdata=ConvertHexChar(lstr);
if((hexdata==16)||(lowhexdata==16))
break;
else 
hexdata=hexdata*16+lowhexdata;
i++;
senddata[hexdatalen]=(char)hexdata;
hexdatalen++;
}
senddata.SetSize(hexdatalen);
return hexdatalen;

}

char CPortsendDlg::ConvertHexChar(char ch)
{
if((ch>='0')&&(ch<='9'))
return ch-0x30;
else if((ch>='A')&&(ch<='F'))
return ch-'A'+10;
else if((ch>='a')&&(ch<='f'))
return ch-'a'+10;
else return (-1);
}

void CPortsendDlg::OnButinput() //插入指令命令处理
{
	// TODO: Add your control notification handler code here
  CString str1,str2,str3,str4;
  int m_DJBS[24];
  str2="";str4="";
  UpdateData(TRUE); //读取编辑框内容
  m_DJBS[0]=m_DJBS1;  m_DJBS[1]=m_DJBS2;  m_DJBS[2]=m_DJBS3;  m_DJBS[3]=m_DJBS4;
  m_DJBS[4]=m_DJBS5;  m_DJBS[5]=m_DJBS6;  m_DJBS[6]=m_DJBS7;  m_DJBS[7]=m_DJBS8;
  m_DJBS[8]=m_DJBS9;  m_DJBS[9]=m_DJBS10; m_DJBS[10]=m_DJBS11;m_DJBS[11]=m_DJBS12;
  m_DJBS[12]=m_DJBS13;m_DJBS[13]=m_DJBS14;m_DJBS[14]=m_DJBS15;m_DJBS[15]=m_DJBS16;
  m_DJBS[16]=m_DJBS17;m_DJBS[17]=m_DJBS18;m_DJBS[18]=m_DJBS19;m_DJBS[19]=m_DJBS20;
  m_DJBS[20]=m_DJBS21;m_DJBS[21]=m_DJBS22;m_DJBS[22]=m_DJBS23;m_DJBS[23]=m_DJBS24;
  int j;
  for( j=23;j>=0;j--)
  {
	  str1.Format("%x",m_DJBS[j]);
	  if(m_DJBS[j]<16)
		  str1=	"0"+str1;
      str2=str1+str2;
	  str4=str3+str4;
  }
  j=m_LIST.GetCurSel();
  m_LIST.InsertString(j,str2);
  m_LIST.SetCurSel(j);
 // m_LIST.AddString(str2);
	
}

void CPortsendDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default

	//CScrollBar*pScrollBar.SetScroIIPos(100,true);
	//

 //
	
 if(pScrollBar==GetDlgItem(IDC_SCROLLDJ1))//第一个电机角度值
 {
    
     m_DJBS1=ScrollString1(nSBCode,nPos,pScrollBar, m_DJBS1);
	 if(outcount==1)
	    outcount++;
	 else
	 {
	   StringOutput(m_DJBS1,1);
	   outcount=1;
	 }
 }
 //222222222222222222222222222222222222
 if(pScrollBar==GetDlgItem(IDC_SCROLLDJ2))
 {
	 m_DJBS2=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS2);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS2,2);
      outcount=1;
	}
 }
 //22222222222222222222222222222222222222
 //33333333333333333333333333333333333333
 if(pScrollBar==GetDlgItem(IDC_SCROLLDJ3))
 {
	m_DJBS3=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS3);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS3,3);
      outcount=1;
	} 
 }
 //333333333333333333333333333333333
 //44444444444444444444444444444444444
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ4))
 {
	m_DJBS4=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS4);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS4,4);
      outcount=1;
	} 	
 }
//444444444444444444444444444444
//5555555555555555555555555555555
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ5))
 {
	m_DJBS5=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS5);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS5,5);
      outcount=1;
	} 
 }
//55555555555555555555555555555
//666666666666666666666666666
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ6))
 {
	m_DJBS6=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS6);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS6,6);
      outcount=1;
	} 
 }
//66666666666666666666666666666
//7777777777777777777777777777
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ7))
 {
	m_DJBS7=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS7);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS7,7);
      outcount=1;
	} 
 }
//777777777777777777777777777777777
//88888888888888888888888888888888
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ8))
 {
	m_DJBS8=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS8);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS8,8);
      outcount=1;
	} 
 }
//8888888888888888888888888888888
//999999999999999999999999999999999
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ9))
 {
	m_DJBS9=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS9);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS9,9);
      outcount=1;
	} 
 }
//99999999999999999999999999
//1010101010101010101010101010
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ10))
 {
	m_DJBS10=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS10);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS10,10);
      outcount=1;
	} 
 }
//1010101010101010101010101010101010
//1111111111111111111111111111111111
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ11))
 {
	m_DJBS11=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS11);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS11,11);
      outcount=1;
	} 
 }
//111111111111111111111111111111111111
//1212121212121212121212121212121212
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ12))
 {
	m_DJBS12=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS12);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS12,12);
      outcount=1;
	} 
 }
//1212121212121212
//1313131313
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ13))
 {
	m_DJBS13=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS13);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS13,13);
      outcount=1;
	} 
 }
//131313131313
//14141414141414
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ14))
 {
	m_DJBS14=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS14);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS14,14);
      outcount=1;
	} 
 }
//1414141414141414
//15 15
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ15))
 {
	m_DJBS15=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS15);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS15,15);
      outcount=1;
	} 
 }
//15
//16
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ16))
 {
	m_DJBS16=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS16);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS16,16);
      outcount=1;
	} 
 }
//16
//17
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ17))
 {
	m_DJBS17=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS17);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS17,17);
      outcount=1;
	} 
 }
//17
//18
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ18))
 {
	m_DJBS18=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS18);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS18,18);
      outcount=1;
	} 
 }
//18
//19
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ19))
 {
	m_DJBS19=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS19);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS19,19);
      outcount=1;
	} 
 }
//19
//20
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ20))
 {
	m_DJBS20=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS20);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS20,20);
      outcount=1;
	} 
 }
//20
//21
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ21))
 {
	m_DJBS21=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS21);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS21,21);
      outcount=1;
	} 
 }
//21
//22
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ22))
 {
	m_DJBS22=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS22);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS22,22);
      outcount=1;
	} 
 }
//22
//23
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ23))
 {
	m_DJBS23=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS23);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS23,23);
      outcount=1;
	} 
 }
//23
//24
if(pScrollBar==GetDlgItem(IDC_SCROLLDJ24))
 {
	m_DJBS24=ScrollString1(nSBCode,nPos,pScrollBar,m_DJBS24);
     if(outcount==1)
       outcount++;
    else
	{
      StringOutput(m_DJBS24,24);
      outcount=1;
	} 
 }

  CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
 
}




int CPortsendDlg::ScrollString1(UINT nSBCode, UINT nPos, CScrollBar *pg1, int m_dj)
{
  int a;
  UINT b=0 ;
  CString str;
   switch(nSBCode)      //滚动条的通知消息码
   {
   case SB_THUMBTRACK: //滚动框被拖动
    pg1->SetScrollPos(nPos);//m_SCROLLDJ1.SetScrollPos(nPos);pScrollBar->SetScrollPos(nPos);
    a=nPos;
    m_dj=a;
    break;
   case SB_LINERIGHT:   //向右滚动一行(列)
    a=pg1->GetScrollPos()+1;//a=m_SCROLLDJ1.GetScrollPos()+1;
    pg1->SetScrollPos(a);//m_SCROLLDJ1.SetScrollPos(a);
    if(a>180)
       a=180;
    m_dj=a;
    break;
 
   case SB_LINELEFT:  //向左滚动一行(列).   
    a=pg1->GetScrollPos()-1;//a=m_SCROLLDJ1.GetScrollPos()-1;
    pg1->SetScrollPos(a);//m_SCROLLDJ1.SetScrollPos(a);
    if(a<=0)
        a=0;
    m_dj=a;
    break;
   case SB_PAGERIGHT : //向右滚动一页.
    a=pg1->GetScrollPos()+10;
    pg1->SetScrollPos(a);
    if(a>180)
        a=180;
    m_dj=a;
    
    break;
 
   case SB_PAGELEFT: //向左滚动一页 
    a=pg1->GetScrollPos()-10;
    pg1->SetScrollPos(a);
    if(a<=0)
        a=0;
    m_dj=a;
    break;
   }
   return m_dj;
}


void CPortsendDlg::StringOutput(UINT m_outdate, UINT m_djh)
{
	CString str;
     m_strTXData.Format("%x",m_outdate);
    if(m_outdate<16)
  	  m_strTXData="0"+m_strTXData;
	m_djh=m_djh-1;
	str.Format("%x",m_djh);
	if(m_djh<16)
		str="0"+str;
	str="c101"+str+m_strTXData+"d1";
    UpdateData(false);
    CByteArray hexdata;
    int len=String2Hex(str,hexdata); //此处返回的len可以用于计算发送了多少个十六进制数
    m_ctrlComm.SetOutput(COleVariant(hexdata)); //发送十六进制数据

}

void CPortsendDlg::OnButtdelall() 
{
	// TODO: Add your control notification handler code here
		m_LIST.ResetContent();
}

void CPortsendDlg::OnButtdel() 
{
	// TODO: Add your control notification handler code here
  int J=m_LIST.GetCurSel();
  m_LIST.DeleteString(J);
	
}

void CPortsendDlg::OnButtsav() 
{
	// TODO: Add your control notification handler code here
	 CFileDialog dlg(FALSE, "SQL", "*.txt",OFN_HIDEREADONLY 
                     | OFN_OVERWRITEPROMPT,"Text Files(*.txt)|*.txt|SQL Files(*.sql)|*.sql|All Files(*.*)|*.*||"); 
  if ( dlg.DoModal()!=IDOK ) return;
//获取文件的绝对路径
  CString sFileName=dlg.GetPathName();
  CStdioFile out;
//打开文件
  out.Open(sFileName, CFile::modeCreate | CFile::modeWrite);

⌨️ 快捷键说明

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