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

📄 down.cpp

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

#include "stdafx.h"
#include "alfa.h"
#include "Down.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

/////////////////////////////////////////////////////////////////////////////
// CDown dialog


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


void CDown::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDown)
	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(CDown, CDialog)
	//{{AFX_MSG_MAP(CDown)
	ON_WM_SHOWWINDOW()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDown message handlers

void CDown::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_z_main;
		m_edt2=main->dlgfixedmode->moveparam.speed_down_main;
	    m_Dist_str.Format("%6.2f", m_edt1);
	    m_Speed_str.Format("%3d", m_edt2);
        GetDlgItem(IDC_EDIT1)->SetWindowText(m_Dist_str);      
        GetDlgItem(IDC_EDIT2)->SetWindowText(m_Speed_str); 
		m_Kill_Flag=0;
//		UpdateData(FALSE);
		main->dlgcur=this;
	}
}

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

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


BOOL CDown::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 CDown::OnLButtonDown(UINT nFlags, CPoint point) 
{
    CString m_x_str, m_z_str; 
	long m_curmz, m_curmy;
	double m_y, m_z;
	WORD wInput0;
	WORD OTStatus, OTStatus1;

    MCC_GetRIOInputValue(&wInput0, RIO_SET1, RIO_PORT0, CARD_INDEX);
	MCC_GetENCValue(&m_curmz, 1, 0);
	MCC_GetENCValue(&m_curmy, 2, 0);
    m_curmz=m_curmz*unit1a;
    m_curmy=m_curmy*unit2a;
    m_z=(m_curmz/2500.0)*unit1;
    m_y=(m_curmy/2500.0)*unit2;

	if((OUTPUT0 & 0x2000)>0 || (wInput0 & 0x0080)>0) return;
    if(PtInRect(CRect(214, 36, 264, 66), point)) {
        MCC_GetLimitSwitchStatus(&OTStatus1, 0, 1, 0);
        if(MCC_GetLimitSwitchStatus(&OTStatus, 1, 1, 0)==0) { // MZ+, HOT
            if(OTStatus==1) ;
			else if(OTStatus1==1) {
                JogDir=3;  m_Kill_Flag=-1;
                KillTimer(43);
		        MCC_JogConti(1, JogSpeed, 2, 0); 
                SetTimer(43, 10, NULL);
            }
			else if((m_z>msafepos || (wInput0 & 0x0800)==0) &&                          
				    m_y>mytsafepos && m_y<mypsafepos) ; // MZ+, SOT
            else if(m_z>MZSOT_Plus)	;
			else if(m_y<mytsafepos && (wInput0 & 0x0001)==0) ;
			else {
                JogDir=3;  m_Kill_Flag=-1;
                KillTimer(43);
		        MCC_JogConti(1, JogSpeed, 2, 0); 
                SetTimer(43, 10, NULL);
            }	
        }
 	}
	else if(PtInRect(CRect(154, 36, 204, 66), point)) {
        if(MCC_GetLimitSwitchStatus(&OTStatus, 0, 1, 0)==0) { // MZ-, HOT
            if(OTStatus==1) ;
			else if(m_z<MZSOT_Minus) ;    // MZ-, SOT
            else {			
                JogDir=4;  m_Kill_Flag=-1;
                KillTimer(43);
		        MCC_JogConti(-1, JogSpeed, 2, 0); 
                SetTimer(43, 10, NULL);
			}
        }
	}
	
	CDialog::OnLButtonDown(nFlags, point); 
}


void CDown::OnLButtonUp(UINT nFlags, CPoint point) 
{
    CString m_z_str; 
	long m_curmz;
	double m_z;
    if(JogDir==3 || JogDir==4) {
//        JogDir=0;
	    MCC_GetENCValue(&m_curmz, 1, 0);
        m_curmz=m_curmz*unit1a;
	    m_z=(m_curmz/2500.0)*unit1;
	    m_z_str.Format("%6.2f", m_z);
        GetDlgItem(IDC_EDIT1)->SetWindowText(m_z_str);
		m_Kill_Flag=100;
// 	    KillTimer(43);     
    }

	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 CDown::OnTimer(UINT nIDEvent) 
{
	int TempAlarm;
    CString m_z_str; 
	long m_curmz, m_curmy;
	double m_y, m_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);
    m_curmz=m_curmz*unit1a;
    m_curmy=m_curmy*unit2a;
	m_z=(m_curmz/2500.0)*unit1;
    m_y=(m_curmy/2500.0)*unit2;
	m_z_str.Format("%6.2f", m_z);
    GetDlgItem(IDC_EDIT1)->SetWindowText(m_z_str);

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

	if((OUTPUT0 & 0x2000)>0 || (wInput0 & 0x0080)>0) TempAlarm=1;
    if(JogDir==3) {
        if(MCC_GetLimitSwitchStatus(&OTStatus, 1, 1, 0)==0) { // MZ+, HOT
            if(OTStatus==1) TempAlarm=1 ;
			else if((m_z>msafepos || (wInput0 & 0x0800)==0) &&                          
				    m_y>mytsafepos && m_y<mypsafepos) TempAlarm=1; // MZ+, SOT
            else if(m_z>MZSOT_Plus)	TempAlarm=1;
        }
		else TempAlarm=1;
 	}
	else if(JogDir==4) {
        if(MCC_GetLimitSwitchStatus(&OTStatus, 0, 1, 0)==0) { // MZ-, HOT
            if(OTStatus==1) TempAlarm=1;
		    else if(m_z<MZSOT_Minus) TempAlarm=1; // MZ-, 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 + -