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

📄 水箱实验view.cpp

📁 这是一个水箱的液位控制程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// 水箱实验View.cpp : implementation of the CMyView class//#include "stdafx.h"#include "水箱实验.h"#include <math.h>#include"afxwin.h"#include "水箱实验Doc.h"#include "水箱实验View.h"#include "caiyang.h"#include "PIDDlg.h"#include "ControlerSet.h"#include "setsv.h"#include "DataPort.h"#include "historydata.h"#include "delaytime.h"#include "updownlimit.h"#include "warninglimit.h"#include "Drawfilter.h"#include "Arom1.h"#include "Arom2.h"#include "seriesoption.h"#include "IdentifyDlg.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endifDataPort mDataport;
float zanshi1[65535];
int yanchi1=0;int zanshi1_shu=0;
float yellowv=4,yellov_backup=4;
float limit=4;
int dmconce=0;
float zanshi2[65535];
int yanchi2=0;
int zanshi2_shu=0;
float yellowv2=4,yellov2_backup=4;
/////////////////////////////////////////////////////////////////////////////// CMyViewIMPLEMENT_DYNCREATE(CMyView, CFormView)BEGIN_MESSAGE_MAP(CMyView, CFormView)	//{{AFX_MSG_MAP(CMyView)	ON_BN_CLICKED(IDC_TIME, OnTime)	ON_COMMAND(ID_OPTION_TIME, OnOptionTime)	ON_BN_CLICKED(IDC_PID, OnPid)	ON_COMMAND(ID_OPTION_PID, OnOptionPid)	ON_BN_CLICKED(IDC_CONTROLER, OnControler)	ON_COMMAND(ID_OPTION_CONTROLSET, OnOptionControlset)	ON_COMMAND(ID_OPTION_SETSV, OnOptionSetsv)	ON_WM_TIMER()	ON_BN_CLICKED(IDC_LEFTSCROLLPAGE, OnLeftscrollpage)	ON_BN_CLICKED(IDC_RIGHTSCROLLPAGE, OnRightscrollpage)	ON_WM_DESTROY()	ON_BN_CLICKED(IDC_START, OnStart)	ON_BN_CLICKED(IDC_STOP, OnStop)	ON_BN_CLICKED(IDC_LEFTSCROLL, OnLeftscroll)	ON_BN_CLICKED(IDC_RIGHTSCROLL, OnRightscroll)	ON_BN_CLICKED(IDC_AORM, OnAorm)	ON_WM_LBUTTONDOWN()	ON_WM_LBUTTONUP()	ON_WM_MOUSEMOVE()	ON_BN_CLICKED(IDC_SAVE, OnSave)	ON_BN_CLICKED(IDC_READ, OnRead)	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)	ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)	ON_BN_CLICKED(IDC_HISTORYDATA, OnHistorydata)	ON_COMMAND(ID_OPTION_HISTORYDATA, OnOptionHistorydata)	ON_COMMAND(ID_SYSTEM_UPDOWNLIMIT, OnSystemUpdownlimit)	ON_COMMAND(ID_SYSTEM_WARNINGLIMIT, OnSystemWarninglimit)	ON_BN_CLICKED(IDC_AORM2, OnAorm2)	ON_COMMAND(ID_SYSTEM_DELAYTIME, OnSystemDelaytime)	ON_COMMAND(ID_SYSTEM_DRAWFILTER, OnSystemDrawfilter)	ON_COMMAND(ID_OPTION_SERIES, OnOptionSeries)	ON_BN_CLICKED(IDC_IDENTIFY, OnIdentify)	ON_BN_CLICKED(IDC_SAVETXT3, OnSavetxt3)	//}}AFX_MSG_MAP	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CMyView construction/destruction
CMyView::CMyView()
	: CFormView(CMyView::IDD)
{
	//{{AFX_DATA_INIT(CMyView)
		// NOTE: the ClassWizard will add member initialization here	
	//}}AFX_DATA_INIT
	// TODO: add construction code here
}CMyView::~CMyView(){}void CMyView::DoDataExchange(CDataExchange* pDX){	CFormView::DoDataExchange(pDX);	//{{AFX_DATA_MAP(CMyView)		// NOTE: the ClassWizard will add DDX and DDV calls here	//}}AFX_DATA_MAP}BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs){	// TODO: Modify the Window class or styles here by modifying	//  the CREATESTRUCT cs	return CFormView::PreCreateWindow(cs);}void CMyView::OnInitialUpdate(){	CFormView::OnInitialUpdate();	GetParentFrame()->RecalcLayout();	ResizeParentToFit();}/////////////////////////////////////////////////////////////////////////////// CMyView diagnostics#ifdef _DEBUGvoid CMyView::AssertValid() const{	CFormView::AssertValid();}void CMyView::Dump(CDumpContext& dc) const{	CFormView::Dump(dc);}CMyDoc* CMyView::GetDocument() // non-debug version is inline{	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));	return (CMyDoc*)m_pDocument;}#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////// CMyView message handlersvoid CMyView::OnDraw(CDC* pDC) {	// TODO: Add your specialized code here and/or call the base class	pDC->SetMapMode(MM_TEXT);		CRect rcClient;		CRect fRect(50,69,850,320);     //定义曲线图操作区域		CRect fRect1(50,369,850,620);	CRect fRectbang(920,45,1000,325);     //定义棒图操作区域		CRect fRectbang1(920,345,1000,625);	CRect fRectwaring1(920,46,1000,63);	CRect fRectwaring2(920,346,1000,363);		CBrush br(RGB(120,100,80));	CBrush brr(RGB(0,0,0));  //CBrush brr(RGB(255,255,255));            //论文打印时改变	CBrush brr1(RGB(m_showbkwhite1?255:0,m_showbkwhite1?255:0,m_showbkwhite1?255:0));	CBrush brr2(RGB(m_showbkwhite2?255:0,m_showbkwhite2?255:0,m_showbkwhite2?255:0));	CBrush brBlack(RGB(0,255,0));	GetClientRect(&rcClient);	pDC->FillRect(rcClient,&br);	pDC->FillRect(fRect,&brr1);     //曲线区	pDC->FillRect(fRect1,&brr2);	pDC->FillRect(fRectbang,&brr);      //棒区	pDC->FillRect(fRectbang1,&brr);	pDC->SetBkColor(RGB(120,100,80));	pDC->SetTextColor(RGB(0,255,255));    rcClient.DeflateRect(2,2);		CPen pen,*old,penyellow,penred,pengray,penwhite;	pen.CreatePen(PS_SOLID,1,RGB(0,255,255));	penyellow.CreatePen(PS_SOLID,1,RGB(255,255,0));	penred.CreatePen(PS_SOLID,1,RGB(255,0,0));	penwhite.CreatePen(PS_SOLID,1,RGB(255,255,255));	pengray.CreatePen(PS_SOLID,1,RGB(192,192,192));	old=pDC->SelectObject(&pen);	pDC->MoveTo(49,68);              //绘图区框	pDC->LineTo(49,321);	pDC->LineTo(851,321);	pDC->LineTo(851,68);	pDC->LineTo(49,68);	pDC->MoveTo(49,368);	pDC->LineTo(49,621);	pDC->LineTo(851,621);	pDC->LineTo(851,368);	pDC->LineTo(49,368);	pDC->MoveTo(919,44);                //棒图框	pDC->LineTo(919,326);	pDC->LineTo(1001,326);	pDC->LineTo(1001,44);	pDC->LineTo(919,44);	pDC->MoveTo(919,344);	pDC->LineTo(919,626);	pDC->LineTo(1001,626);	pDC->LineTo(1001,344);	pDC->LineTo(919,344);    //画网格1    int i=50;	int j=370;	int k=0;	do 	{   i=i+50;	    k=k+1; 	    CString mystring(" ");		mystring.Format("%d",int((k*10+start/5)*m_time/1000*5));		pDC->MoveTo(i,322);        pDC->LineTo(i,328);		pDC->TextOut(i-20,330,mystring);	}while(i<850);	CString mystring("(s)");	pDC->TextOut(i+20,330,mystring);    i=50;	do 	{   i=i+25;	    k=k+1; 	    pDC->MoveTo(i,320);		pDC->LineTo(i,324);	}	while(i<850);    	k=0;    do	{		j=j-50;		CString mystring(" ");	    mystring.Format("%d",k);    	pDC->TextOut(20,j-10-5,mystring);	    k=k+20;    	pDC->MoveTo(48,j); 	    pDC->LineTo(44,j);	}while(j>70);		pDC->TextOut(43,52,"(%)");			    //画网格2    int iOther=50;	int jOther=670;	int kOther=0;	do 	{   iOther=iOther+50;	    kOther=kOther+1; 	    CString mystring(" ");		mystring.Format("%d",(kOther*10+start/5)*m_time/1000*5);		pDC->MoveTo(iOther,622);        pDC->LineTo(iOther,627);		pDC->TextOut(iOther-20,628,mystring);	}while(iOther<850);	CString mystringOther("(s)");	pDC->TextOut(iOther+20,628,mystringOther);    iOther=50;	do 	{   iOther=iOther+25;	    kOther=kOther+1; 	    pDC->MoveTo(iOther,620);		pDC->LineTo(iOther,624);	}	while(iOther<850);    	kOther=0;    do	{		jOther=jOther-50;		CString mystring(" ");	    mystring.Format("%d",kOther);    	pDC->TextOut(20,jOther-10-5,mystring);	    kOther=kOther+20;    	pDC->MoveTo(48,jOther); 	    pDC->LineTo(44,jOther);	}while(jOther>370);	pDC->TextOut(43,350,"(%)");	//画棒图区:	pDC->SelectObject(&penyellow);	pDC->MoveTo(945,70);	pDC->LineTo(945,320);	pDC->MoveTo(945,370);	pDC->LineTo(945,620);	pDC->SelectObject(&penred);	pDC->MoveTo(975,70);	pDC->LineTo(975,320);	pDC->MoveTo(975,370);	pDC->LineTo(975,620);	pDC->SelectObject(&pengray);	pDC->MoveTo(935,70);	pDC->LineTo(935,320);	pDC->MoveTo(935,370);	pDC->LineTo(935,620);	pDC->MoveTo(940,70);	pDC->LineTo(940,320);	pDC->MoveTo(940,370);	pDC->LineTo(940,620);	pDC->MoveTo(980,70);	pDC->LineTo(980,320);	pDC->MoveTo(980,370);	pDC->LineTo(980,620);	pDC->MoveTo(985,70);	pDC->LineTo(985,320);	pDC->MoveTo(985,370);	pDC->LineTo(985,620);	pDC->SelectObject(&penwhite);	for(int loopshow=0;loopshow<=5;loopshow++)	{		pDC->MoveTo(976,70+loopshow*50);		pDC->LineTo(980,70+loopshow*50);		pDC->MoveTo(940,70+loopshow*50);		pDC->LineTo(945,70+loopshow*50);	}	for(int loopshowOther=0;loopshowOther<=5;loopshowOther++)	{		pDC->MoveTo(976,370+loopshowOther*50);		pDC->LineTo(980,370+loopshowOther*50);		pDC->MoveTo(940,370+loopshowOther*50);		pDC->LineTo(945,370+loopshowOther*50);	}	//////////bang:	if(320-int((PvDataValue-1)*50*1.25)<=320)	{		CRect BangShow(950,320-int((PvDataValue-1)*50*1.25),970,320);		pDC->FillRect(BangShow,&brBlack);	}	else	{		CRect BangShow(950,320,970,320);		pDC->FillRect(BangShow,&brBlack);		//加入采样错误代码:	}		if(620-int((PvDataValueOther-1)*50*1.25)<=620)	{		CRect BangShow1(950,620-int((PvDataValueOther-1)*50*1.25),970,620);		pDC->FillRect(BangShow1,&brBlack);	}	else	{		CRect BangShow1(950,620-int((PvDataValueOther-1)*50*1.25),970,620);		pDC->FillRect(BangShow1,&brBlack);	}		///////三角标显示:	SetMv(int((U1-4)*4095/16));	SetMv1(int((U2-4)*4095/16));	SetSv(int((m_getsetsv1-1000)*4095/4000));	SetSv1(int((m_getsetsv2-1000)*4095/4000));		//报警:	if(datanumber>0)	{	if(PvData[datanumber-1]>(float(m_downwarning1)/1000)&&PvData[datanumber-1]<(float(m_upwarning1)/1000))	{		pDC->SetTextColor(RGB(255,255,0));		pDC->SetBkColor(RGB(0,0,0));//pDC->SetBkColor(RGB(255,255,255));////论文打印时改变		pDC->TextOut(940,48,"正常");		}	else	{		pDC->SetTextColor(RGB(255,0,0));		pDC->SetBkColor(RGB(0,0,0));	//pDC->SetBkColor(RGB(255,255,255));//论文打印时改变               		pDC->TextOut(940,48,"警告");	}	if(PvDataOther[datanumber-1]>(float(m_downwarning2)/1000)&&PvDataOther[datanumber-1]<(float(m_upwarning2)/1000))	{		pDC->SetTextColor(RGB(255,255,0));		pDC->SetBkColor(RGB(0,0,0));        //	pDC->SetBkColor(RGB(255,255,255));//论文打印时改变		pDC->TextOut(940,348,"正常");		}	else	{		pDC->SetTextColor(RGB(255,0,0));		pDC->SetBkColor(RGB(0,0,0));           //pDC->SetBkColor(RGB(255,255,255));//论文打印时改变	               		pDC->TextOut(940,348,"警告");	}	}	pDC->SelectObject(old);	}void CMyView::OnTime() {	// TODO: Add your control notification handler code here	Ccaiyang dlg;	dlg.m_time=m_time;	if(dlg.DoModal()==IDOK)	{	m_time=(dlg.m_time/500)*500;	if(m_time==0)		m_time=500;	CRect Rect3(80,330,872,345);	InvalidateRect(&Rect3,NULL);	CRect Rect4(80,630,872,645);	InvalidateRect(&Rect4,NULL);	}	}BOOL CMyView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) {	// TODO: Add your specialized code here and/or call the base class	//绘图和滤波参数:    m_hidemv1=NULL;	m_hidemv2=NULL;	m_hidepv1=NULL;	m_hidepv2=NULL;	m_hidesv1=NULL;	m_hidesv2=NULL;	m_showbkwhite1=NULL;	m_showbkwhite2=NULL;	m_getfilternun1=0.5;              //数字滤波参数 	m_getfilternun2=0.5;	m_filteryes1=TRUE;	m_filteryes2=TRUE;	m_seriesoption=0;	addy2=150;	m_time=1000;	m_pidkp1=50;	m_pidkp2=20;	m_pidti1=30;	m_pidti2=80;	m_pidtd1=0;	m_pidtd2=0;	m_pidcontrolget=pid_control;	m_getsetsv1=1000;	m_getsetsv2=1000;	m_getsetmv1=4000;	m_getsetmv2=4000;	U1=4;	U1New=4;	U1Old=4;	U2New=4;	U2Old=4;	StepU1=float(0.6);	StepU2=float(0.6);	U2=4;	cout=0;	datanumber=0;	start=0;	clean=0;	newdisplay=1;	Move=0;	StartOK=NULL;	StopOK=NULL;	PvDataValue=1;	PvDataValueOther=1;	mvCapture=FALSE;	svCapture=FALSE;	mvOtherCapture=FALSE;	svOtherCapture=FALSE;	//历史数据:	m_historytimeget1=0;	m_historytimeget2=0;	//自定义系统参数:	m_delaytime1=0;	m_delaytime2=0;	m_mvdownlimit1=4000;	m_mvdownlimit2=4000;	m_mvuplimit1=20000;	m_mvuplimit2=20000;	m_upwarning1=5000;	m_upwarning2=5000;	m_downwarning1=1000;	m_downwarning2=1000;                        		//图标:	_mv=320;	_mv1=620;	_sv=320;	_sv1=620;	aorm=1;	aorm2=1;	backBrush.CreateSolidBrush(RGB(0,0,0));       //backBrush.CreateSolidBrush(RGB(255,255,255));//论文打印时改变	mvBrush.CreateSolidBrush(RGB(255,255,0));		svBrush.CreateSolidBrush(RGB(255,0,0));		//mv1图标	CPoint tanglepoint[3];	tanglepoint[0].x=941-7;	tanglepoint[0].y=320;	tanglepoint[1].x=941-17;	tanglepoint[1].y=320+5;	tanglepoint[2].x=941-17;	tanglepoint[2].y=320-5;	mvRgn.CreatePolygonRgn(tanglepoint,3,WINDING);

⌨️ 快捷键说明

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