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

📄 demo11dlg.cpp

📁 一个运动控制卡的例程,编辑后就可以运行.
💻 CPP
字号:
// demo11Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "demo11.h"
#include "demo11Dlg.h"
#include "adt850.h"
#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();

// 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()

/////////////////////////////////////////////////////////////////////////////
// CDemo11Dlg dialog

CDemo11Dlg::CDemo11Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDemo11Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDemo11Dlg)
	m_pos = _T("");
	m_pos1 = _T("");
	m_pos2 = _T("");
	m_speed = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDemo11Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDemo11Dlg)
	DDX_Text(pDX, IDC_LOG_POS, m_pos);
	DDX_Text(pDX, IDC_LOG_POS1, m_pos1);
	DDX_Text(pDX, IDC_LOG_POS2, m_pos2);
	DDX_Text(pDX, IDC_DRIVER_SPEED, m_speed);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDemo11Dlg, CDialog)
	//{{AFX_MSG_MAP(CDemo11Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_STOP_IM, OnStopIm)
	ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDemo11Dlg message handlers

BOOL CDemo11Dlg::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
	cardno = adt850_initial();
    Chk = true;
    if(cardno <= 0){               //未安装ADT850卡
        MessageBox("未安装850卡!");
			return FALSE;}
    
  cardno = 0;                          //可修改卡号,操作其他卡

    for(axis=1;axis<5;axis++)
	{
		set_command_pos(cardno, axis, 0);
		set_pulse_mode(cardno, axis, 1, 0, 0);//设置X轴为脉冲+方向方式
	}
    set_ad_mode (cardno, 1, 0);
    set_dec1_mode (cardno, 1, 0);
    set_dec2_mode (cardno, 1, 0);
    set_range (cardno, 1, 8000000);//设置X倍率为1
    set_range (cardno, 3, 8000000);//设置Z倍率与X倍率相同
    set_startv (cardno, 1, 1000);//X起始速度  1000
    set_speed (cardno, 1, 8000);//X驱动速度  8000
    set_startv (cardno, 3, 8000 );//Z起始速度同X驱动速度
    set_speed (cardno, 3, 8000);//Z驱动速度同X驱动速度
    set_acc (cardno, 1, 100);

    inp_dec_enable (cardno, 1);//插补减速允许


	SetTimer(1,100,NULL);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CDemo11Dlg::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 CDemo11Dlg::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 CDemo11Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CDemo11Dlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	long Pos,Speed;

    get_command_pos(cardno, 1, &Pos);
    m_pos.Format("%d",Pos);

     
    get_command_pos(cardno, 2, &Pos);
    m_pos1.Format("%d",Pos);

    
    get_command_pos(cardno, 3, &Pos);
    m_pos2.Format("%d",Pos);

	get_speed(cardno, 1, &Speed);
    m_speed.Format("%d",Speed);
	UpdateData(FALSE);
	CDialog::OnTimer(nIDEvent);
}

void CDemo11Dlg::OnStopIm() 
{
    inp_move3(cardno, 5000, 10000, -20000);//X-Y-Z开始插补
                                    //X正向移动5000步
                                    //Y正向移动10000步
                                    //Z反向移动20000步	
}

void CDemo11Dlg::OnButton8() 
{
 adt850_end();
 CDialog::OnCancel();
	
}

⌨️ 快捷键说明

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