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

📄 dialoglpt.cpp

📁 CAN通讯的测试软件,数据可发送及接收,并能设置时间
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		CAN_Status();
	}
	CDialog::OnTimer(nIDEvent);
}


void dialogLpt:: CAN_Send()
{
	unsigned int   retval;
    CString        m_display;
	unsigned int   loopX;
	char           buffer[20];

	//#1
	ptrStruct.card = 0x0;
	ptrStruct.channel = 0x0;

	if(m_pDlgDataFrame->m_setPacketNum)
	{
	   while(m_sendNum < m_pDlgDataFrame->m_setPacketNum) //2003.1.6
	   {
          //retval = CAN_Trans(&ptrStruct,&m_pDlgDataFrame->ptrPacket[0]);
		  
	      retval = CAN_Trans(&ptrStruct,&m_pDlgDataFrame->ptrPacket[m_sendNum]);
		  
		  //InterlockedIncrement((LPLONG)m_totalSend);
		  m_intSendNum += 1;		 
          ltoa(m_intSendNum,buffer,10);
          m_display = "No." + (CString)buffer;

		  // 需要显示发送的数据位           
		  if(m_chkDisplaySend.GetCheck() == 1)
		  {
			  // 数据过长,清除所有的显示
			  if(m_lstSend.GetCount() > 100)
			  {
				  m_lstSend.ResetContent(); 
			  }			  
			  // ID and DATA length
			  m_display = m_display + " A:";	
			  if(m_workMode)
			  {
                  m_display +=  m_pDlgDataFrame->HexToString(m_pDlgDataFrame->ptrPacket[m_sendNum].CAN_ID * 8);
			  }
			  else
			  {
			      m_display +=  m_pDlgDataFrame->HexToString(m_pDlgDataFrame->ptrPacket[m_sendNum].CAN_ID * 32);
			  }

			  m_display += " L:" + m_pDlgDataFrame->HexToString(m_pDlgDataFrame->ptrPacket[m_sendNum].length);  
              m_display += " D:";
			  // Data
			  for(loopX = 0; loopX < m_pDlgDataFrame->ptrPacket[m_sendNum].length; loopX++)
			  {
                 m_display += m_pDlgDataFrame->HexToString(m_pDlgDataFrame->ptrPacket[m_sendNum].data[loopX]) + " ";
			  }

			  // add string to LISTBx
			  m_lstSend.InsertString(-1,(LPCTSTR)m_display);
		  }
		  UpdateData(FALSE);

          // 每次循环的计数
		  m_sendNum += 1;
		  Sleep(10);
	   }
       m_sendNum = 0;
	}
}


void  dialogLpt::CAN_Rec()
{
    unsigned int   retVal;
    CString        m_display;
	unsigned int   loopX;
	char           buffer[20];
 
	// 通道1 接收数据
	ptrStruct.card = 0x0;
	ptrStruct.channel = 0x0;

	retVal = CAN_Rece(&ptrStruct,&ptrPacket);
	if(!retVal)
	{
		return;
	}
	// display receive data
	m_intRecNum += 1;
   	ltoa(m_intRecNum,buffer,10);
	m_display = "No." + (CString)buffer;

    // 需要显示接收的数据位           
    if(m_chkDisplayRec.GetCheck() == 1)
    {
		  // 数据过长,清除所有的显示
		  if(m_lstRec.GetCount() > 100)
		  {
			  m_lstRec.ResetContent(); 
		  }			  
		  // ID and DATA length
		  m_display = m_display + " A:";				  

		  // workMode
		  if(m_workMode)
		  {
		      m_display +=  m_pDlgDataFrame->HexToString(ptrPacket.CAN_ID * 8);
		  }
		  else
		  {
			  m_display +=  m_pDlgDataFrame->HexToString(ptrPacket.CAN_ID * 32);
		  }

		  m_display += " L:" + m_pDlgDataFrame->HexToString(ptrPacket.length);  
		  m_display += " D:";
		  // Data
		  for(loopX = 0; loopX < ptrPacket.length; loopX++)
		  {
			 m_display += m_pDlgDataFrame->HexToString(ptrPacket.data[loopX]) + " ";
		  }

		  // add string to LISTBOx
		  m_lstRec.InsertString(-1,(LPCTSTR)m_display);
	}
    // update
	UpdateData(FALSE);
}
      

void dialogLpt::CAN_Status()
{
	unsigned int retVal;
	// #1
	ptrStruct.card = 0x0;
	ptrStruct.channel = 0x0;
    retVal = CAN_Inquiry_Status(&ptrStruct);
	
	// enable all status
	m_opt1.SetCheck(FALSE); 
	m_opt2.SetCheck(FALSE); 
	m_opt3.SetCheck(FALSE); 
	m_opt4.SetCheck(FALSE); 
	m_opt5.SetCheck(FALSE); 
	m_opt6.SetCheck(FALSE); 
	m_opt7.SetCheck(FALSE); 
	m_opt8.SetCheck(FALSE); 

	// 显示状态
    retVal = retVal & 0x0ff;
	if(retVal & 0x01)
	{
		m_opt1.SetCheck(TRUE);		
		
	}
	if(retVal & 0x02)
	{
		m_opt2.SetCheck(TRUE);		
	}
	if(retVal & 0x04)
	{
		m_opt3.SetCheck(TRUE);		
	}
	if(retVal & 0x08)
	{
		m_opt4.SetCheck(TRUE);		
	}
	if(retVal & 0x10)
	{
		m_opt5.SetCheck(TRUE);		
	}
	if(retVal & 0x20)
	{
		m_opt6.SetCheck(TRUE);		
	}
	if(retVal & 0x40)
	{
		m_opt7.SetCheck(TRUE);		
	}
	if(retVal & 0x80)
	{
		m_opt8.SetCheck(TRUE);		
	}
}


void dialogLpt::OnChkStatus() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	if(m_chkStatus.GetCheck() == 1)
	{
       m_statusTimer = SetTimer(30,10,NULL);
	}
	else
	{
		if(m_statusTimer)
		{
			KillTimer(m_statusTimer);
		}
	}
}

void dialogLpt::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	m_pDlgDataFrame = NULL;
	CDialog::OnClose();
}

// 复位操作
void dialogLpt::OnBtnReset() 
{
	// TODO: Add your control notification handler code here
	unsigned int retVal;
	ptrStruct.card = 0;
	ptrStruct.channel = 0;
    // 复位第1路
	retVal =  CAN_Hard_Reset(&ptrStruct);
	if(retVal)
	{
	   this->MessageBox("复位成功","VCDemo",MB_OK); 
	}
	else
	{
       this->MessageBox("复位失败","VCDemo",MB_OK); 
	}
}

void dialogLpt::OnBtnRxBufferCount() 
{
	// TODO: Add your control notification handler code here
	unsigned int retVal;
	char buffer[10];
    
	// 第1路
	ptrStruct.card = 0x0;
	ptrStruct.channel = 0x0;

    retVal =  CAN_Get_RxBufferCount(&ptrStruct);
	itoa(retVal,buffer,10);
	this->MessageBox(buffer,"VCDemo",MB_OK); 	
}

void dialogLpt::OnBtnClearBuffer() 
{
	// TODO: Add your control notification handler code here
	unsigned int retVal;
    // 第1路
	ptrStruct.card = 0x0;
	ptrStruct.channel = 0x0;

	retVal =  CAN_Clear_RxBuffer(&ptrStruct);
}

void dialogLpt::OnChangeEdtSendLap() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(m_sendTimer!=NULL)
	{
		KillTimer(m_sendTimer);	
		m_sendTimer = SetTimer(10,m_intSendLap,NULL);
	}
}

void dialogLpt::OnChangeEdtRecLap() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
    UpdateData(TRUE);
	if(m_recTimer!=NULL)
	{
		KillTimer(m_recTimer);
		m_recTimer =  SetTimer(20,m_intRecLap,NULL);	
	}
}

void dialogLpt::OnBtnRecEnabled() 
{
	// TODO: Add your control notification handler code here
	unsigned int retVal;
    
	// 第1路	
	ptrStruct.card = 0x0;
	ptrStruct.channel = 0x0;
  
	retVal =  CAN_Enable_Receive(&ptrStruct);
	m_btnRecEnabled.EnableWindow(FALSE);
	m_btnRecDisabled.EnableWindow(TRUE);
}

void dialogLpt::OnBtnRecDisabled() 
{
	// TODO: Add your control notification handler code here
	unsigned int retVal;

    // 第1路
	ptrStruct.card = 0x0;
	ptrStruct.channel = 0x0;
	
	retVal =  CAN_Disable_Receive(&ptrStruct);
	m_btnRecEnabled.EnableWindow(TRUE);
	m_btnRecDisabled.EnableWindow(FALSE);
}

void dialogLpt::OnBtnReadBuffer() 
{
	// TODO: Add your control notification handler code here

}

⌨️ 快捷键说明

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