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

📄 plc_demoview.cpp

📁 开发虚拟的被控对象及虚拟的PLC,模似PLC的工作过程进行实验。用户可根据具体的实验,确定其输入和输出的控制条件,用虚拟的连线和虚拟的PLC连接,用户利用梯形图的编程方式编写PLC程序控制被控对象的动
💻 CPP
字号:
// PLC_DEMOView.cpp : implementation of the CPLC_DEMOView class
//

#include "stdafx.h"
#include "PLC_DEMO.h"

#include "PLC_DEMODoc.h"
#include "PLC_DEMOView.h"
#include "Input_link.h"
#include "Auto_truck_load.h"
#include "Traffic_lump_control.h"
#include "Instruction_define.h"
#include "Fetch_communicate.h"
#include "Run_auto_truck_load.h"
#include "Write_inandout_point.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPLC_DEMOView
bool beginset=false;

extern bool inputcheck,outputcheck;
extern bool switchcheck,outcontrolcheck;
extern bool inputenable,outputenable;
extern bool autotruckenable;
extern bool trafficlumpenable;
extern bool T[9];
extern bool WR[1000];
extern bool canload;
extern int signinput[8];
extern int signoutput[10];
extern int fillerstartpoint;
extern int fillerendpoint;
extern int truckloadpoint;
extern int thetruckpoint;
extern bool truckinenable;
extern bool weighto;
extern bool canclearthetruck;
extern bool fillerloadenable;
extern bool candrawpoint;
extern bool objectcheckenable;
extern bool goodsarrive;
extern bool sensorshow1;
extern bool sensorshow2;
extern bool sensorshow3;
extern bool canshow1;
extern bool canshow2;
extern bool cancleargoods;
extern bool waitup;
extern bool thesensor3true;
extern int wasterplace;
extern bool downthewaster;
extern bool canclearwaster;
extern int thegoodsplace;
extern int 	goodskind[6];
extern bool downqualitygoods;
extern int qualitygoodsplace;
extern bool canaddplace;

void inputfetchlink(int,int,int,int);
void outputfetchlink(int,int,int,int);
void autotruckdraw();
void Traffic_lump_draw();
void inputfetchdraw();
void outputfetchdraw();
void draw_object_check();
void initializedraw();
void drawpoint();

CPLC_DEMOView *fortime,*fordraw,*forsend,*forrun;

IMPLEMENT_DYNCREATE(CPLC_DEMOView, CFormView)

BEGIN_MESSAGE_MAP(CPLC_DEMOView, CFormView)
	//{{AFX_MSG_MAP(CPLC_DEMOView)
	ON_BN_CLICKED(IDC_INPUT1, OnInput1)
	ON_BN_CLICKED(IDC_SWITCH1, OnSwitch1)
	ON_BN_CLICKED(IDC_INPUT2, OnInput2)
	ON_BN_CLICKED(IDC_INPUT3, OnInput3)
	ON_BN_CLICKED(IDC_INPUT4, OnInput4)
	ON_BN_CLICKED(IDC_INPUT5, OnInput5)
	ON_BN_CLICKED(IDC_INPUT6, OnInput6)
	ON_BN_CLICKED(IDC_INPUT7, OnInput7)
	ON_BN_CLICKED(IDC_SWITCH2, OnSwitch2)
	ON_BN_CLICKED(IDC_SWITCH3, OnSwitch3)
	ON_BN_CLICKED(IDC_SWITCH4, OnSwitch4)
	ON_BN_CLICKED(IDC_SWITCH5, OnSwitch5)
	ON_BN_CLICKED(IDC_SWITCH6, OnSwitch6)
	ON_BN_CLICKED(IDC_SWITCH7, OnSwitch7)
	ON_BN_CLICKED(IDC_OUTPUT1, OnOutput1)
	ON_BN_CLICKED(IDC_OUTCONTROL1, OnOutcontrol1)
	ON_BN_CLICKED(IDC_OUTPUT2, OnOutput2)
	ON_BN_CLICKED(IDC_OUTPUT3, OnOutput3)
	ON_BN_CLICKED(IDC_OUTPUT4, OnOutput4)
	ON_BN_CLICKED(IDC_OUTPUT5, OnOutput5)
	ON_BN_CLICKED(IDC_OUTPUT6, OnOutput6)
	ON_BN_CLICKED(IDC_OUTPUT7, OnOutput7)
	ON_BN_CLICKED(IDC_OUTPUT8, OnOutput8)
	ON_BN_CLICKED(IDC_OUTPUT9, OnOutput9)
	ON_BN_CLICKED(IDC_OUTCONTROL2, OnOutcontrol2)
	ON_BN_CLICKED(IDC_OUTCONTROL3, OnOutcontrol3)
	ON_BN_CLICKED(IDC_OUTCONTROL4, OnOutcontrol4)
	ON_BN_CLICKED(IDC_OUTCONTROL5, OnOutcontrol5)
	ON_BN_CLICKED(IDC_OUTCONTROL6, OnOutcontrol6)
	ON_BN_CLICKED(IDC_OUTCONTROL7, OnOutcontrol7)
	ON_BN_CLICKED(IDC_OUTCONTROL8, OnOutcontrol8)
	ON_BN_CLICKED(IDC_OUTCONTROL9, OnOutcontrol9)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPLC_DEMOView construction/destruction

CPLC_DEMOView::CPLC_DEMOView()
	: CFormView(CPLC_DEMOView::IDD)
{
	//{{AFX_DATA_INIT(CPLC_DEMOView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// TODO: add construction code here    
    fortime=this;
	fordraw=this;
    forsend=this;
	forrun=this;
}
CPLC_DEMOView::~CPLC_DEMOView()
{
}
void CPLC_DEMOView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPLC_DEMOView)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}
BOOL CPLC_DEMOView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}
void CPLC_DEMOView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
}

/////////////////////////////////////////////////////////////////////////////
// CPLC_DEMOView diagnostics

#ifdef _DEBUG
void CPLC_DEMOView::AssertValid() const
{
	CFormView::AssertValid();
}
void CPLC_DEMOView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CPLC_DEMODoc* CPLC_DEMOView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPLC_DEMODoc)));
	return (CPLC_DEMODoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CPLC_DEMOView message handlers

void CPLC_DEMOView::OnDraw(CDC* pDC) 
{
	// TODO: Add your specialized code here and/or call the base class
	initializedraw();
	if(objectcheckenable)
		draw_object_check();
	if(inputenable)	
		inputfetchdraw();
	if(outputenable)
		outputfetchdraw();
	if(autotruckenable)
		autotruckdraw();
	if(trafficlumpenable)
	   Traffic_lump_draw();
	if(candrawpoint)
		drawpoint();
}
void CPLC_DEMOView::OnInput1() 
{
	// TODO: Add your control notification handler code here
	if(inputenable)
	{
		inputcheck=true;
		inputfetchlink(0,1,71,36);
	}
}
void CPLC_DEMOView::OnSwitch1() 
{
	// TODO: Add your control notification handler code here
		if(inputenable)
		{
			switchcheck=true;
			inputfetchlink(1,0,136,36);
		}
		if (beginset)
		{
		GetDlgItem(IDC_SWITCH1)->SetWindowText(signinput[1]?"off":"on");
		signinput[1]=(signinput[1]?0:1);
		}

}
void CPLC_DEMOView::OnInput2() 
{
	// TODO: Add your control notification handler code here
	if(inputenable)
	{
		inputcheck=true;
		inputfetchlink(0,2,71,60);
	}
	
}
void CPLC_DEMOView::OnInput3() 
{
	// TODO: Add your control notification handler code here
	if(inputenable)
	{
		inputcheck=true;
		inputfetchlink(0,3,71,84);
	}
}
void CPLC_DEMOView::OnInput4() 
{
	// TODO: Add your control notification handler code here
	if(inputenable)
	{
		inputcheck=true;
		inputfetchlink(0,4,71,108);
	}
}
void CPLC_DEMOView::OnInput5() 
{
	// TODO: Add your control notification handler code here
	if(inputenable)
	{
		inputcheck=true;
		inputfetchlink(0,5,71,134);
	}
}
void CPLC_DEMOView::OnInput6() 
{
	// TODO: Add your control notification handler code here
	if(inputenable)
	{
		inputcheck=true;
		inputfetchlink(0,6,71,158);
	}
}
void CPLC_DEMOView::OnInput7() 
{
	// TODO: Add your control notification handler code here
	if(inputenable)
	{
		inputcheck=true;
		inputfetchlink(0,7,71,184);
	}
}
void CPLC_DEMOView::OnSwitch2() 
{
	// TODO: Add your control notification handler code here
	if(inputenable)
	{
		switchcheck=true;
	    inputfetchlink(2,0,136,60);
	}
	if (beginset)
	{
		GetDlgItem(IDC_SWITCH2)->SetWindowText(signinput[2]?"off":"on");
		signinput[2]=(signinput[2]?0:1);
	}
}
void CPLC_DEMOView::OnSwitch3() 
{
	// TODO: Add your control notification handler code here
	if(inputenable)
	{
		switchcheck=true;
		inputfetchlink(3,0,136,84);
	}
	if (beginset)
	{
		GetDlgItem(IDC_SWITCH3)->SetWindowText(signinput[3]?"off":"on");
		signinput[3]=(signinput[3]?0:1);
	}
}
void CPLC_DEMOView::OnSwitch4() 
{
	// TODO: Add your control notification handler code here
	if(inputenable)
	{
		switchcheck=true;
		inputfetchlink(4,0,136,108);
	}
	if (beginset)
	{
		GetDlgItem(IDC_SWITCH4)->SetWindowText(signinput[4]?"off":"on");
		signinput[4]=(signinput[4]?0:1);
	}
}
void CPLC_DEMOView::OnSwitch5() 
{
	// TODO: Add your control notification handler code here
	if(inputenable)
	{
		switchcheck=true;
		inputfetchlink(5,0,136,134);
	}
	if (beginset)
	{
		GetDlgItem(IDC_SWITCH5)->SetWindowText(signinput[5]?"off":"on");
		signinput[5]=(signinput[5]?0:1);
	}
}
void CPLC_DEMOView::OnSwitch6() 
{
	// TODO: Add your control notification handler code here
	if(inputenable)
	{
		switchcheck=true;
		inputfetchlink(6,0,136,158);
	}
	if (beginset)
	{
		GetDlgItem(IDC_SWITCH6)->SetWindowText(signinput[6]?"off":"on");
		signinput[6]=(signinput[6]?0:1);
	}
}
void CPLC_DEMOView::OnSwitch7() 
{
	// TODO: Add your control notification handler code here
	if(inputenable)
	{
		switchcheck=true;
		inputfetchlink(7,0,136,184);
	}
	if (beginset)
	{
		GetDlgItem(IDC_SWITCH7)->SetWindowText(signinput[7]?"off":"on");
		signinput[7]=(signinput[7]?0:1);
	}
}
void CPLC_DEMOView::OnOutput1() 
{
	// TODO: Add your control notification handler code here
	if(outputenable)
	{
		outputcheck=true;
		outputfetchlink(1,0,71,286);
	}
}
void CPLC_DEMOView::OnOutcontrol1() 
{
	// TODO: Add your control notification handler code here
	if(outputenable)
	{
		outcontrolcheck=true;
		outputfetchlink(0,1,136,286);
	}
	if (beginset)
	{
		GetDlgItem(IDC_OUTCONTROL1)->SetWindowText(signoutput[1]?"off":"on");
		signoutput[1]=(signoutput[1]?0:1);
	}
}
void CPLC_DEMOView::OnOutput2() 
{
	// TODO: Add your control notification handler code here
	if(outputenable)
	{
		outputcheck=true;
		outputfetchlink(2,0,71,311);
	}
}
void CPLC_DEMOView::OnOutput3() 
{
	// TODO: Add your control notification handler code here
	if(outputenable)
	{
		outputcheck=true;
		outputfetchlink(3,0,71,336);
	}
}
void CPLC_DEMOView::OnOutput4() 
{
	// TODO: Add your control notification handler code here
	if(outputenable)
	{
		outputcheck=true;
		outputfetchlink(4,0,71,360);
	}
}
void CPLC_DEMOView::OnOutput5() 
{
	// TODO: Add your control notification handler code here
	if(outputenable)
	{
		outputcheck=true;
		outputfetchlink(5,0,71,383);
	}
}
void CPLC_DEMOView::OnOutput6() 
{
	// TODO: Add your control notification handler code here
	if(outputenable)
	{
		outputcheck=true;
		outputfetchlink(6,0,71,408);
	}
}
void CPLC_DEMOView::OnOutput7() 
{
	// TODO: Add your control notification handler code here
	if(outputenable)
	{
		outputcheck=true;
		outputfetchlink(7,0,71,431);
	}
}
void CPLC_DEMOView::OnOutput8() 
{
	// TODO: Add your control notification handler code here
	if(outputenable)
	{
		outputcheck=true;
		outputfetchlink(8,0,71,456);
	}
}
void CPLC_DEMOView::OnOutput9() 
{
	// TODO: Add your control notification handler code here
	if(outputenable)
	{
		outputcheck=true;
		outputfetchlink(9,0,71,481);
	}
}
void CPLC_DEMOView::OnOutcontrol2() 
{
	// TODO: Add your control notification handler code here
	if(outputenable)
	{
		outcontrolcheck=true;
		outputfetchlink(0,2,136,311);	
	}
	if (beginset)
	{
	GetDlgItem(IDC_OUTCONTROL2)->SetWindowText(signoutput[2]?"off":"on");
	signoutput[2]=(signoutput[2]?0:1);
	}
}
void CPLC_DEMOView::OnOutcontrol3() 
{
	// TODO: Add your control notification handler code here
	if(outputenable)
	{
		outcontrolcheck=true;
		outputfetchlink(0,3,136,336);
	}
	if (beginset)
	{
		GetDlgItem(IDC_OUTCONTROL3)->SetWindowText(signoutput[3]?"off":"on");
		signoutput[3]=(signoutput[3]?0:1);
	}
}
void CPLC_DEMOView::OnOutcontrol4() 
{
	// TODO: Add your control notification handler code here
	if(outputenable)
	{
		outcontrolcheck=true;
		outputfetchlink(0,4,136,360);	
	}
	if (beginset)
	{
		GetDlgItem(IDC_OUTCONTROL4)->SetWindowText(signoutput[4]?"off":"on");
		signoutput[4]=(signoutput[4]?0:1);
	}
}
void CPLC_DEMOView::OnOutcontrol5() 
{
	// TODO: Add your control notification handler code here
	if(outputenable)
	{
		outcontrolcheck=true;
		outputfetchlink(0,5,136,383);	
	}
	if (beginset)
	{
		GetDlgItem(IDC_OUTCONTROL5)->SetWindowText(signoutput[5]?"off":"on");
		signoutput[5]=(signoutput[5]?0:1);
	}
}
void CPLC_DEMOView::OnOutcontrol6() 
{
	// TODO: Add your control notification handler code here
	if(outputenable)
	{
		outcontrolcheck=true;
		outputfetchlink(0,6,136,408);
	}
	if (beginset)
	{
		GetDlgItem(IDC_OUTCONTROL6)->SetWindowText(signoutput[6]?"off":"on");
		signoutput[6]=(signoutput[6]?0:1);
	}
}
void CPLC_DEMOView::OnOutcontrol7() 
{
	// TODO: Add your control notification handler code here
	if(outputenable)
	{
		outcontrolcheck=true;
		outputfetchlink(0,7,136,431);
	}
	if (beginset)
	{
		GetDlgItem(IDC_OUTCONTROL7)->SetWindowText(signoutput[7]?"off":"on");
		signoutput[7]=(signoutput[7]?0:1);
	}
}

void CPLC_DEMOView::OnOutcontrol8() 
{
	// TODO: Add your control notification handler code here
	if(outputenable)
	{
		outcontrolcheck=true;
		outputfetchlink(0,8,136,456);
	}
	if (beginset)
	{
		GetDlgItem(IDC_OUTCONTROL8)->SetWindowText(signoutput[8]?"off":"on");
		signoutput[8]=(signoutput[8]?0:1);
	}
}
void CPLC_DEMOView::OnOutcontrol9() 
{
	// TODO: Add your control notification handler code here
	if(outputenable)
	{
		outcontrolcheck=true;
		outputfetchlink(0,9,136,481);
	}
	if (beginset)
	{
		GetDlgItem(IDC_OUTCONTROL9)->SetWindowText(signoutput[9]?"off":"on");
		signoutput[9]=(signoutput[9]?0:1);
	}
}
void CPLC_DEMOView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if((nIDEvent>=1)&&(nIDEvent<=8))
	{
		T[nIDEvent]=true;
		KillTimer(nIDEvent);
	}
	if(nIDEvent==10)
	{
		if (fillerstartpoint<=fillerendpoint)
		{
			KillTimer(10);
		    fillerloadenable=true;
		}
		else
			fillerstartpoint-=1;
	}
	if(nIDEvent==11)
	{
		if(thetruckpoint<=660)
			KillTimer(11);
		else thetruckpoint-=5;
	}
	if(nIDEvent==12)
	{
		if (truckloadpoint<=436)
		{
			KillTimer(12);
			weighto=true;
		}
		else
		{
		fillerstartpoint+=2;
        truckloadpoint-=2;
		}	
	}
	if(nIDEvent==13)
	{
		if(thetruckpoint>=1000)
		{
			KillTimer(13);
			weighto=false;
			canload=true;
			truckinenable=true;
			truckloadpoint=459;
		}
		else
			thetruckpoint+=3;
	}
	if(nIDEvent==14)
		canclearthetruck=true;
	if(nIDEvent==15)
		WR[91]=(WR[91]?false:true);
    if(nIDEvent==17)
	{	
		goodsarrive=true;
		canshow1=true;
	}
	if(nIDEvent==18)
	{
		KillTimer(18);
		sensorshow1=false;
		sensorshow2=false;
	}
	if(nIDEvent==19)
	{
		KillTimer(19);
		sensorshow3=false;
	}
	if(nIDEvent==20)
	{
		cancleargoods=true;
	    thegoodsplace+=2;
	}
	if(nIDEvent==23)
	{
		if(wasterplace>=315)
		{
			KillTimer(23);
			downthewaster=false;
			thesensor3true=true;
			canshow2=true;
		}
		else wasterplace+=20;
	}
	if(nIDEvent==25)
	{
		KillTimer(25);
		SetTimer(26,10,NULL);		
	}
	if(nIDEvent==26)
	{
		downqualitygoods=true;
		if(qualitygoodsplace>=310)
		{
			KillTimer(26);
			downqualitygoods=false;
			qualitygoodsplace=195;
		}
		else qualitygoodsplace+=20;
	}
	CFormView::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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