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

📄 autoteach.cpp

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

#include "stdafx.h"
#include "alfa.h"
#include "AutoTeach.h"
#include "Main.h"
#include "Math.h"
#include "io.h"
#include "MCCL.h"
#include "sys.h"
#define TEACH_FILE _T("teach.bkp")
#define DATAGLB_FILE _T("dataglb.bkp")
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define TimerID 1
/////////////////////////////////////////////////////////////////////////////
// CAutoTeach dialog

void _stdcall PCL_ISR_Function(PCLINT *pstINTSource);

BYTE   byInPos0, byInPos1, byInPos2, byInPos3, byInPos4, byInPos5;
int gnOverflowCount[2] = {0, 0};
int nCommandFinfish;
//int curitem=0;

CAutoTeach::CAutoTeach(CWnd* pParent /*=NULL*/)
	: CDialog(CAutoTeach::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAutoTeach)
	m_num = _T("");
	//}}AFX_DATA_INIT
	m_min=0;
	j_marm=0;
	k_sarm=0;
	n_max=0;
	prgcount=0;
	m_speedtch=2;
	s_speedtch=2;
//	codtmx=0;
//	codtmy=0;
//	codtmz=0;
//	codtsx=0;
//	codtsy=0;
//	codtsz=0;
	runflg=0;
	mopflg=0;
	rmcflg=0;
	nx=0;
	ny=0;
	nz=0;
	stack1flg0=0;
	stack1flg1=0;
//	stack1flg2=0;
//	stack1flg3=0;
//	stack1flg4=0;
//    m_Stack1_Flag=0;
	m_longx=0;
	m_longy=0;
	m_longz=0;
	nx2=0;
	ny2=0;
	nz2=0;
	stack2flg0=0;
	stack2flg1=0;
//	stack2flg2=0;
//	stack2flg3=0;
//	stack2flg4=0;
    m_Stack_Flag=0;
	m_longx2=0;
	m_longy2=0;
	m_longz2=0;
	mopflg2=0;
	atte_waitmx=0;
	atte_waitmz=0;
	atte_waitsx=0;
	atte_waitsz=0;
	atte_waity=0;
	waitrdy=0;
	g0flg=0;
	g1flg=0;
	g2flg=0;
	SglBlk=0;
	CycleSt=0;
	SglCount=0;
}


void CAutoTeach::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAutoTeach)
//	DDX_Control(pDX, IDC_EDIT1, m_edit);
	DDX_Control(pDX, IDC_LIST1, m_list1);
	DDX_Control(pDX, IDC_EDIT7, m_edit7);
	DDX_Text(pDX, IDC_EDIT1, m_num);
//	DDX_Text(pDX, IDC_EDIT2, m_atmx);
//	DDX_Text(pDX, IDC_EDIT3, m_atmz);
//	DDX_Text(pDX, IDC_EDIT4, m_atmsy);
//	DDX_Text(pDX, IDC_EDIT5, m_atsx);
//	DDX_Text(pDX, IDC_EDIT6, m_atsz);
	DDX_Text(pDX, IDC_EDIT2, m_atmx_str);
	DDX_Text(pDX, IDC_EDIT3, m_atmz_str);
	DDX_Text(pDX, IDC_EDIT4, m_atmsy_str);
	DDX_Text(pDX, IDC_EDIT5, m_atsx_str);
	DDX_Text(pDX, IDC_EDIT6, m_atsz_str);
	DDX_Text(pDX, IDC_EDIT7, m_Mold_Set);
	DDX_Text(pDX, IDC_EDIT8, m_Mold_Cur);
	DDX_Text(pDX, IDC_EDIT9, m_Mold_Total);
	DDX_Text(pDX, IDC_EDIT10, m_Mold_Stack1D);
	DDX_Text(pDX, IDC_EDIT11, m_Mold_Stack2D);
	DDX_Text(pDX, IDC_EDIT12, m_NG_Num);
	DDX_Text(pDX, IDC_EDIT13, m_QC_Num);

	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAutoTeach, CDialog)
	//{{AFX_MSG_MAP(CAutoTeach)
	ON_WM_SHOWWINDOW()
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
	ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_CHECK4, OnCheck4)
	ON_BN_CLICKED(IDC_BUTTON41, OnButton41)
	ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
	ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
	ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
	ON_BN_CLICKED(IDC_BUTTON12, OnButton12)
	ON_BN_CLICKED(IDC_BUTTON13, OnButton13)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAutoTeach message handlers

BOOL CAutoTeach::CanSerialize()
{
//    return(0==_access(TEACH_FILE,10));
    if(FileDataType==1) return(0==_access(DATAGLB_FILE, 6));   
    else return(0==_access(TEACH_FILE, 6));
}


void CAutoTeach::Serialize(CArchive& ar) 
{
    if(FileDataType==1) glb.Serialize(ar);
	else m_teach.Serialize(ar);
}


void CAutoTeach::LoadRecords()
{
    if(CanSerialize()) {
	    CFile file;
	    CFileException fe;
		if(FileDataType==1) {
	        if(file.Open(DATAGLB_FILE, CFile::typeBinary|CFile::modeRead, &fe)) {
		        CArchive ar(&file, CArchive::load);
		        Serialize(ar);
			}
		}
		else {
	        if(file.Open(TEACH_FILE,CFile::typeBinary|CFile::modeRead, &fe)) {
		        CArchive ar(&file,CArchive::load);
		        Serialize(ar);
			}
		}
	}
}

void CAutoTeach::SaveRecords()
{
    if(FileDataType==1) {
        BOOL bCansave;
        int flag=CFile::typeBinary|CFile::modeWrite;
        if(_access(DATAGLB_FILE, 0)) {
            flag|=CFile::modeCreate;
            bCansave=TRUE;
		}
        else {
            bCansave=CanSerialize();
		}
        if(bCansave) {
            CFile file;
            CFileException fe;
            if(file.Open(DATAGLB_FILE, flag, &fe)) {
	            CArchive ar(&file, CArchive::store);
	            Serialize(ar);
			}
		}
	}
    else {
        Cteach * pteach=NULL;
        UpdateData();
        m_teach.Lookup(m_num, pteach);
        if(pteach) {
//            command[0].pubpara.funid=command[0].pubpara.funid%100;
//            command[0].pubpara.speed_across=command[0].pubpara.speed_across%125; 
//		    if(pteach->length>0) {
//                command[0].pubpara.funid=MoldSet*100+command[0].pubpara.funid;
//                command[0].pubpara.speed_across=MoldCountCur*125+command[0].pubpara.speed_across;   
//			}  
//	        memcpy(&pteach->queuecommand[0],&command[0],sizeof(command[0]));
			
	        memcpy(&pteach->queuecommand[Cursel],&command[Cursel],sizeof(command[0]));
		}
        if(CanSerialize()) {
	        CFile file;
	        CFileException fe;
	        if(file.Open(TEACH_FILE,CFile::modeWrite|CFile::typeBinary,&fe)) {
		        CArchive ar(&file,CArchive::store);
		        Serialize(ar);
//		        if(pteach->length>0) {
//                    command[0].pubpara.funid=command[0].pubpara.funid%100;
//                    command[0].pubpara.speed_across=command[0].pubpara.speed_across%125; 
//				}
			}
		}
	}
}


void CAutoTeach::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CDialog::OnShowWindow(bShow, nStatus);

	int Temp_int;
//	long m_posmx, m_posmz, m_posmsy, m_possx, m_possz;	
	// TODO: Add your message handler code here
	if(bShow!=1) return;

	CMain * main=(CMain *)GetParent();
	main->dlgcur=this;
	if(DiagID==12) { return; }
	else DiagID=12;

    DataChanged=0;
	for(int j=0; j<=Curindex; j++) m_list1.DeleteString(0);
	Curindex=-1;
	if(main->m_num=="") return;
	LoadRecords();
	Cteach * pteach;
	pteach=NULL;
    m_teach.Lookup(main->m_num, pteach);
	if(pteach) {
		m_num=pteach->m_num;
		UpdateData(FALSE);
		prgcount=pteach->GetQueueLength();
		prgcount--;
		CommandLength=pteach->GetQueueLength();
		memset(command, 0, sizeof(command[0])*1024);
		memcpy(command, pteach->queuecommand, sizeof(command[0])*CommandLength);
 	    Curindex=CommandLength-1;
        if(CommandLength>0) {
            MoldSet=command[0].pubpara.funid/100;   
            command[0].pubpara.funid=command[0].pubpara.funid%100;
			MoldCountCur=command[0].pubpara.speed_across/125;          
            command[0].pubpara.speed_across=command[0].pubpara.speed_across%125;				
		}
		else {
            MoldSet=0;   
			MoldCountCur=0;
		}
		ShowCommand(0);
		atte_waitmx=pteach->wait_mx;
		atte_waitmz=pteach->wait_mz;
		atte_waitsx=pteach->wait_sx;
		atte_waitsz=pteach->wait_sz;
		atte_waity=pteach->wait_y;
	}
	dlgautoteachstatus->ShowWindow(TRUE);

	CButton *SglChk=(CButton *)GetDlgItem(IDC_CHECK4);
    if(SglBlk==1) SglChk->SetCheck(1); 
    else SglChk->SetCheck(0);
	m_min=0;
	j_marm=0;
	k_sarm=0;
	n_max=0;
    SglCount=0;
	waitrdy=0;
	teatovflg=0;
    Across_State=0;
	CycleSt=0;
	Hold_Flag=0;
    DlyChk=0;
	waitrdy=0;
	m_Mold_Close=0;
    m_MoldOpen=0;
    m_MoldOpened=0;
	g0flg=0;
	FileDataType=0;
	Get_Flag=0;
	NG_QC_Flag=0;
    m_Mold_Total=MoldCountSet;
    m_Mold_Set=MoldSet;
    m_Mold_Cur=MoldCountCur;
    m_Mold_Stack1=MoldStack1; 
    m_Mold_Stack2=MoldStack2; 
    m_NG_Num=NG_Num;
    m_QC_Num=QC_Num;
	m_S1ZDown=MoldReserv1 & 0x000000FF; 
	if(m_S1ZDown<=5) m_S1ZDown=5; 
	Temp_int=MoldReserv1 & 0x0000FF00;
	m_S1ZUp=Temp_int/0x00000100;
	if(m_S1ZUp<=5) m_S1ZUp=5; 
	Temp_int=MoldReserv1 & 0x00FF0000;
	m_S2ZDown=Temp_int/0x00010000;
	if(m_S2ZDown<=5) m_S2ZDown=5; 
	Temp_int=MoldReserv1 & 0xFF000000;
	m_S2ZUp=Temp_int/0x01000000;
	if(m_S2ZUp<=5) m_S2ZUp=5; 
	m_Stack1_Full=0;  m_Stack2_Full=0;
    m_TimerCount=0;
   	GetDlgItem(IDC_BUTTON3)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON41)->EnableWindow(TRUE);
	runflg=SYS_STATUS_READY;
    GetPosCoord();
    if(msgalm>0 || JogAlarm>0) AlarmDisplayON();

    SetTimer(TimerID, 30, NULL);
}

// Exit
void CAutoTeach::OnButton2() 
{
	// TODO: Add your control notification handler code here
	CMain * main=(CMain *)GetParent();
	ShowWindow(FALSE);
	dlgautoteachset1->ShowWindow(FALSE);
	dlgautoteachset2->ShowWindow(FALSE);
	dlgautoteachstatus->ShowWindow(FALSE);
	main->dlgmainfrm->ShowWindow(TRUE);

	DiagID=0;
	if(runflg==SYS_STATUS_RUN && m_MoldOpened==1)  {
		runflg=SYS_STATUS_EXIT;
	}
	else { // Hold
//	    MCC_AbortMotionEx(0);
//	    MCC_AbortMotionEx(1);
//	    MCC_AbortMotionEx(2);
        MCC_AbortMotionEx(MX_DecTime, GROUP_INDEX0);
        MCC_AbortMotionEx(SX_DecTime, GROUP_INDEX1);
        MCC_AbortMotionEx(Y_DecTime, GROUP_INDEX2);
	    AlarmDisplayOFF();
        j_marm=0;
 	    k_sarm=0;
        SglCount=0;
	    waitrdy=0;
		g0flg=0;
        runflg=SYS_STATUS_READY;
	    teatovflg=0;
        Across_State=0;
	    CycleSt=0;
	    Hold_Flag=0;

        command[0].pubpara.funid=command[0].pubpara.funid%100;
        command[0].pubpara.speed_across=command[0].pubpara.speed_across%125; 
        command[0].pubpara.funid=MoldSet*100+command[0].pubpara.funid;
        command[0].pubpara.speed_across=MoldCountCur*125+command[0].pubpara.speed_across;   
        Cursel=0;
	    FileDataType=0; 
	    SaveRecords();

		SaveGlobal();
		OUTPUT0=OUTPUT0 | 0x0200;
	    MCC_SetRIOOutputValue(OUTPUT0, RIO_SET1, RIO_PORT0, CARD_INDEX);
		KillTimer(TimerID);
    }
}


void CAutoTeach::ShowCommand(int index)
{
    char que[150], quesub[30];
    int i, j=m_list1.GetCount();
	int XNum, YNum, ZNum;
    
	m_Stack1_Num=0;
	m_Stack2_Num=0;
    if(index>=0)
	    for(i=index;i<j;i++) m_list1.DeleteString(index);
    else index=Curindex;
 
    for(i=index; i<=Curindex; i++) {
	    memset(que, 0, 150);
	    memset(quesub, 0, 30);
	    sprintf(que, "%4d ", i+1);
		if(command[i].fpublic==1) { // Public Fun.
			strcat(que, "          ");
		    switch(command[i].pubpara.funid) {
		        case 0:
			        strcat(que, " 绢︽(Y=");
			        sprintf(quesub, "%7.2f", command[i].pubpara.y);
			        strcat(que, quesub);
			        strcat(que, ")");
			        strcat(que,"     硉

⌨️ 快捷键说明

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