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

📄 cgedoc.cpp

📁 《面向对象程序设计实用教程》一书的源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
					c_temp[6]=tongdao_number[par.channel_index];
					break;}
	}

	
    c_temp[7]=chufa[par.chufa_index ];        //码串8
	c_temp[8]=length[par.length_index ];      //码串6
	int ys_time;
	ys_time = atoi(s[6]);
	char sa[5];	
	itoa(ys_time,sa,10);
	int ns = strlen(sa);
	if (ns==4)
	{  c_temp[9] =  sa[0];
	   c_temp[10] = sa[1]; 
	   c_temp[11] = sa[2];
	   c_temp[12] = sa[3]; 
	}
	if (ns==3)
	{  c_temp[9] =  0x30;
	   c_temp[10] = sa[0]; 
	   c_temp[11] = sa[1];
	   c_temp[12] = sa[2]; 
	}
	if (ns==2)
	{  c_temp[9] =  0x30;
	   c_temp[10] = 0x30; 
	   c_temp[11] = sa[0];
	   c_temp[12] = sa[1]; 
	}
	if (ns==1)
	{  c_temp[9] =  0x30;
	   c_temp[10] = 0x30; 
	   c_temp[11] = 0x30;
	   c_temp[12] = sa[0]; 
	}

    // 10Dms = 0x30303130
    //power_index =                           //码串1
	
	//待加

    //power_index =                           //码串1
	
	//待加

	//call OnWrcom() 
	MyTTY.CloseConnection(); //关闭串口
	//初始化串口并建立一个读线程
	MyTTY.ComPort = m_com;
	MyTTY.CreateTTYInfo();
	if(MyTTY.OpenConnection() == FALSE)
		return;	
	// 向串口写 teststring[256]
	//WriteCommBlock( 串口句柄, 预备写的串 , 串的长度,实际写入的长度);
	//char teststring[256];  
	//teststring[0]=0x0f; //启动自校验
	
	BOOL bret;
	DWORD dwwritenlen;
	if (MyTTY.npTTYInfo!=NULL)
	{
		//bret = WriteCommBlock( MyTTY.npTTYInfo, (BYTE *)teststring , 1,&dwwritenlen); //(DWORD )strlen(teststring)=1
		bret = WriteCommBlock( MyTTY.npTTYInfo, c_temp , 13,&dwwritenlen); //(DWORD )strlen(c_temp) = 6
		if (bret && (dwwritenlen>0))
		{
			PurgeComm(COMDEV(MyTTY.npTTYInfo),PURGE_TXCLEAR);
			//char temp[256];
			//sprintf(temp,"write %d success!",dwwritenlen);
			//AfxMessageBox(temp);
		}
		else
		{	AfxMessageBox("Write failed!");
			return ;
		}
	}
	else
	{	AfxMessageBox("COM not opened!");
		return ;
	}

	}//实际采样

	}
	
	
	if(!monicaiyang)
	{
	
	//事件驱动(中断)读
    //if(M_COM_Return == 0x0e){}
	
	// 从串口直接读到abIn ,不使用事件驱动(中断)读
	//ReadCommBlock( 串口句柄, 读到的串指针 , 可以读到的最大长度=80);	
	//查询读
	int nLength;

	BYTE        abIn[ MAXBLOCK + 1] ;
	do
	{
	nLength = ReadCommBlock( MyTTY.npTTYInfo, (LPSTR) abIn, MAXBLOCK );
	if (nLength>0)
		{	
			//itoa(abIn[0],s_abIn,16);
			//AfxMessageBox(s_abIn);
		}
	}while (nLength<=0);  //(nLength<=0);
	
	if(abIn[0]==0x0e)
	{				  
	  //AfxMessageBox("参数设置发送正确...");
	  //return ;
	}
	else 
	{
	  AfxMessageBox("通讯失败...");
	  return ;	  
	}  

	}//实际采样

	if(	par.parcaiyangKey )
	{
		par.parcaiyangKey = false;
		caiyang();
		//Oncaiyang1();
	}
}	 
  	   

/*void CCgeDoc::Oncanshu5() 
{
	// TODO: Add your command handler code here
	
	Setpar par;
	int OKOrCANCEL;
	BYTE temp[6];
	for(int i=0;i<9;i++)
	    par.s[i] = s[i];//数据从Document类到Setpar对话框
    par.setpar_s8 = Num_Line;
	temp[0]=Channel_2[par.tongdao_index];	
	temp[1]=Channel_6[par.tongdao_index];	
	temp[2]=gaojie[par.gaojie_index ];
	temp[3]=length[par.length_index ];
	temp[4]=chufa[par.chufa_index ];
	temp[5]=xianbo[par.xianbo_index ];
	
	//for(int j=0;j<6;j++)
	//	TRACE("%s",temp[j]);

	


	OKOrCANCEL = par.DoModal();
	if (OKOrCANCEL = !IDOK)
	    return;   
	else
	{for(int i=0;i<9;i++)
	    s[i] = par.s[i];//数据从Setpar对话框到Document类
	 
	Num_Line = par.setpar_s8;
	Num_Pointes = atoi(s[5]);// 在char* 的地方可以直接使用CString的对象
	m_No = par.s[0];
		
	 canshuKey = false; //参数设置完成以后,允许采样
	 caiyangKey = true;
		temp[0]=Channel_2[par.tongdao_index];	
	temp[1]=Channel_6[par.tongdao_index];	
	temp[2]=gaojie[par.gaojie_index ];
	temp[3]=length[par.length_index ];
	temp[4]=chufa[par.chufa_index ];
	temp[5]=xianbo[par.xianbo_index ];


	}
     

}*/



/*void CCgeDoc::Oncanshu5() 
{
	// TODO: Add your command handler code here
	
	Setpar par;
	int OKOrCANCEL;
	BYTE c_temp[10];
	for(int i=0;i<9;i++)
	    par.s[i] = s[i];//数据从Document类到Setpar对话框
    par.setpar_s8 = Num_Line;	

	OKOrCANCEL = par.DoModal();
	if (OKOrCANCEL = !IDOK)
	    return;   
	else
	{for(int i=0;i<9;i++)
	    s[i] = par.s[i];//数据从Setpar对话框到Document类
	 
	Num_Line = par.setpar_s8;
	Num_Pointes = atoi(s[5]);// 在char* 的地方可以直接使用CString的对象
	m_No = par.s[0];
		
	 canshuKey = false; //参数设置完成以后,允许采样
	 caiyangKey = true;
	
    //获得数据通信规约的码串1_10    c_temp(0_9)  	
	
	c_temp[0]=xianbo[par.xianbo_index ];      //码串2
	c_temp[1]=dijie[par.dijie_index ];        //码串3  ??
	c_temp[2]=gaojie[par.gaojie_index ];      //码串4
	//c_temp[3] = zengy_index = 0x00;         //码串7 增益倍数
    //case 
	//码串1  
	switch  (par.channel_index) 
	{
		case 0:    {c_temp[4]=Channel_2[par.tongdao_index];	  
					c_temp[6]=tongdao_number[par.channel_index];
					break;}
		case 1:    {c_temp[4]=Channel_6[par.tongdao_index];	  
					c_temp[6]=tongdao_number[par.channel_index];
					break;}
		case 2:    {c_temp[4]=Channel_2[par.tongdao_index];	  
					c_temp[6]=tongdao_number[par.channel_index];
					break;}
		case 3:    {c_temp[4]=Channel_2[par.tongdao_index];	  
					c_temp[6]=tongdao_number[par.channel_index];
					break;}
	}

	
    c_temp[5]=jiange[par.jiange_index];	      //码串5  ?? 
	//c_temp[6]=Channel_2[par.tongdao_index];	  //码串10  !_4
    c_temp[7]=chufa[par.chufa_index ];        //码串8
	c_temp[8]=length[par.length_index ];      //码串6
	//c_temp[9] = yanshi_time                 //码串9  ??转换函数	
	    // 10Dms = 0x30303130
    //power_index =                           //码串1
	
	//待加

	//call OnWrcom() 
	//初始化串口并建立一个读线程
	MyTTY.ComPort = m_com;
	MyTTY.CreateTTYInfo();
	if(MyTTY.OpenConnection() == FALSE)
		return;	
	// 向串口写 teststring[256]
	//WriteCommBlock( 串口句柄, 预备写的串 , 串的长度,实际写入的长度);
	char teststring[256];  
	teststring[0]=0x0f; //启动自校验
	
	BOOL bret;
	DWORD dwwritenlen;
	if (MyTTY.npTTYInfo!=NULL)
	{
		//bret = WriteCommBlock( MyTTY.npTTYInfo, (BYTE *)teststring , 1,&dwwritenlen); //(DWORD )strlen(teststring)=1
		bret = WriteCommBlock( MyTTY.npTTYInfo, c_temp , 6,&dwwritenlen); //(DWORD )strlen(c_temp) = 6
		if (bret && (dwwritenlen>0))
		{
			PurgeComm(COMDEV(MyTTY.npTTYInfo),PURGE_TXCLEAR);
			char temp[256];
			sprintf(temp,"write %d success!",dwwritenlen);
			AfxMessageBox(temp);
		}
		else
			AfxMessageBox("Write failed!");
	}
	else
		AfxMessageBox("COM not opened!");
	
	// 从串口读到abIn 
	//ReadCommBlock( 串口句柄, 读到的串指针 , 可以读到的最大长度=80);	
	/*  //查询读
	int nLength;
	BYTE        abIn[ MAXBLOCK + 1] ;
	do
	{
	nLength = ReadCommBlock( MyTTY.npTTYInfo, (LPSTR) abIn, MAXBLOCK );
	if (nLength>0)
		{	AfxMessageBox((char*)abIn);}
	}while (nLength<=0);  //(nLength<=0);
	*/
	//事件驱动(中断)读

//	}
     

//}	   	   

void CCgeDoc::Oncaiyang1() //开始单次采样
{	
	POSITION Position;
	Position = GetFirstViewPosition();
	CView* pVView = GetNextView(Position);
	CCgeView *pView;
	while(pVView!=NULL)
	{
		if(pVView->IsKindOf(RUNTIME_CLASS(CCgeView)))
		{ break;};
		pVView = GetNextView(Position);
	}
	pView = (CCgeView *)pVView;

	if (IsModified() != 0)//提示数据已经修改,是否保存
	{
		//OnFileSave();
		pView->m_Viewparfile();
		SetModifiedFlag( false );
	}
	caiyang();

	//m611
	if(s[4].Right(2) == "us")
	{
		m_jiange = atof(s[4])/1000.0;
	}
	//m723
	if(s[4].Right(2) == "ms")
	{
		m_jiange = atof(s[4]);
	}
	m_dtf = m_jiange;
	
	Fangs = s[0];
	
    CDialogBar* pDLGBAR = (CDialogBar* )AfxGetApp()->m_pMainWnd->GetDescendantWindow(CG_ID_VIEW_MYDIALOGBAR);
	//pDLGBAR->GetDlgItem(IDC_DLGBARUSORMS)->SetWindowText("  "+s[4].Right(2));
	pDLGBAR->GetDlgItem(IDC_DLGBARUSORMS)->SetWindowText("  ms");
	//m611
	

}

//DEL void CCgeDoc::Oncaiyang3() //重新采样
//DEL {
//DEL 	if (IsModified()!=0)//提示数据已经修改,是否保存
//DEL 	  OnFileSave();
//DEL 	
//DEL  if(!m_CMyLineList.IsEmpty())
//DEL    {	
//DEL 		//m_CMyLineList.RemoveAll();// CAge's aren't destroyed.	
//DEL 		//ASSERT(m_CMyLineList.IsEmpty()); // Yes it is.			
//DEL 		CMyLine *pMyLine;
//DEL 		POSITION ps;
//DEL 		ps = m_CMyLineList.GetHeadPosition();
//DEL 		while ( ps != NULL )
//DEL 		{			
//DEL 			pMyLine = (CMyLine *)m_CMyLineList.GetNext(ps);
//DEL 			delete pMyLine; // Now delete the CAge objects.
//DEL 		}
//DEL 		m_CMyLineList.RemoveHead();
//DEL 		m_CMyLineList.RemoveAll();// CAge's aren't destroyed.	
//DEL 		
//DEL 		ASSERT(m_CMyLineList.IsEmpty()); // Yes it is.			
//DEL 
//DEL    }
//DEL 	//	m_CMyLineList.RemoveAll();
//DEL    //  if(m_CMyLineList.IsEmpty())
//DEL 	//	nCount = m_CMyLineList.GetCount();
//DEL 	blank=true;
//DEL 	unbas=true;
//DEL 
//DEL 	canshuKey = true;
//DEL 	recaiyangKey = true; //false;
//DEL 	m_Ndb = 0;
//DEL 	m_H = 0;
//DEL 	
//DEL //	CRect rect;
//DEL //	view2->GetClientRect(&rect);
//DEL //	view2->InvalidateRect(&rect,FALSE);
//DEL 	
//DEL //	view2->Invalidate();
//DEL 	UpdateAllViews(NULL);
//DEL 	
//DEL //	RedrawWindow(NULL,NULL);
//DEL 	
//DEL }

//DEL void CCgeDoc::OnUpdatecaiyang1(CCmdUI* pCmdUI) 
//DEL {
//DEL 
//DEL 	   pCmdUI->Enable(caiyangKey);//没有设置参数以前,禁止采样
//DEL }

void CCgeDoc::DrawLine(CDC * pDC)
{		   
  //关于 X 值的计算请参考此函数中xp2
  int i,j,xp1,yp1,xp2,yp2,ENp;
  POSITION m_position;
  CMyLine* pMyLine;

  BOOL Draw_T = false;
  int  Draw_i;
  if(Fangs==s[0] ) Draw_T = true;
  Draw_i = atoi(Fangs)-1;
  ENp = Num_Pointes-1;
	
  if(!m_CMyLineList.IsEmpty())
  {			
			m_position = m_CMyLineList.GetHeadPosition();
 	 		
		
			for(i=0;i<Num_Line;i++)
			{   
				pMyLine = (CMyLine* )m_CMyLineList.GetNext(m_position);	
				//xp1 = (pMyLine->mypoint.x+m_viewX0);  
				xp1 = m_viewX0; //注意调节步长
				yp1 = (pMyLine->y * m_stepY + i*basline+m_viewY0);  			 			    
				pDC->MoveTo(xp1,yp1); //画第一个点
				
			  for(j=0;j<ENp;j++) //注意已经取出了一个数
			  {
				    pMyLine = (CMyLine* )m_CMyLineList.GetNext(m_position);					  
					xp2 = j * m_stepX + m_viewX0;   
					//yp2 = pMyLine->y * m_stepY + i * basline + m_viewY0;//???  
						
					if(Draw_T)
					{
					  yp2 = pMyLine->y * m_stepY  + i * basline + m_viewY0;  
					}else if(i == Draw_i)
					{
					  yp2 = pMyLine->y * m_stepY  + i * basline + m_viewY0; 
					  	//单放其他道时,所有通道回到原来状态
					}else 
					{
					  yp2 = pMyLine->y * old_m_stepY + i * basline + m_viewY0;  
					}
				    /*
					CString s;
					s.Format("%d",FillKey);
					
					if(FillKey && yp2 < (i-1)*basline)
					{AfxMessageBox(s);
						break;
					}*/
						pDC->LineTo(xp2,yp2);
					
			  }

			}    
  //CString sd;
  //static int d=0;
  //d++;
  //sd.Format("%d",d);
	//		pDC->TextOut(140,240,sd);
  }


}


void CCgeDoc::OnUpdateChuli1(CCmdUI* pCmdUI) 
{

	pCmdUI->Enable(drawlineKey);
}

void CCgeDoc::OnFileOpen() 
{
	/*int OKORCANCEL;
	CMdlg mdlg;
	if (IsModified()!=0)//提示数据已经修改,是否保存
	{	  
		OKORCANCEL = mdlg.DoModal();
		if(OKORCANCEL==IDOK)
		{
			OnFileSave();
		}
	}*/
	
	blank=false;
	unbas=false;
	int IDOKCANCEL;
    CString PathName;
    //SetCurrentDirectory( "e:\\cge\\5-13" ); //指定缺省路径	
	CFileDialog fdlg(true,"dat",NULL,
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"CGE串行化文件(*.dat) |*.dat|CGE File(*.*) |*.*||" );      

	/*char lpszTitle[]={"      地震仪VC串行化文件"};//{"Save As File"};
	fdlg.m_ofn.lpstrTitle=lpszTitle;*/
	IDOKCANCEL = fdlg.DoModal();	
	if(IDOKCANCEL == IDOK)
	{
	  
		if(!m_CMyLineList.IsEmpty())
		{	
			CMyLine *pMyLine;
			POSITION ps;
			ps = m_CMyLineList.GetHeadPosition();
			while ( ps != NULL )
			{			
				pMyLine = (CMyLine *)m_CMyLineList.GetNext(ps);
				delete pMyLine; // Now delete the CAge objects.
			}
			m_CMyLineList.RemoveHead();
			m_CMyLineList.RemoveAll();// CAge's aren't destroyed.	
		
			ASSERT(m_CMyLineList.IsEmpty()); // Yes it is.			

		}
		
	
	PathName = fdlg.GetPathName();
	this->SetPathName(PathName,true);
	
	CDocument::OnOpenDocument(PathName);

	m_Fill = 0;
	//olddataKey = true;
	}
	else
	{
			int err = CommDlgExtendedError();
			return;
	}
	
	m_iniapage();
	Fangs = s[0];
	if(recentpath)
	{
		POSITION Position;
		Position = GetFirstViewPosition();
		CView* pVView = GetNextView(Position);
		CCgeView *pView;
		while(pVView!=NULL)
		{
			if(pVView->IsKindOf(RUNTIME_CLASS(CCgeView)))
				{ break;};
			pVView = GetNextView(Position);
		}
			pView = (CCgeView *)pVView;	

⌨️ 快捷键说明

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