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

📄 testdlg.cpp

📁 CAN网测试工具的源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	}

	str1.Format("%02x %02x %02x %02x",*(p1+0),*(p1+1),*(p1+2),*(p1+3));
	str2.Format("%02x %02x %02x %02x",*(p2+0),*(p2+1),*(p2+2),*(p2+3));

	m_strSdVoltage1 = str1;
	m_strSdVoltage2 = str2;
}


void CTestDlg::OnRadioNode0On() 
{
	// TODO: Add your control notification handler code here
	m_bIsOnNode0 = true;
	UpdateIDRadio();
}

void CTestDlg::OnRadioNode1On() 
{
	// TODO: Add your control notification handler code here
	m_bIsOnNode1 = true;
	UpdateIDRadio();
}

void CTestDlg::OnRadioNode2On() 
{
	// TODO: Add your control notification handler code here
	m_bIsOnNode2 = true;
	UpdateIDRadio();
}

void CTestDlg::OnRadioNode3On() 
{
	// TODO: Add your control notification handler code here
	m_bIsOnNode3 = true;
	UpdateIDRadio();
}

void CTestDlg::OnRadioNode4On() 
{
	// TODO: Add your control notification handler code here
	m_bIsOnNode4 = true;
	UpdateIDRadio();
}

void CTestDlg::OnRadioNode5On() 
{
	// TODO: Add your control notification handler code here
	m_bIsOnNode5 = true;
	UpdateIDRadio();
}

void CTestDlg::OnRadioNode6On() 
{
	// TODO: Add your control notification handler code here
	m_bIsOnNode6 = true;
	UpdateIDRadio();	
}

void CTestDlg::OnRadioNode7On() 
{
	// TODO: Add your control notification handler code here
	m_bIsOnNode7 = true;
	UpdateIDRadio();	
}

void CTestDlg::OnRadioNode0Off() 
{
	// TODO: Add your control notification handler code here
	m_bIsOnNode0 = false;
	UpdateIDRadio();
}

void CTestDlg::OnRadioNode1Off() 
{
	// TODO: Add your control notification handler code here
	m_bIsOnNode1 = false;
	UpdateIDRadio();
}

void CTestDlg::OnRadioNode2Off() 
{
	// TODO: Add your control notification handler code here
	m_bIsOnNode2 = false;
	UpdateIDRadio();
}

void CTestDlg::OnRadioNode3Off() 
{
	// TODO: Add your control notification handler code here
	m_bIsOnNode3 = false;
	UpdateIDRadio();
}

void CTestDlg::OnRadioNode4Off() 
{
	// TODO: Add your control notification handler code here
	m_bIsOnNode4 = false;
	UpdateIDRadio();
}

void CTestDlg::OnRadioNode5Off() 
{
	// TODO: Add your control notification handler code here
	m_bIsOnNode5 = false;
	UpdateIDRadio();
}


void CTestDlg::OnRadioNode6Off() 
{
	// TODO: Add your control notification handler code here
	m_bIsOnNode6 = false;
	UpdateIDRadio();	
}


void CTestDlg::OnRadioNode7Off() 
{
	// TODO: Add your control notification handler code here
	m_bIsOnNode7 = false;
	UpdateIDRadio();	
}

void CTestDlg::EnableWindowRadioNode(bool bEnable)
{
	CButton* pRadio;
	pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE0_ON);
	pRadio->EnableWindow(bEnable);
	pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE0_OFF);
	pRadio->EnableWindow(bEnable);

	pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE1_ON);
	pRadio->EnableWindow(bEnable);
	pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE1_OFF);
	pRadio->EnableWindow(bEnable);

	pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE2_ON);
	pRadio->EnableWindow(bEnable);
	pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE2_OFF);
	pRadio->EnableWindow(bEnable);

	pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE3_ON);
	pRadio->EnableWindow(bEnable);
	pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE3_OFF);
	pRadio->EnableWindow(bEnable);

	pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE4_ON);
	pRadio->EnableWindow(bEnable);
	pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE4_OFF);
	pRadio->EnableWindow(bEnable);

	pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE5_ON);
	pRadio->EnableWindow(bEnable);
	pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE5_OFF);
	pRadio->EnableWindow(bEnable);

	pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE6_ON);
	pRadio->EnableWindow(bEnable);
	pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE6_OFF);
	pRadio->EnableWindow(bEnable);

	pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE7_ON);
	pRadio->EnableWindow(bEnable);
	pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE7_OFF);
	pRadio->EnableWindow(bEnable);
}

void CTestDlg::UpdateIDRadio()
{
	CButton* pRadio;
	CEdit*   pEdit;

	if(m_bSendTimer)
	{
		pEdit = (CEdit* )GetDlgItem(IDC_EDIT_TIME);
		pEdit->SetReadOnly(true);
		pRadio = (CButton*)GetDlgItem(IDC_CHECK_TIMER);
		pRadio->SetCheck(true);
	}
	else
	{
		pEdit = (CEdit* )GetDlgItem(IDC_EDIT_TIME);
		pEdit->SetReadOnly(false);
		pRadio = (CButton*)GetDlgItem(IDC_CHECK_TIMER);
		pRadio->SetCheck(false);
	}

	if(m_bAutoSaveCan)
	{
		pRadio = (CButton*)GetDlgItem(IDC_CHECK_AUTOSAVECAN);
		pRadio->SetCheck(true);
	}
	else
	{
		pRadio = (CButton*)GetDlgItem(IDC_CHECK_AUTOSAVECAN);
		pRadio->SetCheck(false);
	}

	if(m_bSourceDataViewEnable)
	{
		pRadio = (CButton*)GetDlgItem(IDC_CHECK_SOURCEDATAVIEW);
		pRadio->SetCheck(true);
	}
	else
	{
		pRadio = (CButton*)GetDlgItem(IDC_CHECK_SOURCEDATAVIEW);
		pRadio->SetCheck(false);
	}

	if(m_bCheckDataType)
	{
		pRadio = (CButton*)GetDlgItem(IDC_CHECK_DATATYPE);
		pRadio->SetCheck(true);
	}
	else
	{
		pRadio = (CButton*)GetDlgItem(IDC_CHECK_DATATYPE);
		pRadio->SetCheck(false);
	}

    
	if(!m_bIsOnNode0)
	{
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE0_ON);
		pRadio->SetCheck(false);
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE0_OFF);
		pRadio->SetCheck(true);
	}
	else
	{
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE0_ON);
		pRadio->SetCheck(true);
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE0_OFF);
		pRadio->SetCheck(false);
	}

	if(!m_bIsOnNode1)
	{
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE1_ON);
		pRadio->SetCheck(false);
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE1_OFF);
		pRadio->SetCheck(true);
	}
	else
	{
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE1_ON);
		pRadio->SetCheck(true);
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE1_OFF);
		pRadio->SetCheck(false);
	}

	if(!m_bIsOnNode2)
	{
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE2_ON);
		pRadio->SetCheck(false);
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE2_OFF);
		pRadio->SetCheck(true);
	}
	else
	{
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE2_ON);
		pRadio->SetCheck(true);
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE2_OFF);
		pRadio->SetCheck(false);
	}

	if(!m_bIsOnNode3)
	{
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE3_ON);
		pRadio->SetCheck(false);
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE3_OFF);
		pRadio->SetCheck(true);
	}
	else
	{
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE3_ON);
		pRadio->SetCheck(true);
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE3_OFF);
		pRadio->SetCheck(false);
	}

	if(!m_bIsOnNode4)
	{
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE4_ON);
		pRadio->SetCheck(false);
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE4_OFF);
		pRadio->SetCheck(true);
	}
	else
	{
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE4_ON);
		pRadio->SetCheck(true);
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE4_OFF);
		pRadio->SetCheck(false);
	}

	if(!m_bIsOnNode5)
	{
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE5_ON);
		pRadio->SetCheck(false);
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE5_OFF);
		pRadio->SetCheck(true);
	}
	else
	{
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE5_ON);
		pRadio->SetCheck(true);
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE5_OFF);
		pRadio->SetCheck(false);
	}

	if(!m_bIsOnNode6)
	{
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE6_ON);
		pRadio->SetCheck(false);
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE6_OFF);
		pRadio->SetCheck(true);
	}
	else
	{
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE6_ON);
		pRadio->SetCheck(true);
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE6_OFF);
		pRadio->SetCheck(false);
	}

	if(!m_bIsOnNode7)
	{
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE7_ON);
		pRadio->SetCheck(false);
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE7_OFF);
		pRadio->SetCheck(true);
	}
	else
	{
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE7_ON);
		pRadio->SetCheck(true);
		pRadio = (CButton*)GetDlgItem(IDC_RADIO_NODE7_OFF);
		pRadio->SetCheck(false);
	}

	CANNODE node;
    node.nodebit0 = m_bIsOnNode0;
	node.nodebit1 = m_bIsOnNode1;
	node.nodebit2 = m_bIsOnNode2;
	node.nodebit3 = m_bIsOnNode3;
	node.nodebit4 = m_bIsOnNode4;
	node.nodebit5 = m_bIsOnNode5;
	node.nodebit6 = m_bIsOnNode6;
	node.nodebit7 = m_bIsOnNode7;

	m_byteNodeNo = node.NODE;
	m_iNodeNo = m_byteNodeNo;
	m_cmbNodeNo.SetCurSel(m_iNodeNo);
}


void CTestDlg::OnSelchangeCmbNodeno() 
{
	// TODO: Add your control notification handler code here
	m_iNodeNo = m_cmbNodeNo.GetCurSel();
	m_byteNodeNo = m_iNodeNo;

	CANNODE node;
	node.NODE = m_byteNodeNo;

    m_bIsOnNode0 = node.nodebit0;
	m_bIsOnNode1 = node.nodebit1;
    m_bIsOnNode2 = node.nodebit2;
    m_bIsOnNode3 = node.nodebit3;
    m_bIsOnNode4 = node.nodebit4;
    m_bIsOnNode5 = node.nodebit5;
    m_bIsOnNode6 = node.nodebit6;
    m_bIsOnNode7 = node.nodebit7;

    UpdateIDRadio();
}


void CTestDlg::OnCheckAutoSaveCan() 
{
	// TODO: Add your control notification handler code here
	m_bAutoSaveCan = !m_bAutoSaveCan;

	UpdateIDRadio();
}

void CTestDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	COleDateTime  timeSys;
	CString strFrameSum;
	switch(nIDEvent)
	{
	case 1:
		if(m_connect != 1)
		{
		   m_progressSysRunStatus.SetPos(0);
		}
		else
		{
			timeSys = COleDateTime::GetCurrentTime();
			m_progressSysRunStatus.SetPos(timeSys.GetSecond()%4 + 1);
            
			strFrameSum.Format("%d",m_iFrameCount);
			m_editFrameSum.SetWindowText(strFrameSum);
		}

		break;
	case 2:
		if(m_bSendTimer && (m_connect == 1))
			OnButtonSend();
		break;

	default:
		break;
	}

	CDialog::OnTimer(nIDEvent);
}

void CTestDlg::OnCheckSourceDataView() 
{
	// TODO: Add your control notification handler code here
	m_bSourceDataViewEnable = !m_bSourceDataViewEnable;

	UpdateIDRadio();	
}

void CTestDlg::OnButtonExtendWindow() 
{
	// TODO: Add your control notification handler code here
	m_bExtendWindow = !m_bExtendWindow;

	int iDetaX = 0;
	if(m_bExtendWindow)
	{
		iDetaX = 385;
		m_button_extendwindow.SetWindowText(">>");
	}
	else
	{
		m_button_extendwindow.SetWindowText("<<");
		iDetaX = -385;
	}

	CRect rectWindow;
	AfxGetApp()->GetMainWnd()->GetWindowRect(&rectWindow);
	MoveWindow(rectWindow.TopLeft().x,rectWindow.BottomRight().y,rectWindow.Width() - iDetaX,rectWindow.Height(),TRUE);
	CenterWindow(NULL);
}

void CTestDlg::OnButtonCalculate() 
{
	// TODO: Add your control notification handler code here
    UpdateData(true);

	CIDCalculate dlg;
	if(m_ComboSendFrmType.GetCurSel() == 1)
		dlg.m_bExtFrameType = true;
	else
		dlg.m_bExtFrameType = false;

	dlg.m_strID = m_EditSendFrmID;
	dlg.ConvertFromIDToIDByte(dlg.m_strIDByte,dlg.m_strID);

	if(dlg.DoModal() == IDOK)
	{
	   m_EditSendFrmID	= dlg.m_strID;
	   UpdateData(FALSE);
	}
}


void CTestDlg::OnCheckTimerSend() 
{
	// TODO: Add your control notification handler code here
	if(m_connect == 0)
	{
		AfxMessageBox("请先连接CAN网!");
		UpdateIDRadio();
		return;
	}

	m_bSendTimer = !m_bSendTimer;
	UpdateIDRadio();
    
	if(m_bSendTimer)
	{
		UpdateData(true);
		SetTimer(2,m_iTimePre,NULL);
	}
	else
	{
		KillTimer(2);
	}
}

void CTestDlg::OnCheckDataType() 
{
	// TODO: Add your control notification handler code here
	m_bCheckDataType = !m_bCheckDataType;
    UpdateIDRadio();
}

void CTestDlg::UpdateUserInputWindow() 
{
	// TODO: Add your control notification handler code here
	CButton* pBut;
	if(m_devtype == VCI_USBCAN2)
	{
		pBut = (CButton* )GetDlgItem(IDC_EDIT_REVPORT);
		pBut->EnableWindow(false);
		pBut = (CButton* )GetDlgItem(IDC_EDIT_SENDPORT);
		pBut->EnableWindow(false);
		pBut = (CButton* )GetDlgItem(IDC_IPADDRESS_CANET);
		pBut->EnableWindow(false);
		pBut = (CButton* )GetDlgItem(IDC_COMBO_BAUDRATE);
		pBut->EnableWindow(true);		
	}
	else
	{
		pBut = (CButton* )GetDlgItem(IDC_EDIT_REVPORT);
		pBut->EnableWindow(true);
		pBut = (CButton* )GetDlgItem(IDC_EDIT_SENDPORT);
		pBut->EnableWindow(true);
		pBut = (CButton* )GetDlgItem(IDC_IPADDRESS_CANET);
		pBut->EnableWindow(true);
		pBut = (CButton* )GetDlgItem(IDC_COMBO_BAUDRATE);
		pBut->EnableWindow(false);
	}
}

void CTestDlg::ReadConfig()
{
    CFileException fe;
	CFile IniFile;

	CString strPathName;
	char uPathName[512];

	::GetCurrentDirectory(512,uPathName);
	strPathName = LPTSTR(uPathName); 

	CString strFileName = _T("VDRIPSE.exe"); 
	CFileFind finder;
	BOOL bWorking = finder.FindFile(strFileName);
	if(bWorking)
		m_strAppPath = strPathName + "\\TOOLS";
	else
		m_strAppPath = strPathName;

    if(!IniFile.Open(m_strAppPath+"\\ADCAN.ini",CFile::modeRead,&fe))
	{
		m_devtype   = VCI_USBCAN2;
		m_iRevPort  = 4060;
		m_iSndPort  = 4001;

		m_strBaudRate = "125000";

		m_byteIP[0] = 192;
		m_byteIP[1] = 168;
		m_byteIP[2] = 0;
		m_byteIP[3] = 196;

		m_strPathName = "C:\\";

		return ;
	}

	CArchive LoadArchive( &IniFile, CArchive::load);
    LoadArchive>>m_devtype;
	LoadArchive>>m_iRevPort;
	LoadArchive>>m_iSndPort;

	LoadArchive>>m_strBaudRate;

    LoadArchive>>m_byteIP[0];
	LoadArchive>>m_byteIP[1];
	LoadArchive>>m_byteIP[2];
	LoadArchive>>m_byteIP[3];

	LoadArchive>>m_strPathName;

	LoadArchive.Close();
	IniFile.Close();
}


void CTestDlg::WriteConfig()
{	
    CFileException fe;
	CFile IniFile;
	
	IniFile.Open(m_strAppPath + "\\ADCAN.ini",CFile::modeCreate,&fe);
	IniFile.Close();

    if(!IniFile.Open(m_strAppPath + "\\ADCAN.ini",CFile::modeWrite,&fe))
	{
		return ;
	}

    UpdateData(true);
	m_ComboBaudRate.GetLBText(m_ComboBaudRate.GetCurSel( ),m_strBaudRate);
    m_IPAddress.GetAddress(m_byteIP[0],m_byteIP[1],m_byteIP[2],m_byteIP[3]);

	CArchive SaveArchive( &IniFile, CArchive::store);


    SaveArchive<<m_devtype;
	SaveArchive<<m_iRevPort;
	SaveArchive<<m_iSndPort;

	SaveArchive<<m_strBaudRate;

    SaveArchive<<m_byteIP[0];

⌨️ 快捷键说明

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