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

📄 backass.cpp

📁 机械手IPC控制器伺服运动程序
💻 CPP
字号:
// BackAss.cpp : implementation file
//

#include "stdafx.h"
#include "alfa.h"
#include "BackAss.h"
#include "Main.h"
#include "mccl.h"
#include "sys.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBackAss dialog


CBackAss::CBackAss(CWnd* pParent /*=NULL*/)
	: CDialog(CBackAss::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBackAss)
	m_edt1 = 0.0;
	m_edt2 = 10;
	//}}AFX_DATA_INIT
}


void CBackAss::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBackAss)
	DDX_Control(pDX, IDC_EDIT2, m_edit2);
	DDX_Control(pDX, IDC_EDIT1, m_edit1);
	DDX_Text(pDX, IDC_EDIT1, m_edt1);
	DDX_Text(pDX, IDC_EDIT2, m_edt2);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBackAss, CDialog)
	//{{AFX_MSG_MAP(CBackAss)
	ON_WM_SHOWWINDOW()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBackAss message handlers

void CBackAss::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CDialog::OnShowWindow(bShow, nStatus);
    CString m_Dist_str, m_Speed_str;
	
	// TODO: Add your message handler code here
	if(bShow==1)
	{
		CMain * main=(CMain *)GetParent();
		m_edt1=main->dlgfixedmode->moveparam.distance_x_ass;
		m_edt2=main->dlgfixedmode->moveparam.speed_back_ass;
        CStatic *Distmsg=(CStatic *)GetDlgItem(IDC_EDIT1);
        CStatic *Speedmsg=(CStatic *)GetDlgItem(IDC_EDIT2);
	    m_Dist_str.Format("%6.2f", m_edt1);
	    m_Speed_str.Format("%3d", m_edt2);
        Distmsg->SetWindowText(m_Dist_str);      
        Speedmsg->SetWindowText(m_Speed_str);  
		m_Kill_Flag=0;
//		UpdateData(FALSE);
		main->dlgcur =this;
	}
}

void CBackAss::OnOK() 
{
	// TODO: Add extra validation here
	CMain * main=(CMain *)GetParent();
	UpdateData();
    main->dlgfixedmode->moveparam.distance_x_ass=m_edt1;
    main->dlgfixedmode->moveparam.speed_back_ass=m_edt2;
	JogDir=0;  KillTimer(47);
	ShowWindow(FALSE);
    main->dlgfixedmode->ShowWindow(TRUE);
}

void CBackAss::OnCancel() 
{
	// TODO: Add extra cleanup here
	CMain * main=(CMain *)GetParent();
	JogDir=0;  KillTimer(47);
	ShowWindow(FALSE);
    main->dlgfixedmode->ShowWindow(TRUE);
}


BOOL CBackAss::OnInitDialog() 
{
	CDialog::OnInitDialog();
	h_SkinDialog.SubClassDialog(m_hWnd);
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


void CBackAss::OnLButtonDown(UINT nFlags, CPoint point) 
{
	long m_curmx;
	double m_x;
	WORD wInput0;
	WORD OTStatus;

    MCC_GetRIOInputValue(&wInput0, RIO_SET1, RIO_PORT0, CARD_INDEX);
	MCC_GetENCValue(&m_curmx, 3, 0);
    m_curmx=m_curmx*unit3a;
    m_x=(m_curmx/2500.0)*unit3;

	if((OUTPUT0 & 0x2000)>0 || (wInput0 & 0x0080)>0) return;

	if(PtInRect(CRect(214, 36, 264, 66), point)) {
        if(MCC_GetLimitSwitchStatus(&OTStatus, 1, 3, 0)==0) { // SX+, HOT
            if(OTStatus==1) ;
			else if(m_x>SXSOT_Plus) ;     // SX+, SOT
			else {
                JogDir=7;  m_Kill_Flag=-1;    
                KillTimer(47);
		        MCC_JogConti(1, JogSpeed, 0, 1); //  SX+
                SetTimer(47, 10, NULL);
            }
		}
	}
	else if(PtInRect(CRect(154, 36, 204, 66), point)) {
        if(MCC_GetLimitSwitchStatus(&OTStatus, 0, 3, 0)==0) { // SX-, HOT
            if(OTStatus==1) ;
			else if(m_x<SXSOT_Minus) ;    // SX-, SOT
			else {
                JogDir=8;  m_Kill_Flag=-1; 
                KillTimer(47);
		        MCC_JogConti(-1, JogSpeed, 0, 1); //  SX-
                SetTimer(47, 10, NULL);
            }
		}
	}

	CDialog::OnLButtonDown(nFlags, point); 
}


void CBackAss::OnLButtonUp(UINT nFlags, CPoint point) 
{
    CString s_x_str; 
	long m_cursx;
	double s_x;
    if(JogDir==7 || JogDir==8) {
//        JogDir=0;
	    MCC_GetENCValue(&m_cursx, 3, 0);
        m_cursx=m_cursx*unit3a;
	    s_x=(m_cursx/2500.0)*unit3;
        CStatic *PosXmsg=(CStatic *)GetDlgItem(IDC_EDIT1);
	    s_x_str.Format("%6.2f", s_x);
        PosXmsg->SetWindowText(s_x_str);
        m_Kill_Flag=100; 
// 	    KillTimer(41);     
    }

	MCC_AbortMotion(0);//  stop current motion and discard all motion commands in a command queue
	MCC_AbortMotion(1);//  stop current motion and discard all motion commands in a command queue
	MCC_AbortMotion(2);//  stop current motion and discard all motion commands in a command queue
//    MCC_AbortMotionEx(MX_DecTime*JogSpeed/100.0, GROUP_INDEX0);
//    MCC_AbortMotionEx(SX_DecTime*JogSpeed/100.0, GROUP_INDEX1);
//    MCC_AbortMotionEx(Y_DecTime*JogSpeed/100.0, GROUP_INDEX2);

	CDialog ::OnLButtonUp(nFlags, point); 
}


void CBackAss::OnTimer(UINT nIDEvent) 
{
	int TempAlarm;
    CString m_x_str; 
	long m_curmx;
	double m_x;
	WORD wInput0;
	WORD OTStatus;

    TempAlarm=0;
    MCC_GetRIOInputValue(&wInput0, RIO_SET1, RIO_PORT0, CARD_INDEX);
	MCC_GetENCValue(&m_curmx, 3, 0);
    m_curmx=m_curmx*unit3a;
	m_x=(m_curmx/2500.0)*unit3;
    CStatic *PosXmsg=(CStatic *)GetDlgItem(IDC_EDIT1);
	m_x_str.Format("%6.2f", m_x);
    PosXmsg->SetWindowText(m_x_str);

	if(m_Kill_Flag>0) { m_Kill_Flag--;  return; }
	if(m_Kill_Flag==0) { JogDir=0;  m_Kill_Flag=-1;  KillTimer(47);  return; }

	if((OUTPUT0 & 0x2000)>0 || (wInput0 & 0x0080)>0) TempAlarm=1;
	if(JogDir==7) {
        if(MCC_GetLimitSwitchStatus(&OTStatus, 1, 3, 0)==0) { // SX+, HOT
            if(OTStatus==1) TempAlarm=1;
			else if(m_x>SXSOT_Plus) TempAlarm=1; // SX+, SOT
        }
		else TempAlarm=1;
	}
	else if(JogDir==8) {
        if(MCC_GetLimitSwitchStatus(&OTStatus, 0, 3, 0)==0) { // SX-, HOT
            if(OTStatus==1) TempAlarm=1;
			else if(m_x<SXSOT_Minus) TempAlarm=1; // SX-, SOT
		}
		else TempAlarm=1;
	}
	if(TempAlarm>0) {
        JogDir=0; 
	    MCC_AbortMotion(0);
	    MCC_AbortMotion(1);
	    MCC_AbortMotion(2);
//        MCC_AbortMotionEx(MX_DecTime*JogSpeed/100.0, GROUP_INDEX0);
//        MCC_AbortMotionEx(SX_DecTime*JogSpeed/100.0, GROUP_INDEX1);
//        MCC_AbortMotionEx(Y_DecTime*JogSpeed/100.0, GROUP_INDEX2);
        m_Kill_Flag=100; 
//		KillTimer(42);	
    }

	CDialog::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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