📄 movedlg.cpp
字号:
// moveDlg.cpp : implementation file
//
#include<windows.h>
#include<stdio.h>
#include "stdafx.h"
#include "move.h"
#include "moveDlg.h"
#include"AdControll.h"
#include"DMC1000.H"
#include"Piso813.h"
//定义二轴的常量
const int XCH = 0;
const int ZCH = 1;
//int nAxis;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
ColScan();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
////////////////////////////////////////////////////////////////////////
//delay for scanning the image
void DelayTask(unsigned long iTimeInMilliSeconds)
{
unsigned long i,j;
for(i=0;i<iTimeInMilliSeconds;i++)
{
for(j=0;j<22000;j++);
}
return;
}
////////////////////////////////////////////////////////////////////////
void delay(unsigned long timems)
{
DWORD dwStart = GetTickCount();
DWORD dwEnd = dwStart;
do
{
MSG msg;
GetMessage(&msg,NULL,0,0);
TranslateMessage(&msg);
DispatchMessage(&msg);
dwEnd = GetTickCount()-dwStart;
}while(dwEnd<timems);
}
void ScanX(int Col,int ScanS,int ScanT,long Xstart,long Xspeed,double tacc)
{
int i;
// int changdir=-1;
for(i=0;i<Col;i++)
{
Sleep(ScanT);
d1000_start_s_move(XCH,ScanS,Xstart,Xspeed,tacc);
while(d1000_check_done(XCH));
// Sleep(ScanT);
// d1000_start_s_move(XCH,ScanS*changdir,Xstart,Xspeed,tacc);
}
}
/////////////////////////////////////////////////////////////////////////////
// CMoveDlg dialog
CMoveDlg::CMoveDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMoveDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMoveDlg)
m_CheckX = FALSE;
m_CHECKZ = FALSE;
m_ScanS = 0;
m_ScanT = 0;
m_Xspeed = 0;
m_Xstart = 0;
m_Zspeed = 0;
m_Zstart = 0;
m_ScanCOL = 0;
m_ScanLN = 0;
m_Dir = FALSE;
m_AdResult = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMoveDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMoveDlg)
DDX_Control(pDX, IDC_SetP, m_SetP);
DDX_Control(pDX, IDC_SetN, m_SetN);
DDX_Control(pDX, IDC_Stop, m_Stop);
DDX_Control(pDX, IDC_Start, m_Start);
DDX_Check(pDX, IDC_CheckX, m_CheckX);
DDX_Check(pDX, IDC_CHECKZ, m_CHECKZ);
DDX_Text(pDX, IDC_ScanS, m_ScanS);
DDX_Text(pDX, IDC_ScanT, m_ScanT);
DDX_Text(pDX, IDC_Xspeed, m_Xspeed);
DDX_Text(pDX, IDC_Xstart, m_Xstart);
DDX_Text(pDX, IDC_Zspeed, m_Zspeed);
DDX_Text(pDX, IDC_Zstart, m_Zstart);
DDX_Text(pDX, IDC_ScanCOL, m_ScanCOL);
DDX_Text(pDX, IDC_ScanLN, m_ScanLN);
DDX_Check(pDX, IDC_DIR, m_Dir);
DDX_Text(pDX, IDC_EDIT1, m_AdResult);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMoveDlg, CDialog)
//{{AFX_MSG_MAP(CMoveDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_Start, OnStart)
ON_BN_CLICKED(IDC_SetP, OnSetP)
ON_BN_CLICKED(IDC_SetN, OnSetN)
ON_BN_CLICKED(IDC_DIR, OnDir)
ON_BN_CLICKED(IDC_CheckX, OnCheckX)
ON_BN_CLICKED(IDC_CHECKZ, OnCheckz)
ON_BN_CLICKED(IDC_Stop, OnStop)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMoveDlg message handlers
BOOL CMoveDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
d1000_board_init();
d1000_set_pls_outmode(XCH,1);
// d1000_set_pls_outmode(ZCH,1);
// SetTimer( IDC_TIMER, 100, NULL );
return TRUE; // return TRUE unless you set the focus to a control
}
void CMoveDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CMoveDlg::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 CMoveDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMoveDlg::OnStart()
{//开始扫描
// TODO: Add your control notification handler code here
double tacc=0.1;
int nDir=1;
int ChanDir=-1;
int j;
UpdateData(TRUE);
if(m_Dir==TRUE)
{nDir=-1;}
else
{nDir=1;}
m_ScanS=m_ScanS*nDir*100;
m_Xstart=m_Xstart*100;
m_Xspeed=m_Xspeed*100;
m_Zstart=m_Zstart*100;
m_Zspeed=m_Zspeed*100;
Sleep(m_ScanT);
ScanX(m_ScanCOL,m_ScanS,m_ScanT,m_Xstart,m_Xspeed,tacc);
Sleep(m_ScanT);
for(j=0;j<m_ScanLN-1;j++)
{
Sleep(m_ScanT);
d1000_start_s_move(ZCH,m_ScanS*ChanDir,m_Zstart,m_Zspeed,tacc);
Sleep(m_ScanT);
Sleep(m_ScanT);
if(j%2==0)
{
ScanX(m_ScanCOL,m_ScanS*ChanDir,m_ScanT,m_Xstart,m_Xspeed,tacc);
Sleep(m_ScanT);
Sleep(m_ScanT);
}
else{
ScanX(m_ScanCOL,m_ScanS,m_ScanT,m_Xstart,m_Xspeed,tacc);
Sleep(m_ScanT);
Sleep(m_ScanT);
}
}
}
void CMoveDlg::OnSetP()
{
// TODO: Add your control notification handler code here
double tacc=0.1;
int dir=-1;
UpdateData(TRUE);
if(m_CheckX==TRUE)
{
d1000_start_s_move(XCH,400*dir,400,400,tacc);
while(d1000_check_done(XCH));
}
else if(m_CHECKZ==TRUE)
{
d1000_start_s_move(ZCH,400*dir,400,400,tacc);
while(d1000_check_done(ZCH));
}
}
void CMoveDlg::OnSetN()
{
// TODO: Add your control notification handler code here
int dir=1;
double tacc=0.1;
UpdateData(TRUE);
if(m_CheckX==TRUE)
{
d1000_start_s_move(XCH,400*dir,400*dir,400*dir,tacc);
while(d1000_check_done(XCH));
}
else if(m_CHECKZ==TRUE)
{
d1000_start_s_move(ZCH,400*dir,400*dir,400*dir,tacc);
while(d1000_check_done(ZCH));
}
}
void CMoveDlg::OnDir()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_Dir=TRUE;
UpdateData(TRUE);
}
void CMoveDlg::OnCheckX()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_CheckX=TRUE;
}
void CMoveDlg::OnCheckz()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_CHECKZ=TRUE;
}
void CMoveDlg::OnStop()
{
// TODO: Add your control notification handler code here
d1000_decel_stop(XCH);
d1000_decel_stop(ZCH);
}
void CMoveDlg::OnDestroy()
{
d1000_board_close(); //关闭控制卡(此句一定要有)
CDialog::OnDestroy();
// TODO: Add your message handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -