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

📄 run_auto_truck_load.cpp

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

#include "PLC_DEMODoc.h"
#include "PLC_DEMOView.h"
#include "Fetch_communicate.h"
#include "Makesure_in_out_point.h"
#include "Draw_function.h"

int fillerstartpoint;
int fillerendpoint;
int thetruckpoint;
int truckloadpoint;
int m1,m2,m3;
bool fillerloadenable;
bool truckinenable;
bool canclearthetruck;
bool truckcanout;
bool canload;
bool weighto;
bool wheelredraw1;
bool wheelredraw2;
bool wheelredraw3;
bool wheelsign1,wheelsign2,wheelsign3;
bool clearexit1=true;

extern CPLC_DEMOView *forrun;
extern int forautotruckinput[2];
extern int forautotruckoutput[7];
extern int signinput[8];
extern int signoutput[10];

void clearpart(int,int,int,int,CBrush*,CDC*);
void drawround(int,int,int,int,CDC*);

void auto_truck_startset()
{
	fillerstartpoint=139;
	fillerendpoint=82;
	thetruckpoint=1000;
    truckloadpoint=459;
    m1=1,m2=1,m3=1;
    fillerloadenable=true;
    truckinenable=true;
    canclearthetruck=true;
    truckcanout=true;
    canload=true;
    weighto=false;
    wheelredraw1=true;
    wheelredraw2=true;
    wheelredraw3=true;
	forrun->SetTimer(14,50,NULL);
}
void auto_truck_outresult()
{
	CDC* thisDC=forrun->GetDC();
	CPen blackpen(PS_SOLID,1,RGB(0,0,0));
	CPen *oldpen=thisDC->SelectObject(&blackpen);
	CBrush blackbrush(RGB(0,0,0));
	CBrush* oldbrush=thisDC->SelectObject(&blackbrush);
	CBrush nobrush;
	nobrush.CreateSysColorBrush(COLOR_3DFACE);
	thisDC->SetBkMode(TRANSPARENT);
	if(!signoutput[forautotruckoutput[0]])
	{
		drawround(485,42,8,8,thisDC);
		clearpart(411,48,9,3,&blackbrush,thisDC);//开关一
		if(clearexit1)
		{
			clearpart(411,92,9,42,&nobrush,thisDC);
	        clearexit1=false;
		}
	}
	if(!signinput[forautotruckinput[0]])
		drawround(485,80,8,8,thisDC);
	if(!signoutput[forautotruckoutput[1]])
	{
		clearpart(431,214,51,7,&nobrush,thisDC);
	    clearpart(480,268,49,7,&nobrush,thisDC);
		clearpart(531,323,51,7,&nobrush,thisDC);
		drawround(485,150,8,8,thisDC);
        clearpart(411,143,14,3,&blackbrush,thisDC);
        clearpart(411,183,14,37,&nobrush,thisDC);
	    thisDC->MoveTo(390,200);
	    thisDC->LineTo(490,200);	
	    clearpart(480,240,12,31,&nobrush,thisDC);
	    thisDC->MoveTo(450,238);
	    thisDC->LineTo(492,215);
	    thisDC->MoveTo(440,255);
	    thisDC->LineTo(540,255);
	    clearpart(525,295,14,35,&nobrush,thisDC);
	    thisDC->MoveTo(500,293);
	    thisDC->LineTo(542,270);
	    thisDC->MoveTo(490,309);
	    thisDC->LineTo(590,309);
		clearpart(580,375,12,60,&nobrush,thisDC);
	    thisDC->MoveTo(550,348);
	    thisDC->LineTo(592,325);
	}
	if(!signoutput[forautotruckoutput[4]])
	{
		if(wheelredraw1)
		{
			thisDC->SelectObject(&nobrush);
			clearpart(420,218,80,22,&nobrush,thisDC);
			drawround(350,230,8,8,thisDC);
            drawround(350,230,4,4,thisDC);//轮一
			drawround(450,230,8,8,thisDC);//轮二
		    drawround(450,230,4,4,thisDC);
			CString forelect="电机M1";
            thisDC->TextOut(333,255,forelect);
			thisDC->MoveTo(350,222);//皮带一
	        thisDC->LineTo(450,222);
	        thisDC->MoveTo(350,238);
	        thisDC->LineTo(450,238);
	        thisDC->LineTo(492,215);
	        thisDC->MoveTo(350,222);
	        thisDC->LineTo(390,200);
	        thisDC->LineTo(490,200);
	        thisDC->MoveTo(350,238);
	        thisDC->LineTo(380,222);
	        thisDC->MoveTo(350,230);//轴线一
	        thisDC->LineTo(320,250);
		    CPoint round3(490,208);
	        CRect rect5(round3,round3);
	        rect5.InflateRect(8,8);
	        CPoint round4(490,200);
	        CPoint round5(491,214);
	        thisDC->Arc(rect5,round5,round4);//圆弧一
	     	wheelredraw1=false;
		}
		drawround(315,257,8,8,thisDC);
	}
	if(!signoutput[forautotruckoutput[5]])
	{
		if(wheelredraw2)
		{
			thisDC->SelectObject(&nobrush);
			clearpart(470,273,80,22,&nobrush,thisDC);
            drawround(400,285,8,8,thisDC);//轮三
			drawround(400,285,4,4,thisDC);
	        thisDC->MoveTo(400,285);//轴线二
	        thisDC->LineTo(370,305);
	        CString forelect="电机M2";
            thisDC->TextOut(382,310,forelect);
			drawround(500,285,8,8,thisDC);//轮四
		    drawround(500,285,4,4,thisDC);
	        thisDC->MoveTo(400,277);//皮带二
	        thisDC->LineTo(500,277);
        	thisDC->MoveTo(400,293);
	        thisDC->LineTo(500,293);
	        thisDC->LineTo(542,270);
	        thisDC->MoveTo(400,277);
	        thisDC->LineTo(440,255);
	        thisDC->LineTo(540,255);
	        thisDC->MoveTo(400,293);
	        thisDC->LineTo(430,277);
	        CPoint round8(540,263);//圆弧二
	        CRect rect10(round8,round8);
	        rect10.InflateRect(8,8);
	        CPoint round9(540,255);
	        CPoint round10(541,271);
        	thisDC->Arc(rect10,round10,round9);//滑轮2
		    wheelredraw2=false;
		}
		drawround(365,312,8,8,thisDC);
	}
	if(!signoutput[forautotruckoutput[6]])
	{
		if(wheelredraw3)
		{
       		thisDC->SelectObject(&nobrush);
			clearpart(520,327,80,22,&nobrush,thisDC);
			drawround(450,340,8,8,thisDC);//轮五
			drawround(450,340,4,4,thisDC);
	        thisDC->MoveTo(450,340);//轴线三
	        thisDC->LineTo(420,360);
	        CString forelect="电机M3";
            thisDC->TextOut(432,364,forelect);
			drawround(550,340,8,8,thisDC);//轮六
			drawround(550,340,4,4,thisDC);
	        thisDC->MoveTo(450,332);//皮带三
	        thisDC->LineTo(550,332);
	        thisDC->MoveTo(450,348);
	        thisDC->LineTo(550,348);
	        thisDC->LineTo(592,325);
	        thisDC->MoveTo(450,332);
        	thisDC->LineTo(490,309);
	        thisDC->LineTo(590,309);
	        thisDC->MoveTo(450,348);
	        thisDC->LineTo(480,332);
	        CPoint round13(590,318);//圆弧三
	        CRect rect15(round13,round13);
	        rect15.InflateRect(8,8);
	        CPoint round14(590,309);
	        CPoint round15(591,325);
	        thisDC->Arc(rect15,round15,round14);//滑轮3
    		wheelredraw3=false;
		}
		drawround(415,367,8,8,thisDC);
    }
	if(!signinput[forautotruckinput[1]])
		drawround(630,505,8,8,thisDC);
	if(!signoutput[forautotruckoutput[2]])
		drawround(400,450,8,8,thisDC);
	if(!signoutput[forautotruckoutput[3]])
		drawround(400,470,8,8,thisDC);
  
    CPen redpen(PS_SOLID,1,RGB(255,0,0));
	thisDC->SelectObject(&redpen);
	CBrush redbrush(RGB(255,0,0));
	thisDC->SelectObject(&redbrush);

	if(signoutput[forautotruckoutput[0]])
	{
		clearexit1=true;
		drawround(485,42,8,8,thisDC);
	}
	if(signinput[forautotruckinput[0]])
		drawround(485,80,8,8,thisDC);
	if(signoutput[forautotruckoutput[1]])
		drawround(485,150,8,8,thisDC);
	if(signoutput[forautotruckoutput[4]])
	{
		wheelredraw1=true;
		drawround(315,257,8,8,thisDC);
	}
	if(signoutput[forautotruckoutput[5]])
	{
		wheelredraw2=true;
		drawround(365,312,8,8,thisDC);
	}
	if(signoutput[forautotruckoutput[6]])
	{
		wheelredraw3=true;
		drawround(415,367,8,8,thisDC);
    }
    if(signinput[forautotruckinput[1]])
		drawround(630,505,8,8,thisDC);
	
	if(signoutput[forautotruckoutput[2]])
		drawround(400,450,8,8,thisDC);
	if(signoutput[forautotruckoutput[3]])
		drawround(400,470,8,8,thisDC);

	CPen fleetredpen(PS_DOT,1,RGB(200,100,0));//料线
	thisDC->SelectObject(&fleetredpen);
    
    if((signoutput[forautotruckoutput[0]])||(signoutput[forautotruckoutput[1]]))
		clearpart(410,105,49,34,&nobrush,thisDC);

	if(signoutput[forautotruckoutput[0]])
	{
		clearpart(411,48,9,3,&nobrush,thisDC);
		thisDC->MoveTo(403,45);
    	thisDC->LineTo(403,fillerstartpoint);
    	thisDC->MoveTo(405,45);
    	thisDC->LineTo(405,fillerstartpoint);
    	thisDC->MoveTo(407,45);
	    thisDC->LineTo(407,fillerstartpoint);
     	thisDC->MoveTo(409,45);
	    thisDC->LineTo(409,fillerstartpoint);
    	thisDC->MoveTo(411,45);
	    thisDC->LineTo(411,fillerstartpoint);
    	thisDC->MoveTo(413,45);
    	thisDC->LineTo(413,fillerstartpoint);
	    thisDC->MoveTo(415,45);
    	thisDC->LineTo(415,fillerstartpoint);
      	thisDC->MoveTo(417,45);
    	thisDC->LineTo(417,fillerstartpoint);
	}
	for(int i=fillerstartpoint;i<=139;i++)
	{
		if(i%2==0)
		{
			thisDC->MoveTo(360,i);
			thisDC->LineTo(458,i);
		}
		else
		{
			thisDC->MoveTo(362,i);
			thisDC->LineTo(460,i);
		}
	}
	if(signoutput[forautotruckoutput[1]])
	{
		clearpart(411,143,14,3,&nobrush,thisDC);	
		thisDC->MoveTo(398,139);
     	thisDC->LineTo(398,215);
    	thisDC->MoveTo(403,139);
    	thisDC->LineTo(403,213);
        thisDC->MoveTo(408,139);
	    thisDC->LineTo(408,212);
    	thisDC->MoveTo(413,139);
    	thisDC->LineTo(413,211);
 	    thisDC->MoveTo(418,139);
	    thisDC->LineTo(418,210);
	    thisDC->MoveTo(423,139);
    	thisDC->LineTo(423,208);

		thisDC->MoveTo(404,207);
		thisDC->LineTo(480,207);
		thisDC->LineTo(478,262);
    	thisDC->MoveTo(400,211);
		thisDC->LineTo(475,211);
		thisDC->LineTo(474,266);
		thisDC->MoveTo(395,215);
		thisDC->LineTo(470,215);
		thisDC->LineTo(470,270);

		thisDC->MoveTo(478,262);
		thisDC->LineTo(530,262);
		thisDC->LineTo(530,316);
		thisDC->MoveTo(474,266);
		thisDC->LineTo(525,266);
		thisDC->LineTo(526,320);
		thisDC->MoveTo(470,270);
		thisDC->LineTo(520,270);
		thisDC->LineTo(522,324);

		thisDC->MoveTo(530,316);
		thisDC->LineTo(580,316);
		thisDC->MoveTo(526,320);
		thisDC->LineTo(576,320);
		thisDC->MoveTo(522,324);
		thisDC->LineTo(572,324);
		
		thisDC->MoveTo(580,316);
		thisDC->LineTo(580,truckloadpoint);
		thisDC->MoveTo(576,320);
		thisDC->LineTo(576,truckloadpoint);
		thisDC->MoveTo(572,324);
		thisDC->LineTo(572,truckloadpoint);
	}
	thisDC->SelectObject(&blackpen);
	thisDC->SelectObject(&nobrush);

	if(signoutput[forautotruckoutput[4]])
	{
		wheelsign1=(wheelsign1?false:true);	
		if (m1==5)
		{
			if(wheelsign1)
			{
				drawround(350,230,7,8,thisDC);
			    drawround(350,230,3,4,thisDC);
			    drawround(450,230,7,8,thisDC);
			    drawround(450,230,3,4,thisDC);
			}
			else
			{
			    drawround(350,230,8,7,thisDC);
			    drawround(350,230,4,3,thisDC);//轮一//轮二
			    drawround(450,230,8,7,thisDC);
			    drawround(450,230,4,3,thisDC);
			}
		}
		m1=m1+1;
		if (m1>5)
			m1=1;		
		thisDC->MoveTo(350,230);//轴线一
	    thisDC->LineTo(320,250);
	}
	if(signoutput[forautotruckoutput[5]])
	{
		 if(m2==5)
		 {
			 wheelsign2=(wheelsign2?false:true);
		     if(wheelsign2)
			 {
				 drawround(400,285,7,8,thisDC);//轮三
			     drawround(400,285,3,4,thisDC);
			     drawround(500,285,7,8,thisDC);//轮四
			     drawround(500,285,3,4,thisDC);
			 }
			 else
			 {                                 
			     drawround(400,285,8,7,thisDC); //轮三
			     drawround(400,285,4,3,thisDC);
			     drawround(500,285,8,7,thisDC);//轮四
				 drawround(500,285,4,3,thisDC);
			 }
		 }
		 m2=m2+1;
	   	 if (m2>5)
			m2=1;
		 thisDC->MoveTo(400,285);//轴线二
	     thisDC->LineTo(370,305);
	 }
	 if(signoutput[forautotruckoutput[6]])
	 {
		 if(m3==5)
		 {
			 wheelsign3=(wheelsign3?false:true);
		     if(wheelsign3)
			 {
				 drawround(450,340,7,8,thisDC);//轮五
			     drawround(450,340,3,4,thisDC);
			     drawround(550,340,7,8,thisDC); //轮六
			     drawround(550,340,3,4,thisDC);
			 }
		     else
			 {	
				 drawround(450,340,8,7,thisDC); //轮五
			     drawround(450,340,4,3,thisDC);
			     drawround(550,340,8,7,thisDC);//轮六
			     drawround(550,340,4,3,thisDC);
			 }
		 }
		 m3=m3+1;
		 	if (m3>5)
				m3=1;
		 	thisDC->MoveTo(450,340);//轴线三
	        thisDC->LineTo(420,360);
	 }
	 if(fillerstartpoint<=fillerendpoint)
		 signinput[forautotruckinput[0]]=1;	 
	 else signinput[forautotruckinput[0]]=0;

	 if((fillerloadenable)&&(signoutput[forautotruckoutput[0]]))
	 {
		 fillerloadenable=false;
		 forrun->SetTimer(10,150,NULL);
	 }
	 if((thetruckpoint<=660)&&(!weighto))
		 signinput[forautotruckinput[1]]=1;
	 else signinput[forautotruckinput[1]]=0;
	 if(((truckinenable)&&(signoutput[forautotruckoutput[3]]))
		 &&(!signoutput[forautotruckoutput[2]]))
	 {
		 truckcanout=true;
		 forrun->SetTimer(11,50,NULL);
		 truckinenable=false;
	 }
	 if(signoutput[forautotruckoutput[1]])
	 {
		 if(canload)
		 {
			 forrun->SetTimer(12,150,NULL);
			 canload=false;
		 }
	 }
	 if(((signoutput[forautotruckoutput[3]])
		 &&(!signoutput[forautotruckoutput[2]]))
		 &&((weighto)&&(truckcanout)))
	 {
		 truckcanout=false;
		 forrun->SetTimer(13,50,NULL);
	 }
	 thisDC->SelectObject(&blackpen);
	 if(canclearthetruck)
	 {
		 canclearthetruck=false;
	     clearpart(700,440,240,48,&nobrush,thisDC);
	     thisDC->MoveTo(thetruckpoint-20,470);
	     thisDC->LineTo(thetruckpoint,470);
	     thisDC->LineTo(thetruckpoint,440);
	     thisDC->LineTo(thetruckpoint-20,410);
	     thisDC->LineTo(thetruckpoint-50,410);
	     thisDC->LineTo(thetruckpoint-50,470);
	 
	     thisDC->MoveTo(thetruckpoint-10,440);
   	     thisDC->LineTo(thetruckpoint-45,440);
	     thisDC->LineTo(thetruckpoint-45,420);
	     thisDC->LineTo(thetruckpoint-23,420);
	     thisDC->LineTo(thetruckpoint-10,440);

	     thisDC->MoveTo(thetruckpoint-50,435);
	     thisDC->LineTo(thetruckpoint-150,435);
	     thisDC->LineTo(thetruckpoint-150,460);
	     thisDC->LineTo(thetruckpoint-50,460);
	     thisDC->MoveTo(thetruckpoint-100,460);
	     thisDC->LineTo(thetruckpoint-100,475);
	     thisDC->MoveTo(thetruckpoint-127,460);
	     thisDC->LineTo(thetruckpoint-127,475);

	     thisDC->SelectObject(&nobrush);
	     CPoint carfront(thetruckpoint-35,475);
	     CRect car1(carfront,carfront);
	     car1.InflateRect(15,15);
	     CPoint carfront1(thetruckpoint-20,470);
	     CPoint carfront2(thetruckpoint-50,470);
	     thisDC->Arc(car1,carfront1,carfront2);

	     CPoint carpoint1(thetruckpoint-35,476);
	     CRect carwheel1(carpoint1,carpoint1);
	     carwheel1.InflateRect(12,12);
	     thisDC->Ellipse(carwheel1);
	     carwheel1.DeflateRect(6,6);
	     thisDC->Ellipse(carwheel1);

	     drawround(thetruckpoint-113,476,12,12,thisDC);
         drawround(thetruckpoint-113,476,6,6,thisDC);
	     thisDC->SelectObject(&fleetredpen);	 
		 for(i=truckloadpoint;i<459;i++)
		 {
		  	 if(i%2==0)
			 {
			  	 thisDC->MoveTo(thetruckpoint-51,i);
		   	     thisDC->LineTo(thetruckpoint-147,i);
			 }
		     else
			 {
				 thisDC->MoveTo(thetruckpoint-53,i);
		         thisDC->LineTo(thetruckpoint-149,i);		
			 }
		 }
	 }

	 
	thisDC->SelectObject(oldbrush);
	thisDC->SelectObject(oldpen);
	forrun->ReleaseDC(thisDC);
}

⌨️ 快捷键说明

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