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

📄 formset.cpp

📁 电机加速曲线生成器VC源程序,为从事或学习VC的朋友提供方便,同时该电机加速曲线生成器也是从事电机控制的朋友不可或缺的开发利器.
💻 CPP
字号:
// FormSet.cpp : implementation file
//

#include "stdafx.h"
#include "MotorCtrlDoc.h"
#include "MotorCtrl.h"
#include "FormSet.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFormSet

IMPLEMENT_DYNCREATE(CFormSet, CFormView)

CFormSet::CFormSet()
	: CFormView(CFormSet::IDD)
{
	//{{AFX_DATA_INIT(CFormSet)
	m_BeginF = 500.0f;
	m_A = 1.0f;
	m_nSteps = 100;
	m_nOsc   = 921500;
	//}}AFX_DATA_INIT
}

CFormSet::~CFormSet()
{
}

void CFormSet::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFormSet)
	DDX_Text(pDX, IDC_EDIT_BEGIN, m_BeginF);
	DDX_Text(pDX, IDC_EDIT_ACCESS, m_A);
	DDX_Text(pDX, IDC_EDIT_STEP, m_nSteps);
	DDX_Text(pDX, IDC_EDIT_OSC, m_nOsc);
	DDV_MinMaxInt(pDX, m_nSteps, 1, 10000);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFormSet, CFormView)
	//{{AFX_MSG_MAP(CFormSet)
	ON_COMMAND(ID_MENU_VIEW_FQ, ViewFQ)
	ON_COMMAND(ID_MENU_TIMER,MkTimerVal)
	ON_COMMAND(ID_BTN_TIMER,MkTimerVal)
	ON_COMMAND(ID_BTN_FQ,ViewFQ)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFormSet diagnostics

#ifdef _DEBUG
void CFormSet::AssertValid() const
{
	CFormView::AssertValid();
}

void CFormSet::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
CMotorCtrlDoc* CFormSet::GetDocument()
{
    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMotorCtrlDoc)));
	return (CMotorCtrlDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CFormSet message handlers

void CFormSet::ViewFQ() 
{
	UpdateData(TRUE);
	
	CMotorCtrlDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
    
	pDoc->m_A      = m_A;
	pDoc->m_nSteps = m_nSteps;
	pDoc->m_BeginF = m_BeginF;
    pDoc->UpdateAllViews(NULL); 
	
}
void CFormSet::MkTimerVal() 
{
int nRet,i; 
UINT TimerVal;

    ViewFQ( );
	CMotorCtrlDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	
	CFileDialog SaveDlg(FALSE,"数据另存为");

	nRet = SaveDlg.DoModal();
	if(nRet==IDCANCEL) return;
	//t= 65535-(921500./y);	
	FILE *fstr;
	if( (fstr = fopen( (LPCTSTR)SaveDlg.GetFileName(), "w+" )) == NULL ){
		MessageBox( "创建文件失败" );
		return;
    }	
	
    fprintf(fstr,"/*\n起步频率[%f],加速系数[%f],加速步数[%d],晶振频率[%u]\n",
		      m_BeginF,m_A,m_nSteps ,m_nOsc); 

	for(i=0;i<pDoc->m_FqArray.GetSize();i++){
		if ( i%10 == 0) fprintf(fstr,"\n");				
		fprintf(fstr,"%5.5d  ",pDoc->m_FqArray[i]);		
    }
    
	fprintf(fstr,"%5.5d  ",pDoc->m_FqArray[i-1]);//加上一步
    fprintf(fstr,"\n*/\n");
    //定时器初值给脉冲方式
    fprintf(fstr,"//定时器初值给脉冲方式(这里默认是16位定时器)\n");
	fprintf(fstr,"TimerVal[]=\n{");
    for(i=0;i<pDoc->m_FqArray.GetSize();i++){
		if ( i%10 == 0) fprintf(fstr,"\n");		
		TimerVal = (UINT)65535-(m_nOsc / pDoc->m_FqArray[i]);
	    fprintf(fstr,"0x%X, ",TimerVal);		
		
    } 
    fprintf(fstr,"0x%X",TimerVal); //加上一步
	fprintf(fstr,"\n};");
	//延时给脉冲方式
    fprintf(fstr,"\n//延时(us)给脉冲方式\n");
	fprintf(fstr,"DelayVal[]=\n{");
    for(i=0;i<pDoc->m_FqArray.GetSize();i++){
		if ( i%10 == 0) fprintf(fstr,"\n");		
		TimerVal = (1 /(float) pDoc->m_FqArray[i]) * 1000000 ;
		fprintf(fstr,"%4.4d, ",TimerVal);		
		
    } 
    fprintf(fstr,"%4.4d",TimerVal); //加上一步
	fprintf(fstr,"\n};");


	fclose(fstr);
	ShellExecute(NULL,"open",(LPCTSTR)SaveDlg.GetFileName(), 
		NULL, NULL,	SW_SHOW	);	
	

}


⌨️ 快捷键说明

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