📄 illustra03dlg.cpp
字号:
// illustra03Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "illustra03.h"
#include "illustra03Dlg.h"
#include"dmc2000.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int AxisNo ;
/////////////////////////////////////////////////////////////////////////////
// CIllustra03Dlg dialog
void DoEvents(void);
CIllustra03Dlg::CIllustra03Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CIllustra03Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CIllustra03Dlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CIllustra03Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CIllustra03Dlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CIllustra03Dlg, CDialog)
//{{AFX_MSG_MAP(CIllustra03Dlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_STARTING, OnStarting)
ON_BN_CLICKED(IDC_STOP, OnStop)
ON_BN_CLICKED(IDC_CLEARPOS, OnClearpos)
ON_EN_CHANGE(IDC_AXISNO, OnChangeAxisno)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CIllustra03Dlg message handlers
BOOL CIllustra03Dlg::OnInitDialog()
{
char O_String[64];
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
sprintf(O_String,"%ld",1000);
SetDlgItemText(IDC_DISTANCE,O_String);
sprintf(O_String,"%ld",100);
SetDlgItemText(IDC_LOWSPEED,O_String);
sprintf(O_String,"%ld",3000);
SetDlgItemText(IDC_HIGHSPEED,O_String);
sprintf(O_String,"%1.1f",0.1);
SetDlgItemText(IDC_ACCTIME,O_String);
sprintf(O_String,"%d",0);
SetDlgItemText(IDC_AXISNO,O_String);
Board_init(); //初始化控制卡
AxisNo=0;
SetTimer(1,60,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CIllustra03Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CIllustra03Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CIllustra03Dlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
char t_string[64];
double t_pos ;
long t_iostatus;
//if(Cout<10000)Cout++;
//else Cout=0;
t_pos=Get_position(AxisNo);
sprintf(t_string,"%ld",(long)(t_pos));
SetDlgItemText(IDC_CURRPOS,t_string);
t_iostatus=Get_io_status(AxisNo);
sprintf(t_string,"0x%x",t_iostatus);
SetDlgItemText(IDC_IOSTATUS,t_string);
CDialog::OnTimer(nIDEvent);
}
void CIllustra03Dlg::OnCancel()
{
// TODO: Add extra cleanup here
int i ;
KillTimer(1);
for(i=0;i<4;i++)Board_close(0);
CDialog::OnCancel();
}
void CIllustra03Dlg::OnStarting()
{
// TODO: Add your control notification handler code here
double lowspeed ,highspeed , taccel ;
double distance ;
char c_string[64];
//CIllustrate1Dlg dlg;
//distance = m_Distance;
//lowspeed = m_LowSpeed;
GetDlgItemText(IDC_AXISNO,c_string,8);
AxisNo=atoi(c_string);
GetDlgItemText(IDC_DISTANCE,c_string,8);
distance=atol(c_string);
GetDlgItemText(IDC_LOWSPEED,c_string,8);
lowspeed=atol(c_string);
GetDlgItemText(IDC_HIGHSPEED,c_string,8);
highspeed=atol(c_string);
GetDlgItemText(IDC_ACCTIME,c_string,8);
taccel=atof(c_string);
Start_r_move(AxisNo,distance,lowspeed,highspeed,taccel);
while(Motion_done(AxisNo)==0)DoEvents();
}
void CIllustra03Dlg::OnStop()
{
// TODO: Add your control notification handler code here
Decel_stop(AxisNo,0.1);
}
void CIllustra03Dlg::OnClearpos()
{
// TODO: Add your control notification handler code here
Set_position(AxisNo,0);
}
void DoEvents(void)
{
MSG message;
while( :: PeekMessage(&message,NULL,0,0,PM_REMOVE) )
{
::TranslateMessage(&message);
::DispatchMessage(&message);
}
}
void CIllustra03Dlg::OnChangeAxisno()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
char c_string[64];
// TODO: Add your control notification handler code here
GetDlgItemText(IDC_AXISNO,c_string,8);
AxisNo=atoi(c_string);
if(AxisNo>3||AxisNo<0)AxisNo=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -