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

📄 ultrasonicview.cpp

📁 接收来自下位机的数据,然后进行数据处理和通讯
💻 CPP
📖 第 1 页 / 共 5 页
字号:
void CUltrasonicView::OnViewwaveCh6() 
{
	// TODO: Add your command handler code here
		WaveDlg* pdlg=new WaveDlg;
	pdlg->Create(IDD_DIALOG_WAVE,this);
	pdlg->ShowWindow(SW_SHOW);
    pdlg->SetWindowText("通道六波形");
    pdlg->DisplayWave(5);
}

void CUltrasonicView::OnViewwaveCh7() 
{
	// TODO: Add your command handler code here
		WaveDlg* pdlg=new WaveDlg;
	pdlg->Create(IDD_DIALOG_WAVE,this);
	pdlg->ShowWindow(SW_SHOW);
    pdlg->SetWindowText("通道七波形");
    pdlg->DisplayWave(6);
}

void CUltrasonicView::OnViewwaveCh8() 
{
	// TODO: Add your command handler code here
		WaveDlg* pdlg=new WaveDlg;
	pdlg->Create(IDD_DIALOG_WAVE,this);
	pdlg->ShowWindow(SW_SHOW);
    pdlg->SetWindowText("通道八波形");
    pdlg->DisplayWave(7);
}

void CUltrasonicView::OnViewwaveCh9() 
{
	
		WaveDlg* pdlg=new WaveDlg;
	pdlg->Create(IDD_DIALOG_WAVE,this);
	pdlg->ShowWindow(SW_SHOW);
    pdlg->SetWindowText("速度");
    pdlg->DisplayWave(8);
}

void CUltrasonicView::OnViewwaveAll() 
{
	// TODO: Add your command handler code here
	AllWaveDlg* pdlg=new AllWaveDlg;
	pdlg->Create(IDD_DIALOG_AllWave,this);
	pdlg->ShowWindow(SW_SHOW);
    pdlg->SetWindowText("多通道波形");
   
}

void CUltrasonicView::Onzoom() 
{
	// TODO: Add your control notification handler code here
		zoom=0;
		ratio=1;//比例为1
		xcenter=6000;
		m_Scroll.SetScrollPos(6000);
//		m_Scroll1.SetScrollPos(100);
		CRect rc(45,260,845,566);
		InvalidateRect(rc);
	

}

void CUltrasonicView::Onzoomup() 
{
	// TODO: Add your control notification handler code here
  	zoom=1;//放大

}

void CUltrasonicView::Onzoomdown() 
{
	// TODO: Add your control notification handler code here
	zoom=2;//缩小
}

void CUltrasonicView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(zoom!=0)
	{		
	     xcenter=oldcenter+int((point.x-445)*(12000/ratio)/800);
		if(zoom==1) 
		{	
			if(ratio<128) 
				ratio=ratio*2;
			//else ratio=1.0;
		}
		if(zoom==2 ) 
		{	
			if(ratio>1.0) 
				ratio=ratio/2;
			//else ratio=0.4;
		}
		m_1=ratio;
		if(xcenter<=6000/ratio)  xcenter=int(6000/ratio);
		if((xcenter+6000/ratio)>=12000)  xcenter=int(12000-6000/ratio); 
		oldcenter=xcenter;
		UpdateData(FALSE);
		m_Scroll.SetScrollPos(xcenter-int(6000/ratio));//
       CRect rc(45,260,845,536);
       InvalidateRect(rc);
	}
	CFormView::OnLButtonDown(nFlags, point);
}

void CUltrasonicView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	int iPos=m_Scroll.GetScrollPos();
	switch (nSBCode)
	{
        case SB_ENDSCROLL:
     			break;
        case SB_LINELEFT:
			 iPos-=1;
			    break; 
         case SB_LINERIGHT:
			 iPos+=1;
			    break; 
        case SB_THUMBTRACK:
			 iPos=nPos;
			 break;
		default: 
		/*	m_Scroll.SetScrollPos(nPos);
			xcenter=nPos*6;
	        if(xcenter<=6000/ratio)  xcenter=int(6000/ratio);
            if((xcenter+6000/ratio)>=12000)  xcenter=int(12000-6000/ratio); 
			oldcenter=xcenter;
			UpdateData(FALSE);
		    CRect rc(45,260,845,516);
            InvalidateRect(rc);  */
		
			break;
	}
	if(iPos<0) iPos=0;
    if(iPos>12000) iPos=12000;
	m_Scroll.SetScrollPos(iPos);
	        xcenter=iPos*6;//
	        if(xcenter<=6000/ratio)  xcenter=int(6000/ratio);
            if((xcenter+6000/ratio)>=12000)  xcenter=int(12000-6000/ratio); 
			oldcenter=xcenter;
			UpdateData(FALSE);
		    CRect rc(45,260,845,516);
            InvalidateRect(rc);
//	nPos=iPos;
	CFormView::OnHScroll(nSBCode, nPos, pScrollBar);
}

void CUltrasonicView::Onshowdata() 
{
	// TODO: Add your control notification handler code here
   if(showdata==1)
	{   
		m_showdata.SetWindowText("显示数据");
		showdata=0;
	}
	else
	{	m_showdata.SetWindowText("不显示数据");
		showdata=1;
	}


}

void CUltrasonicView::Onshowwave() 
{
	// TODO: Add your control notification handler code here
	if(showwave==1)
	{   
		m_showwave.SetWindowText("显示波形");
		showwave=0;
	}
	else
	{	m_showwave.SetWindowText("不显示波形");
		showwave=1;
	}
	CRect rc(45,260,845,516);
    InvalidateRect(rc);
}

void CUltrasonicView::Onautomaticadjust() 
{
	WaveDlg* pdlg=new WaveDlg;
	pdlg->Create(IDD_DIALOG_WAVE,this);
 	pdlg->ShowWindow(SW_SHOW);
    pdlg->SetWindowText("波形分析");
}



void CUltrasonicView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	
		int iPos=m_Scroll1.GetScrollPos();
	switch (nSBCode)
	{
        case SB_ENDSCROLL:
     			break;
        case SB_LINEUP:
			 iPos-=1;
			    break; 
         case SB_LINEDOWN:
			 iPos+=1;
			    break; 
		 case SB_THUMBTRACK:
			 iPos=nPos;
			 break;
		default: 						
			 break;
	}
	if(iPos<1) iPos=1;
	if(iPos>32) iPos=32;
	m_Scroll1.SetScrollPos(iPos);
    
		if (iPos!=0)
            chus=iPos;
			UpdateData(FALSE);
		    CRect rc(45,260,845,516);
            InvalidateRect(rc);
 
	CFormView::OnVScroll(nSBCode, nPos, pScrollBar);

}

int count=0;
void CUltrasonicView::OnRadio1() 
{
	int i;
	count++;
   i=((CButton*)GetDlgItem(IDC_RADIO1))->GetCheck();
   tz=count % 2;
   if(count % 2==0) 
   {((CButton*)GetDlgItem(IDC_RADIO1))->SetCheck(1-i);
    SetDlgItemText(IDC_RADIO1,"不调零");
 //   tz=1-i;
   }
   else 
    SetDlgItemText(IDC_RADIO1,"调零");
   CRect rc(45,260,845,516);
   InvalidateRect(rc);
   UpdateData(FALSE);
}

void CUltrasonicView::OnTecPlotFormat() 
{

	int i,j,l,k,m;	
	int cha;
	char g[1];
	char ch3;
	CString hdata[8][12288];
    CFileException e;
	for(i=0;i<8;i++) 
		for(j=0;j<12288;j++)  
			hdata[i][j]="0.0";
/////////////打开历史数据文件////////////////////
	LPCTSTR lpszFilter="文本文件(*.txt_tec)|*.txt_tec|任何文件|*.*||";
    CFileDialog dlg(TRUE,lpszFilter,NULL, OFN_ALLOWMULTISELECT| OFN_OVERWRITEPROMPT,lpszFilter,NULL);//OFN_HIDEREADONLY
	CString a,dao,ban,strtemp,pos1;
	CStringArray filename;
	POSITION pos;
    fstream file1;
	CFile file0;
	char fdat[7];
    
	if(dlg.DoModal() == IDOK)
	{	
		pos=dlg.GetStartPosition( );//a = dlg.GetPathName() ;
	}
   while(pos!=NULL)
   { pos1=dlg.GetNextPathName(pos);
	filename.Add(pos1);
   }
    m=filename.GetSize();

	for(k=0;k<m;k++)
	{	
         a = filename[k];
		 dao=a.GetAt(a.Find("道")+2);
         cha=atoi(dao)-1;
		 
        file1.open(a,ios::in);
	    l=0;
//		le=file1.GetLength();
		 while(l<=12288)
		{ 			                    	
		//	file1.
			
			file1.get((char*)fdat,7,'\n');//line
			file1.read(&ch3,1);
			file1.get((char*)fdat,7,'\n');
			file1.read(&ch3,1);
            hdata[cha][l]=fdat;
			l++; 
		}        
        file1.close();	
	}
    itoa(m,g,10);
	if(a.GetLength()>16)
    a=a.Left(a.GetLength()-14)+g+"个通道.txt_tec";
	else
    a=strf+"合成"+g+"个通道.txt_tec";

	if( !file0.Open(a, CFile::modeCreate|CFile::modeWrite, &e ) )//|CFile::typeText
   {
      #ifdef _DEBUG
      afxDump << "File could not be opened " << e.m_cause << "\n";
      #endif
   }

	for(j=0;j<12288;j++)
	{
		strtemp.Format("%5d ",j); //将字符以十六进制方式送入临时变量strtemp存放,注意这里加入一个空隔
        const char* chi=(const char*)strtemp;
		file0.Write(chi,5);
        file0.Write(",",1);
		for(i=0;i<7;i++)  
		{file0.Write(hdata[i][j],6);file0.Write(",",1);}
	    file0.Write(hdata[7][j],6);
        file0.Write("\r\n",2);
	}
    file0.Close();

 


  
}

void CUltrasonicView::OnCustomdrawSlider1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
   xzhou=m_Slider.GetPos();	
	*pResult = 0;
}

void CUltrasonicView::OnStatisticParameter() 
{
	// TODO: Add your command handler code here
//	m_cha=channel;
	long int sum,df;
	int i,max,min,av;
    
	intialpara();//获取通道比例因子

	if(m_realorhis==0)
    {
		      max=-3000,min=3000,sum=0;
			for (i=xzhou+1;i<rxnum[channel]/2-xzhou;i++)
			{    
				sum=sum+RxDatab[channel][i];
				if(RxDatab[channel][i]>max) max=RxDatab[channel][i];
				if(RxDatab[channel][i]<min) min=RxDatab[channel][i];
			}
            av=sum/(rxnum[channel]/2-1-2*xzhou);
			df=0;
		for (i=xzhou+1;i<rxnum[channel]/2-xzhou;i++)
		{
		     df=df+pow((RxDatab[channel][i]-av),2);//*(RxDataOldb[channel][i]-av);			
		}
		df=df/(rxnum[channel]/2-2-2*xzhou);
		df=sqrt(df);
	}
	else
	{
		    max=-3000,min=3000,sum=0;
		for (i=xzhou+1;i<numx/2-xzhou;i++)
		{
			sum=sum+RxDataOldb[channel][i];
			if(RxDataOldb[channel][i]>max) max=RxDataOldb[channel][i];
			if(RxDataOldb[channel][i]<min) min=RxDataOldb[channel][i];
		}
		av=sum/(numx/2-1-2*xzhou);
        df=0;
		for (i=xzhou+1;i<numx/2-xzhou;i++)
		{
		     df=df+pow((RxDataOldb[channel][i]-av),2);//*(RxDataOldb[channel][i]-av);			
		}
		df=df/(numx/2-2-2*xzhou);
		df=sqrt(df);
	}
	parameter para;
    para.m_cha=channel+1;
	if(channel!=8)
	{
	para.m_max=(int)(max*m_k);
	para.m_min=(int)(min*m_k);
    para.m_average=(int)(av*m_k);
	para.m_avd=(int)(df*m_k);
	}
	else
	{ 
	para.m_max=0;
	para.m_min=0;

        sum=0;
		for (i=400;i<500;i++) //统计40到50米一段的速度
		{
			sum=sum+RxDataOldb[channel][i];			
		}
		av=sum/100;
    para.m_average=(int)av;
	para.m_avd=0;
	}
   	para.DoModal();
	
}

void CUltrasonicView::OnCoefficient() 
{
//	LPTSTR lpBuffer;
//	DWORD nBufferLength;
//	GetCurrentDirectory(nBufferLength,  // size, in characters, of directory buffer
//   lpBuffer ); 
//	SetCurrentDirectory(lpBuffer);
	ShellExecute(NULL,NULL,_T("notepad.exe"),
   _T(""),NULL,//D:\\高速摄像图像处理系统\\train
	 SW_SHOWNORMAL);
	
}

void CUltrasonicView::intialpara()
{
 
	 switch(channel)
			{
			case 0:m_k=(float)(m_kk1/100.0);
				break;
			case 1:m_k=(float)(m_kk2/100.0);
				break;
            case 2:m_k=(float)(m_kk3/100.0);
				break;
            case 3:m_k=(float)(m_kk4/100.0);
				break;
			case 4:m_k=(float)(m_kk5/100.0);
				break;
            case 5:m_k=(float)(m_kk6/100.0);
				break;
			case 6:m_k=(float)(m_kk7/100.0);
				break;
			case 7:m_k=(float)(m_kk8/100.0);
				break;
            case 8:m_k=(float)(m_kk9/100.0);
				break;
			default:break;
			}
    
}

void CUltrasonicView::OnParameterRead() 
{
	  /////////////打开参数数据文件////////////////////
	LPCTSTR lpszFilter="文本文件(*.txt)|*.txt|任何文件|*.*||";
    CFileDialog dlg(TRUE,lpszFilter,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,lpszFilter,NULL);
	CString a;
	if(dlg.DoModal() == IDOK)
	{

⌨️ 快捷键说明

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