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

📄 motordlgpower.cpp

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

#include "stdafx.h"
#include "TestForm.h"
#include "MotorDlgPower.h"

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

/////////////////////////////////////////////////////////////////////////////
// MotorDlgPower dialog


MotorDlgPower::MotorDlgPower(CWnd* pParent /*=NULL*/)
	: CDialog(MotorDlgPower::IDD, pParent)
{
	//{{AFX_DATA_INIT(MotorDlgPower)
	m_dModlgpowSpeed = 320.0;
	//}}AFX_DATA_INIT
	m_nModlgpowPs = 0;
	m_nModlgpowPt = 0;
	m_nModlgpowPti = 0;
	m_bSelfchekflag =FALSE;//设备自检未完成
}


void MotorDlgPower::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(MotorDlgPower)
	DDX_Control(pDX, IDC_RAMODLGPOW_PTI, m_cModlgpowPti);
	DDX_Control(pDX, IDC_RAMODLGPOW_PT, m_cModlgpowPt);
	DDX_Control(pDX, IDC_RAMODLGPOW_PS, m_cModlgpowPs);
	DDX_Control(pDX, IDC_COMODLGPOW_DIRECT, m_cModlgpowDirect);
	DDX_Text(pDX, IDC_EDMODLGPOW_SPEED, m_dModlgpowSpeed);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(MotorDlgPower, CDialog)
	//{{AFX_MSG_MAP(MotorDlgPower)
	ON_BN_CLICKED(IDC_BUMODLGPOW_INIT, OnBumodlgpowInit)
	ON_BN_CLICKED(IDC_BUMODLGPOW_START, OnBumodlgpowStart)
	ON_BN_CLICKED(IDC_BUMODLGPOW_STOP, OnBumodlgpowStop)
	ON_BN_CLICKED(IDC_BUMODLGPOW_FINISH, OnBumodlgpowFinish)
	ON_MESSAGE(WM_OPENDATA,OnOpendata)
	ON_BN_CLICKED(IDC_RAMODLGPOW_PS, OnRamodlgpowPs)
	ON_BN_CLICKED(IDC_RAMODLGPOW_PT, OnRamodlgpowPt)
	ON_BN_CLICKED(IDC_RAMODLGPOW_PTI, OnRamodlgpowPti)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// MotorDlgPower message handlers

///////////////////////////
BOOL MotorDlgPower::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here	
	m_cModlgpowPti.SetCheck(1);//显示曲线为效率-时间曲线
	m_cModlgpowDirect.SetCurSel(0);//初始化为正转
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

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

//开始试验
void MotorDlgPower::OnBumodlgpowStart() 
{
	// TODO: Add your control notification handler code here
	//读取控制面板参数
	UpdateData(TRUE);
	if (m_bSelfchekflag)
	{
		
	int radionumber;
	CTestFormApp *pApp=(CTestFormApp *)AfxGetApp();

	motorpowerDlg.m_dMotorSpeed = m_dModlgpowSpeed;
	motorpowerDlg.m_dMotorTangle = 10;
	motorpowerDlg.m_nMotorDirectTem=m_cModlgpowDirect.GetCurSel();
	
	//获取Radio Button 状态
	m_nModlgpowPti = m_cModlgpowPti.GetCheck();
	m_nModlgpowPt = m_cModlgpowPt.GetCheck();
	m_nModlgpowPs = m_cModlgpowPs.GetCheck();
	if (m_nModlgpowPti==1)
	// 	MessageBox("1");
		radionumber=1;
	if (m_nModlgpowPs==1)
	//	MessageBox("2");
		radionumber=2;
	if (m_nModlgpowPt==1)
	//	MessageBox("3");
		radionumber=3;
	//MessageBox("3");
	//给绘图窗口发送消息
	pApp->pCTestFormView->powerDrawDlg.PostMessage(WM_MOTDLGPORSTART_HIT,radionumber,1);
	//给效率仪控制窗口发送消息
	pApp->pPeDialogBase->powerDlg.PostMessage(WM_MOTDLGPORSTART_HIT,0,0);
	// 	MessageBox("3");
	motorpowerDlg.MotorRun();
	}
	else
		MessageBox("请先设备自检和效率仪的串口设置操作!");
	
}

//中止试验
void MotorDlgPower::OnBumodlgpowStop() 
{
	// TODO: Add your control notification handler code here
	motorpowerDlg.MotorStop();
	
}

//完成试验
void MotorDlgPower::OnBumodlgpowFinish() 
{
	// TODO: Add your control notification handler code here
	motorpowerDlg.MotorStop();
}

//打开数据响应函数
void MotorDlgPower::OnOpendata(WPARAM wParam, LPARAM lParam)
{
	// TODO: Add your control notification handler code here
	//MessageBox("123");
	CTestFormApp *pApp=(CTestFormApp *)AfxGetApp();
	m_dModlgpowSpeed=pApp->pCTestFormDoc->motorRate;	//获得转速
	int direct=pApp->pCTestFormDoc->motorDirect;		//获得转向
	if(direct==-1)
		m_cModlgpowDirect.SetCurSel(1);		//初始化为反转
	else
		m_cModlgpowDirect.SetCurSel(0);		//初始化为正转
	UpdateData(FALSE);		//更新主控窗口中的显示

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

//选择试验件输出转速-时间曲线
void MotorDlgPower::OnRamodlgpowPs() 
{
	// TODO: Add your control notification handler code here
	CTestFormApp *pApp=(CTestFormApp *)AfxGetApp();
	//曲线类型为2
	pApp->pCTestFormView->powerDrawDlg.SendMessage(WM_DRAWTYPE_SELECT,2,0);
}

//选择试验件输出端所受扭矩-时间曲线
void MotorDlgPower::OnRamodlgpowPt() 
{
	// TODO: Add your control notification handler code here
	CTestFormApp *pApp=(CTestFormApp *)AfxGetApp();
	//曲线类型为3
	pApp->pCTestFormView->powerDrawDlg.SendMessage(WM_DRAWTYPE_SELECT,3,0);
}

//选择试验件效率-时间曲线
void MotorDlgPower::OnRamodlgpowPti() 
{
	// TODO: Add your control notification handler code here
	CTestFormApp *pApp=(CTestFormApp *)AfxGetApp();
	//曲线类型为1
	pApp->pCTestFormView->powerDrawDlg.SendMessage(WM_DRAWTYPE_SELECT,1,0);
}

⌨️ 快捷键说明

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