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

📄 pmacctrldlg.cpp

📁 利用VC编写的PMAC控制芯片驱动程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	// TODO: Add your command handler code here
	// Show prompt information at the bottom of the dialog
	UpdateData(TRUE);
	m_Info = "正在进行数据处理:插补——逆解,请稍候...";
	UpdateData(FALSE);

	// Get the current track
	CString msg;
	m_cb.GetLBText(m_cb.GetCurSel(),msg);
	
	// Do interpolation
	if(msg == "直线_LINE")
		CPmacCtrlDlg::OnCtrlInterpolationL();
	else if(msg == "圆_CIRCLE")
		CPmacCtrlDlg::OnCtrlInterpolationC();
	else
		CPmacCtrlDlg::OnCtrlInterpolationH();

	Sleep(5000);	//delay

	// show prompt information
	m_Info = "数据处理完成,可以下载数据文件至PMAC,也可查看插补、逆解数据。";
	UpdateData(FALSE);
}

//	================="初始化PMAC"-函数================
//	==========================================
void CPmacCtrlDlg::OnCtrlInitial() 
{
	// TODO: Add your command handler code here
	// show prompt information
	m_Info = "正在对PMAC进行初始化设置,请稍候...";
	UpdateData(FALSE);

	OpenPmacDevice(0);
	PmacFlush(0);

	// Send reset command to PMAC
	char	response[20];
	UINT	maxchar = 20;
	CString	reset;
	reset = "$$$";
	PmacGetResponse(0, response, maxchar, reset);
	Sleep(10000);	// delay
	PmacGetResponse(0, response, maxchar, reset);
	Sleep(10000);	// delay

	// show prompt information
	m_Info = "PMAC初始化完毕!要继续,请执行“机床归零”!";
	UpdateData(FALSE);
}

//	================="机床归零"-函数=================
//	==========================================
void CPmacCtrlDlg::OnCtrlZero() 
{
	// TODO: Add your command handler code here
	// show prompt information
	m_Info = "正在执行机床归零程序,请稍候...";
	UpdateData(FALSE);

	OpenPmacDevice(0);
	PmacFlush(0);

	// Send closeloop and return zero commands to PMAC
	char	response[20];
	UINT	maxchar = 20;
	CString	closeloop, zerocommand;
	closeloop = "p1=1";
	zerocommand = "p2=1";

	//PmacGetResponse(DWORD dwDevice,LPTSTR response,UINT maxchar,LPCTSTR command);
	//dwDevice		Device number. 
	//response		Pointer to string buffer to copy the PMAC’s response into.
	//maxchar		Maximum characters to copy. 
	//command		Pointer to NULL terminated string to be sent to the PMAC as a question/command.

	PmacGetResponse(0, response, maxchar, closeloop);		// Closeloop command
	PmacGetResponse(0, response, maxchar, zerocommand);		// Return zero command
	Sleep(5000);	//delay

	// show prompt information
	m_Info = "机床归零完成!要继续,请执行“零点偏移”!";
	UpdateData(FALSE);
}

//	================="零点偏移"-函数=================
//	==========================================
void CPmacCtrlDlg::OnCtrlExcursion() 
{
	// TODO: Add your command handler code here
	// show prompt information
	m_Info = "正在执行零点偏移程序,请稍候...";
	UpdateData(FALSE);

	OpenPmacDevice(0);
	PmacFlush(0);

	// Send zero excursion command to PMAC
	char	response[20];
	UINT	maxchar = 20;
	CString	excommand,excommand2;
	excommand = "b2";
	excommand2 = "r";
	PmacGetResponse(0, response, maxchar, excommand);
	PmacGetResponse(0, response, maxchar, excommand2);
	Sleep(5000);

	// show prompt information
	m_Info = "零点偏移完成!您可以直接“执行程序”,也可以先进行“文件下载”!";
	UpdateData(FALSE);
}

//	================="文件下载"-函数=================
//	判断当前轨迹类型,下载相应的.pmc文件到PMAC。
//	==========================================
void CPmacCtrlDlg::OnCtrlLoadfile() 
{
	// TODO: Add your command handler code here
	CString	msg, fileload;
	m_cb.GetLBText(m_cb.GetCurSel(),msg);

	// According to current track, define which file to download
	if(msg == "直线_LINE")
		fileload = FILEPMACL;
	else if(msg == "圆_CIRCLE")
		fileload = FILEPMACC;
	else
		fileload = FILEPMACH;

	// show prompt information
	UpdateData(TRUE);
	m_Info = "正在将数据文件下载到PMAC,请稍候...";
	UpdateData(FALSE);

	// Start download progress bar
	CProgressCtrl*	pProg = (CProgressCtrl*) GetDlgItem (IDC_PROGRESS);
	pProg->SetPos(0);
	SetTimer(1000,100,NULL);

	OpenPmacDevice(0);
	PmacFlush(0);
	// PmacDownload(DWORD dwDevice, DOWNLOADMSGPROC msgp, DOWNLOADGETPROC getp, DOWNLOADPROGRESS pprg, LPCTSTR filename, BOOL macro, BOOL map, BOOL log, BOOL dnld);
	// DWORD dwDevice: Device number
	// DOWNLOADMSGPROC msgp: Pointer to message procedure pointer, if NULL no function is called
	// DOWNLOADGETPROC getp: Pointer to line retrieval function, if NULL no function is called
	// DOWNLOADPROGRESS pprg: Pointer to download progress function, if NULL no function is called
	// LPCTSTR filename: Path to file to download
	// BOOL macro: Flag to parse for macros
	// BOOL map: Flag to create a map file created from macros
	// BOOL log: Flag to create a log file. This is the same messages as sent to the "msgp" procedure
	// BOOL dnld: Flag indicating to send final parsed file to PMAC
	PmacDownload (0, NULL, NULL, NULL, fileload, 1, 1, 1, 1);
}

//	================="Progress Process"===============
//	=========================================
void CPmacCtrlDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(nIDEvent == 1000)
	{
		CProgressCtrl*	pProg = (CProgressCtrl*) GetDlgItem (IDC_PROGRESS);
		pProg->SetPos(pProg->GetPos()+1);
		if(pProg->GetPos() >= 100)
		{
			KillTimer(nIDEvent);
			m_Info = "文件成功下载到PMAC!您可以“执行程序”!";
			UpdateData(FALSE);
		}
	}

	if(nIDEvent == 1001)
	{
		CTime tNow;
		tNow = CTime::GetCurrentTime();
		CString sNow = tNow.Format(" [%H : %M : %S]  %B %d-%Y  [%a]");
		m_TimeEdit.SetSel(0,-1);
		m_TimeEdit.ReplaceSel(sNow);		
	}
	CDialog::OnTimer(nIDEvent);
}

//	================="执行程序"-函数=================
//	首先下载文件到PMAC,然后执行运动程序。
//	==========================================
void CPmacCtrlDlg::OnCtrlExecute() 
{
	// TODO: Add your command handler code here
	// Download file
	CString	msg, fileload;
	m_cb.GetLBText(m_cb.GetCurSel(),msg);

	if(msg == "直线_LINE")
		fileload = FILEPMACL;
	else if(msg == "圆_CIRCLE")
		fileload = FILEPMACC;
	else
		fileload = FILEPMACH;
	
	UpdateData(TRUE);
	m_Info = "开始文件下载,请稍候...";
	UpdateData(FALSE);

	OpenPmacDevice(0);
	PmacFlush(0);
	PmacDownload (0, NULL, NULL, NULL, fileload,1,1,1,1);
	Sleep(10000);

	m_Info = "文件下载完毕,开始执行程序,请稍候...";
	UpdateData(FALSE);

	// Execute the routine
	char	response[20];
	UINT	maxchar = 20;
	CString	execommand1, execommand2;
	execommand1 = "b10";
	execommand2 = "r";
	PmacGetResponse(0, response, maxchar, execommand1);
	PmacGetResponse(0, response, maxchar, execommand2);
	Sleep(20000);

	m_Info = "程序执行完毕!";
	UpdateData(FALSE);
}

//	================"导出构型参数"-函数================
//	导出当前构型的参数至程序所在文件夹\Data\Spara.txt
//	==========================================
void CPmacCtrlDlg::OnCtrlOutputpara() 
{
	// TODO: Add your command handler code here
	// prompt path to the parameter file 
	AfxMessageBox(MSGPARA);
	char	paraEdit[10000];
	int		iStructureRADIO;
	iStructureRADIO = GetCheckedRadioButton(IDC_Structure1_RADIO,IDC_Structure5_RADIO);
	strcpy(paraEdit, "您选择的是:");
	if(iStructureRADIO == IDC_Structure1_RADIO)
	{
		strcat(paraEdit, "构型-1。\n");
		strcat(paraEdit, "---------------------------------\n");
		strcat(paraEdit, "静平台直径1485mm,距顶板底面84mm,6个铰链点的角度见图例;\n\n");
		strcat(paraEdit, "动平台直径340mm,距动平台顶面61.5mm,6个铰链点的角度见图例。\n\n");
		strcat(paraEdit, "各铰链点位置分布见图例。");
	}
	else if(iStructureRADIO == IDC_Structure2_RADIO)
	{
		strcat(paraEdit, "构型-2。\n");
		strcat(paraEdit, "---------------------------------\n");
		strcat(paraEdit, "静平台铰链点位于形心高度为357.25mm的正三角形上,距顶板底面84mm,见图例;\n\n");
		strcat(paraEdit, "动平台直径340mm,距动平台顶面61.5mm,6个铰链点的角度见图例;\n\n");
		strcat(paraEdit, "滑块中心平面的极限位置为136-350mm,见图例。");
	}
	else if(iStructureRADIO == IDC_Structure3_RADIO)
	{
		strcat(paraEdit, "构型-3。\n");
		strcat(paraEdit, "---------------------------------\n");
		strcat(paraEdit, "静平台直径1109.02mm,距顶板底面84mm,6个铰链点的角度见图例;\n\n");
		strcat(paraEdit, "动平台直径340mm,距动平台顶面61.5mm,6个铰链点的角度见图例。\n\n");
		strcat(paraEdit, "各铰链点位置分布见图例。");
	}
	else if(iStructureRADIO == IDC_Structure4_RADIO)
	{
		strcat(paraEdit, "构型-4。\n");
		strcat(paraEdit, "---------------------------------\n");
		strcat(paraEdit, "静平台直径1101mm,距顶板底面84mm,3个铰链点的角度见图例;\n\n");
		strcat(paraEdit, "动平台直径340mm,距动平台顶面61.5mm,3个铰链点的角度见图例。\n\n");
		strcat(paraEdit, "各铰链点位置分布见图例。");
	}
	else
	{
		strcat(paraEdit, "构型-5。\n");
		strcat(paraEdit, "---------------------------------\n");
		strcat(paraEdit, "静平台直径1485mm,距顶板底面84mm,6个铰链点的角度见图例;\n\n");
		strcat(paraEdit, "动平台直径340mm,距动平台顶面61.5mm,6个铰链点的角度见图例。\n\n");
		strcat(paraEdit, "各铰链点位置分布见图例。");
	}

	// Write the parameter of current structure down to the default file
	FILE	*parafp;
	parafp = fopen(BASEDIR + FILEPARA, "w+");
	if(parafp == NULL)
	{
		AfxMessageBox("保存构型参数失败!");
		return;
	}
	fputs(paraEdit, parafp);
	fclose(parafp);
}

//	==============="显示构型图例"-函数===============
//	采用mspaint或iexplore显示当前构型的图例。
//	========================================
void CPmacCtrlDlg::OnCtrlOutputphoto() 
{
	// TODO: Add your command handler code here
	CString	illuA, illuB, illuC, illuD, illuE;
	CString	struA, struB, struC, struD, struE;

	// Show illustration by mspaint
/*	illuA = "C:\\WINDOWS\\system32\\mspaint.exe " + BASEDIR + "\\Illustration\\IllustrationA.jpg";
	illuB = "C:\\WINDOWS\\system32\\mspaint.exe " + BASEDIR + "\\Illustration\\IllustrationB.jpg";
	illuC = "C:\\WINDOWS\\system32\\mspaint.exe " + BASEDIR + "\\Illustration\\IllustrationC.jpg";
	illuD = "C:\\WINDOWS\\system32\\mspaint.exe " + BASEDIR + "\\Illustration\\IllustrationD.jpg";
	illuE = "C:\\WINDOWS\\system32\\mspaint.exe " + BASEDIR + "\\Illustration\\IllustrationE.jpg";
*/
	// Show illustration by iexplore
	illuA = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE " + BASEDIR + "\\Illustration\\IllustrationA.jpg";
	illuB = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE " + BASEDIR + "\\Illustration\\IllustrationB.jpg";
	illuC = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE " + BASEDIR + "\\Illustration\\IllustrationC.jpg";
	illuD = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE " + BASEDIR + "\\Illustration\\IllustrationD.jpg";
	illuE = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE " + BASEDIR + "\\Illustration\\IllustrationE.jpg";

	// Show illustration by iexplore
	struA = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE " + BASEDIR + "\\Illustration\\StructureA.jpg";
	struB = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE " + BASEDIR + "\\Illustration\\StructureB.jpg";
	struC = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE " + BASEDIR + "\\Illustration\\StructureC.jpg";
	struD = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE " + BASEDIR + "\\Illustration\\StructureD.jpg";
	struE = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE " + BASEDIR + "\\Illustration\\StructureE.jpg";

	// Call WinExec() function to show illustration
	UpdateData(TRUE);
	if(m_Structure == 0)
	{
//		WinExec(illuA,SW_MAXIMIZE);
		WinExec(illuA,SW_SHOW);
		WinExec(struA,SW_SHOW);
	}
	else if(m_Structure == 1)
	{
//		WinExec(illuB,SW_MAXIMIZE);
		WinExec(illuB,SW_SHOW);
		WinExec(struB,SW_SHOW);
	}
	else if(m_Structure == 2)
	{
//		WinExec(illuC,SW_MAXIMIZE);
		WinExec(illuC,SW_SHOW);
		WinExec(struC,SW_SHOW);
	}
	else if(m_Structure == 3)
	{
//		WinExec(illuD,SW_MAXIMIZE);
		WinExec(illuD,SW_SHOW);
		WinExec(struD,SW_SHOW);
	}
	else
	{
//		WinExec(illuE,SW_MAXIMIZE);
		WinExec(illuE,SW_SHOW);
		WinExec(struE,SW_SHOW);
	}
}

//	==============="查看插补数据"-函数===============

⌨️ 快捷键说明

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