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

📄 motordlgresp.cpp

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

#include "stdafx.h"
#include "TestForm.h"
#include "MotorDlgResp.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// MotorDlgResp dialog


MotorDlgResp::MotorDlgResp(CWnd* pParent /*=NULL*/)
	: CDialog(MotorDlgResp::IDD, pParent)
{
	//{{AFX_DATA_INIT(MotorDlgResp)
	m_dModlgresSpeed = 100.0;
	//}}AFX_DATA_INIT
	/*布尔变量初始化*/
	m_bSelfchekflag =FALSE;//设备自检未完成
}


void MotorDlgResp::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(MotorDlgResp)
	DDX_Control(pDX, IDC_COMODLGRES_RISET, m_cModlgresRiset);
	DDX_Control(pDX, IDC_COMODLGRES_STABLE, m_cModlgresStable);
	DDX_Control(pDX, IDC_COMODLGRES_RISEF, m_cModlgresRisef);
	DDX_Control(pDX, IDC_COMODLGRES_DIRECT, m_cModlgresDirect);
	DDX_Text(pDX, IDC_EDMODLGRES_SPEED, m_dModlgresSpeed);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(MotorDlgResp, CDialog)
	//{{AFX_MSG_MAP(MotorDlgResp)
	ON_BN_CLICKED(IDC_BUMODLGRES_INIT, OnBumodlgresInit)
	ON_BN_CLICKED(IDC_BUMODLGRES_START, OnBumodlgresStart)
	ON_BN_CLICKED(IDC_BUMODLGRES_STOP, OnBumodlgresStop)
	ON_BN_CLICKED(IDC_BUMODLGRES_FINISH, OnBumodlgresFinish)
	ON_MESSAGE(WM_OPENDATA,OnOpendata)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// MotorDlgResp message handlers

BOOL MotorDlgResp::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_cModlgresDirect.SetCurSel(0);//电机转向为正转
	m_cModlgresRisef.SetCurSel(0);//待测值(电机转速)上升起点
	m_cModlgresRiset.SetCurSel(0);//待测值(电机转速)上升终点
	m_cModlgresStable.SetCurSel(0);//待测值(电机转速)稳定值范围
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

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

//开始试验
void MotorDlgResp::OnBumodlgresStart() 
{
	// TODO: Add your control notification handler code here
	//用于存放试验设置中三个设置值的选择状态
	int risef,riset,stable,rate;
	//用于存放试验设置中三个设置值拼接后的字符串
	CString addthree;

	CString str1,str2,str3;
	//读取控制面板参数
	UpdateData(TRUE);
	if (m_bSelfchekflag)
	{	
	 	CTestFormApp *pApp=(CTestFormApp *)AfxGetApp();

		motorresDlg.m_bMotorVmove = TRUE;//电机运动类型为连续运动
		motorresDlg.m_dMotorSpeed = m_dModlgresSpeed;//电机运动速度		
		motorresDlg.m_nMotorDirectTem=m_cModlgresDirect.GetCurSel();//电机运动方向

		long speed =(long)m_dModlgresSpeed;//数据转换,以便在消息中传递
		//获取过度过程试验的各个设置值		
		risef=m_cModlgresRisef.GetCurSel();//待测值(电机转速)上升起点
		riset=m_cModlgresRiset.GetCurSel();//待测值(电机转速)上升终点
		stable=m_cModlgresStable.GetCurSel();//待测值(电机转速)稳定值范围

		str1.Format("%d",risef);
		str2.Format("%d",riset);
		str3.Format("%d",stable);
		
		//拼接字符串
		addthree=str1+str2+str3;		
		if (addthree=="000")
		{
			rate=0x000;		
		}
		else if (addthree=="001")
		{
			rate=0x001;
		}
		else if (addthree=="010")
		{
			rate=0x010;
		}
		else if (addthree=="011")
		{
			rate=0x011;
		}
		else if (addthree=="100")
		{
			rate=0x100;
		}
		else if (addthree=="101")
		{
			rate=0x101;
		}
		else if (addthree=="110")
		{
			rate=0x110;
		}
		else if (addthree=="111")
		{
			rate=0x111;
		}
		else
		{
			rate=0x200;
		}

	//发送消息给效率仪控制窗口
	pApp->pPeDialogBase->powerDlg.PostMessage(WM_MOTDLGRESPSTART_HIT,rate,speed);
	//发送消息给绘图窗口
	pApp->pCTestFormView->respDrawDlg.PostMessage(WM_MOTDLGRESPSTART_HIT,rate,0);
		motorresDlg.MotorRun();
	//MessageBox("3");
	}
	else
	MessageBox("请先进行设备自检和效率仪的串口设置操作!");	
}

//暂停试验
void MotorDlgResp::OnBumodlgresStop() 
{
	// TODO: Add your control notification handler code here
	//停止电机
	motorresDlg.MotorStop();
}

//完成试验
void MotorDlgResp::OnBumodlgresFinish() 
{
	// TODO: Add your control notification handler code here
	//停止电机
	motorresDlg.MotorStop();
}

//打开数据响应函数
void MotorDlgResp::OnOpendata(WPARAM wParam, LPARAM lParam)
{
	// TODO: Add your control notification handler code here
	//MessageBox("123");
	CTestFormApp *pApp=(CTestFormApp *)AfxGetApp();	 
	int riseup = (int)wParam;		//上升时间上限
	int risedown = (int)lParam;		//上升时间上限
	int stable = pApp->pCTestFormDoc->nTotalCoderNumber;//上升时间上限
	m_dModlgresSpeed=pApp->pCTestFormDoc->motorRate;	//获得转速
	int direct=pApp->pCTestFormDoc->motorDirect;		//获得转向
	if(direct==-1)
		m_cModlgresDirect.SetCurSel(1);		//电机反转
	else
		m_cModlgresDirect.SetCurSel(0);		//电机正转
	if (riseup==1)
	{
		m_cModlgresRisef.SetCurSel(1); //上升时间上限为10%
	}
	else
			m_cModlgresRisef.SetCurSel(0); //上升时间上限为0%
	if (risedown==1)
	{
		m_cModlgresRiset.SetCurSel(1); //上升时间下限为90%
	}
	else
			m_cModlgresRiset.SetCurSel(0); //上升时间下限为100%
	if (stable==1)
	{
		m_cModlgresStable.SetCurSel(1); //上升时间下限为4%
	}
	else
			m_cModlgresStable.SetCurSel(0); //上升时间下限为10%

	UpdateData(FALSE);		//更新主控窗口中的显示

	//OnBumodlgpowInit();
	//OnBumodlgpowStart(); 
}

⌨️ 快捷键说明

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