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

📄 motordlgblanke.cpp

📁 一个用于无刷直流电动机的驱动与控制程序.里面所用的采集卡的型号为MC08.
💻 CPP
字号:
// MotorDlgBlanke.cpp : implementation file
//

#include "stdafx.h"
#include "TestForm.h"
#include "MotorDlgBlanke.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// MotorDlgBlanke dialog
MotorDlgBlanke::MotorDlgBlanke(CWnd* pParent /*=NULL*/)
	: CDialog(MotorDlgBlanke::IDD, pParent)
{
	//{{AFX_DATA_INIT(MotorDlgBlanke)
	m_dModlgblnNtangle = 0.0;
	m_dModlgblnPtangle = 0.0;
	m_dModlgblnSpeed = 100.0;
	//}}AFX_DATA_INIT
	m_bSelfchekflag =FALSE;//设备自检未完成
}


void MotorDlgBlanke::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(MotorDlgBlanke)
	DDX_Control(pDX, IDC_COMODLGBLN_DIRECT, m_cModlgblnDirect);
	DDX_Text(pDX, IDC_EDMODLGBLN_NTANGLE, m_dModlgblnNtangle);
	DDX_Text(pDX, IDC_EDMODLGBLN_PTANGLE, m_dModlgblnPtangle);
	DDX_Text(pDX, IDC_EDMODLGBLN_SPEED, m_dModlgblnSpeed);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(MotorDlgBlanke, CDialog)
	//{{AFX_MSG_MAP(MotorDlgBlanke)
	ON_BN_CLICKED(IDC_BUMODLGBLN_INIT, OnBumodlgblnInit)
	ON_BN_CLICKED(IDC_BUMODLGBLN_START, OnBumodlgblnStart)
	ON_BN_CLICKED(IDC_BUMODLGBLN_STOP, OnBumodlgblnStop)
	ON_BN_CLICKED(IDC_BUMODLGBLN_FINISH, OnBumodlgblnFinish)
	ON_MESSAGE(WM_OPENDATA,OnOpendata)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// MotorDlgBlanke message handlers

//////////////////////////////
BOOL MotorDlgBlanke::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_cModlgblnDirect.SetCurSel(0);//初始化为正转
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

//设备自检
void MotorDlgBlanke::OnBumodlgblnInit() 
{
	// TODO: Add your control notification handler code here
	motorblnkDlg.initBoard();
	m_bSelfchekflag =TRUE;//设备自检完成
	
}

//开始试验
void MotorDlgBlanke::OnBumodlgblnStart() 
{
	// TODO: Add your control notification handler code here
	if (m_bSelfchekflag)
	{
		CTestFormApp *pApp=(CTestFormApp *)AfxGetApp();

		motorblnkDlg.m_dMotorSpeed = m_dModlgblnSpeed;
		motorblnkDlg.m_dMotorTangle = 10;
		motorblnkDlg.m_nMotorDirectTem=m_cModlgblnDirect.GetCurSel();

		//向画图窗口发送消息
		pApp->pCTestFormView->blankeDrawDlg.PostMessage(WM_MOTDLGBLANSTART_HIT,0,0);
		motorblnkDlg.MotorRun();
	}
	else
		MessageBox("请先进行设备自检和编码器的串口设置操作!");	
}

//中止试验
void MotorDlgBlanke::OnBumodlgblnStop() 
{
	// TODO: Add your control notification handler code here
	motorblnkDlg.MotorStop();
}

//完成试验
void MotorDlgBlanke::OnBumodlgblnFinish() 
{
	// TODO: Add your control notification handler code here
	motorblnkDlg.MotorStop();
}

//打开数据响应函数
void MotorDlgBlanke::OnOpendata(WPARAM wParam, LPARAM lParam)
{
	// TODO: Add your control notification handler code here
	//MessageBox("123");
	CTestFormApp *pApp=(CTestFormApp *)AfxGetApp();
	m_dModlgblnSpeed=pApp->pCTestFormDoc->motorRate;	//获得电机转速
	int direct=pApp->pCTestFormDoc->motorDirect;		//获得转向
	if(direct==-1)
		m_cModlgblnDirect.SetCurSel(1);		//初始化为反转
	else
		m_cModlgblnDirect.SetCurSel(0);		//初始化为正转	

	m_dModlgblnNtangle = pApp->pCTestFormDoc->motorCTangle;
	m_dModlgblnPtangle = pApp->pCTestFormDoc->motorTangle;	
	UpdateData(FALSE);		//更新主控窗口中的显示	
}

⌨️ 快捷键说明

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