accross.cpp

来自「机械手IPC控制器伺服运动程序」· C++ 代码 · 共 230 行

CPP
230
字号
// Accross.cpp : implementation file
//

#include "stdafx.h"
#include "alfa.h"
#include "mccl.h"
#include "Accross.h"
#include "TeachMode.h"
#include "sys.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAccross dialog


CAccross::CAccross(CWnd* pParent /*=NULL*/)
	: CDialog(CAccross::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAccross)
    m_y = 0.0;
    m_speed = 10;
	//}}AFX_DATA_INIT
}


void CAccross::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAccross)
	DDX_Control(pDX, IDC_EDIT2, m_edt2);
	DDX_Control(pDX, IDC_EDIT1, m_edt1);
    DDX_Text(pDX, IDC_EDIT1, m_y);
	DDX_Text(pDX, IDC_EDIT2, m_speed);
//	DDX_Text(pDX, IDC_EDIT1, m_y_str);
//	DDX_Text(pDX, IDC_EDIT2, m_speed_str);
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// CAccross message handlers

void CAccross::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CDialog::OnShowWindow(bShow, nStatus);
    CString m_y_str, m_speed_str;
	
	// TODO: Add your message handler code here
	if(bShow==1) {
		CTeachMode * parent=(CTeachMode *)GetParent();
		if(parent->flagShow==0) {
			m_y=0;
		    m_speed=10;
		}
		else {
			int idx=parent->curidx;
			m_y=parent->command[idx].pubpara.y;
			m_speed=parent->command[idx].pubpara.speed_across;
		}
		m_y_str.Format("%6.2f", m_y);
        m_speed_str.Format("%3d", m_speed); 
        GetDlgItem(IDC_EDIT1)->SetWindowText(m_y_str);
        GetDlgItem(IDC_EDIT2)->SetWindowText(m_speed_str);
		//UpdateData(FALSE);
	}
}


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


void CAccross::OnLButtonDown(UINT nFlags, CPoint point) 
{
    CString m_y_str; 
	long m_curmz, s_curmz, m_curmy;
	double m_z, s_z;
	WORD wInput0;
	WORD OTStatus;

    MCC_GetRIOInputValue(&wInput0, RIO_SET1, RIO_PORT0, CARD_INDEX);
	MCC_GetENCValue(&m_curmz, 1, 0);
	MCC_GetENCValue(&m_curmy, 2, 0);
	MCC_GetENCValue(&s_curmz, 4, 0);
    m_curmz=m_curmz*unit1a;
    m_curmy=m_curmy*unit2a;
    s_curmz=s_curmz*unit4a;
    m_z=(m_curmz/2500.0)*unit1;
    m_y=(m_curmy/2500.0)*unit2;
    s_z=(s_curmz/2500.0)*unit4;
    m_y_str.Format("%6.2f", m_y);
    GetDlgItem(IDC_EDIT1)->SetWindowText(m_y_str);

	if((OUTPUT0 & 0x2000)>0 || (wInput0 & 0x0080)>0) return;
	if(PtInRect(CRect(110, 50, 160, 80), point)) {     // JOG Y+
        if(MCC_GetLimitSwitchStatus(&OTStatus, 1, 2, 0)==0) { // Y+, HOT
            if(OTStatus==1) ;
			else if(m_y>mytsafepos && m_y<((mypsafepos+mytsafepos)/2.0) &&
		           (m_z>msafepos     || s_z>msafepos ||
		           (wInput0 & 0x0800)==0 || (wInput0 & 0x1000)==0)) ;
            else if(m_y>YSOT_Plus)	;
			else {
		        MCC_JogConti(1, JogSpeed, 1, 2); //  Y+
		        JogDir=5;
			    SetTimer(32, 10, NULL);
            }	
        }
	}
	else if(PtInRect(CRect(50, 50, 100, 80), point)) { // JOG Y-
        if(MCC_GetLimitSwitchStatus(&OTStatus, 0, 2, 0)==0) { // Y-, HOT
            if(OTStatus==1) ;
			else if(m_y<mypsafepos && m_y>((mypsafepos+mytsafepos)/2.0) &&
		           (m_z>msafepos     || s_z>msafepos ||
		           (wInput0 & 0x0800)==0 || (wInput0 & 0x1000)==0)) ;
            else if(m_y<YSOT_Minus) ;
			else {
		        MCC_JogConti(-1, JogSpeed, 1, 2); //  Y+
                JogDir=6;
			    SetTimer(32, 10, NULL);
            }	
        }
	}

    CDialog ::OnLButtonDown(nFlags, point); 
}


void CAccross::OnLButtonUp(UINT nFlags, CPoint point) 
{
    CString m_y_str, m_speed_str; 
	if(JogDir==5 || JogDir==6) {
      JogDir=0;
	  KillTimer(32);
    }
	m_y_str.Format("%6.2f", m_y);
    m_speed_str.Format("%3d", m_speed); 
    GetDlgItem(IDC_EDIT1)->SetWindowText(m_y_str);
    GetDlgItem(IDC_EDIT2)->SetWindowText(m_speed_str);
	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, GROUP_INDEX0);
//    MCC_AbortMotionEx(SX_DecTime, GROUP_INDEX1);
//    MCC_AbortMotionEx(Y_DecTime, GROUP_INDEX2);

    CDialog::OnLButtonUp(nFlags, point); 
}


void CAccross::OnTimer(UINT nIDEvent) 
{
	int TempAlarm;
    CString m_y_str; 
	long m_curmz, s_curmz, m_curmy;
	double m_z, s_z;
	WORD wInput0;
	WORD OTStatus;

    TempAlarm=0;
    MCC_GetRIOInputValue(&wInput0, RIO_SET1, RIO_PORT0, CARD_INDEX);
	MCC_GetENCValue(&m_curmz, 1, 0);
	MCC_GetENCValue(&m_curmy, 2, 0);
	MCC_GetENCValue(&s_curmz, 4, 0);
    m_curmz=m_curmz*unit1a;
    m_curmy=m_curmy*unit2a;
    s_curmz=s_curmz*unit4a;
    m_z=(m_curmz/2500.0)*unit1;
    m_y=(m_curmy/2500.0)*unit2;
    s_z=(s_curmz/2500.0)*unit4;
    m_y_str.Format("%6.2f", m_y);
    GetDlgItem(IDC_EDIT1)->SetWindowText(m_y_str);

	if((OUTPUT0 & 0x2000)>0 || (wInput0 & 0x0080)>0) TempAlarm=1;
	if(JogDir==5) {     // JOG Y+
        if(MCC_GetLimitSwitchStatus(&OTStatus, 1, 2, 0)==0) { // Y+, HOT
            if(OTStatus==1) TempAlarm=1;
			else if(m_y>mytsafepos && m_y<((mypsafepos+mytsafepos)/2.0) &&
		           (m_z>msafepos     || s_z>msafepos ||
		           (wInput0 & 0x0800)==0 || (wInput0 & 0x1000)==0)) TempAlarm=1;
            else if(m_y>YSOT_Plus) TempAlarm=1;
        }
		else TempAlarm=1;
	}
	else if(JogDir==6) { // JOG Y-
        if(MCC_GetLimitSwitchStatus(&OTStatus, 0, 2, 0)==0) { // Y-, HOT
            if(OTStatus==1) TempAlarm=1;
			else if(m_y<mypsafepos && m_y>((mypsafepos+mytsafepos)/2.0) &&
		           (m_z>msafepos     || s_z>msafepos ||
		           (wInput0 & 0x0800)==0 || (wInput0 & 0x1000)==0)) TempAlarm=1;
            else if(m_y<YSOT_Minus) TempAlarm=1;
        }
		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);
		KillTimer(32);	
    }

	CDialog::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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