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

📄 smt5kview.cpp

📁 一个很好的VC++程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// SMT5KView.cpp : implementation of the CSMT5KView class
//

#include "stdafx.h"
#include "SMT5K.h"

#include "SMT5KDoc.h"
#include "SMT5KView.h"
#include "SerialPort.h"
#include "SM5000.h"
#include "RegTestDlg.h"
#include "ConfigDlg.h"
#include "DrvFuncTest.h"
#include "IPLFuncTest.h"
#include "MonitorAxis.h"
#include "MonitorIPL.h"
#include "WriteReg.h"
#include "WriteParam.h"
#include "WriteDrvCmd.h"
#include "WriteIPLCmd.h"
#include "ReadReg.h"


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

extern CDialog * pRegTestDlg	;
extern CDialog * pConfigDlg		;
extern CDialog * pDrvFuncTestDlg;
extern CDialog * pIPLFuncTestDlg;
extern CDialog * pReadRegisterDlg;
extern CView   * pMyView ;

extern CSerialPort m_ComPort; 
extern CString m_strRXDataCOM1; //COM1接收数据
extern CString m_strTXDataCOM1; //COM1发送数据
extern BOOL bStart;
extern unsigned short m_RR0;
extern unsigned short m_RR1;
extern unsigned short m_RR2;
extern int CurrentAxis;        //轴号
extern int SerialPortNo ;
extern int g_ExppEn;
extern int g_SampleTime;

CMonitorAxis *pMonitorAxis[4];
CMonitorIPL  *pMonitorIPL;


/////////////////////////////////////////////////////////////////////////////
// CSMT5KView

IMPLEMENT_DYNCREATE(CSMT5KView, CFormView)

BEGIN_MESSAGE_MAP(CSMT5KView, CFormView)
	//{{AFX_MSG_MAP(CSMT5KView)
	ON_MESSAGE(WM_COMM_RXCHAR, OnCommunication)
	ON_WM_TIMER()
	ON_MESSAGE(WM_SM5K_DATA_READ, OnSm5kDataRead)
	ON_COMMAND(ID_TEST_REG, OnTestReg)
	ON_COMMAND(ID_TEST_CONFIG, OnTestConfig)
	ON_WM_CREATE()
	ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_CV_RANGE, OnDeltaposSpinCvYRange)
	ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_X_RANGE, OnDeltaposSpinXRange)
	ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_LP_RANGE, OnDeltaposSpinLpRange)
	ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_CA_RANGE, OnDeltaposSpinCaRange)
	ON_COMMAND(ID_TEST_DRV_MOVE, OnTestDrvMove)
	ON_COMMAND(ID_TEST_IPL_MOVE, OnTestIplMove)
	ON_COMMAND(ID_TEST_WRITE_REG, OnTestWriteReg)
	ON_COMMAND(ID_TEST_WRITE_PARAM, OnTestWriteParam)
	ON_COMMAND(ID_TEST_SEND_DRVCMD, OnTestSendDrvcmd)
	ON_COMMAND(ID_TEST_SEND_IPLCMD, OnTestSendIplcmd)
	ON_COMMAND(ID_TEST_READ_REG, OnTestReadReg)
	ON_COMMAND(ID_TEST_SHOW_DRV, OnTestShowDrv)
	ON_UPDATE_COMMAND_UI(ID_TEST_SHOW_DRV, OnUpdateTestShowDrv)
	ON_COMMAND(ID_TEST_SHOW_IPL, OnTestShowIpl)
	ON_UPDATE_COMMAND_UI(ID_TEST_SHOW_IPL, OnUpdateTestShowIpl)
	ON_BN_CLICKED(IDC_BUTTON_CLR, OnButtonClr)
	ON_COMMAND(ID_TEST_DOWN_SPEED, OnTestDownSpeed)
	ON_COMMAND(ID_TEST_IMSTOP, OnTestImstop)
	ON_COMMAND(ID_TEST_GO_HOME, OnTestGoHome)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSMT5KView construction/destruction

CSMT5KView::CSMT5KView()
	: CFormView(CSMT5KView::IDD)
{
	int i;

	pMyView = this;

	m_DrvX = 0;
	m_DrvY = 0;
	m_DrvZ = 0;
	m_DrvU = 0;
	
	for(i=0;i<4;i++)
	{
	m_XDiv[i]   = 100;
	m_YDivCA[i] = 1000;
	m_YDivCV[i] = 10000;
	m_YDivLP[i] = 100000;
	}
	

	//{{AFX_DATA_INIT(CSMT5KView)
	m_DrawSelEP = 0;
	//}}AFX_DATA_INIT
	// TODO: add construction code here

	m_ShowIplState = 0;

}

CSMT5KView::~CSMT5KView()
{
}

void CSMT5KView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSMT5KView)
	//}}AFX_DATA_MAP
}

BOOL CSMT5KView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CSMT5KView drawing

void CSMT5KView::OnDraw(CDC* pDC)
{
	CPen pen(PS_SOLID,1,RGB(0,0,255));
	CPen pen1(PS_SOLID,1,RGB(255,0,0));
	CPen pen2(PS_SOLID,1,RGB(255,55,250));
	int i;
	CSMT5KDoc *pDoc = GetDocument();

	if(!m_ShowIplState)
	{
		// Draw CV curve
		pDC->SelectObject(pen);

		ptCurrentCV.x = m_X0;
		ptCurrentCV.y = m_Y0CV ;
		pDC->MoveTo(ptCurrentCV);

		for(i=0;i<(pDoc->CVCount[CurrentAxis])*m_XMax;i+=(m_XDiv[CurrentAxis]*2))
		{
			if(ptCurrentCV.x++>=m_X0+m_XMax) break;
			ptCurrentCV.y = m_Y0CV - (pDoc->CVArray[CurrentAxis][i/m_XMax])*m_YMulCV/m_YDivCV[CurrentAxis];
			if(ptCurrentCV.y>m_YMinCV && ptCurrentCV.y<=m_YMaxCV)
			{
				pDC->LineTo(ptCurrentCV);
			}
			else
			{
				pDC->MoveTo(ptCurrentCV);
			}
		}
		
		// Draw CA curve

		pDC->SelectObject(pen1);
		ptCurrentCA.x = m_X0;
		ptCurrentCA.y = m_Y0CA ;
		pDC->MoveTo(ptCurrentCA);

		for(i=0;i<(pDoc->CACount[CurrentAxis])*m_XMax;i+=(m_XDiv[CurrentAxis]*2))
		{
			if(ptCurrentCA.x++>=m_X0+m_XMax) break;
			ptCurrentCA.y = m_Y0CA - (pDoc->CAArray[CurrentAxis][i/m_XMax])*m_YMulCA/(m_YDivCA[CurrentAxis]/4.0);
			if(ptCurrentCA.y>m_YMinCA && ptCurrentCA.y<=m_YMaxCA)
				pDC->LineTo(ptCurrentCA);
			else
				pDC->MoveTo(ptCurrentCA);
		}
		
		// Draw LP curve

		pDC->SelectObject(pen2);
		ptCurrentLP.x = m_X0;
		ptCurrentLP.y = m_Y0LP ;
		pDC->MoveTo(ptCurrentLP);

		if(m_DrawSelEP)
		for(i=0;i<(pDoc->EPCount[CurrentAxis])*m_XMax;i+=(m_XDiv[CurrentAxis]*2))
		{
			if(ptCurrentLP.x++>=m_X0+m_XMax) break;
			ptCurrentLP.y = m_Y0LP - (pDoc->EPArray[CurrentAxis][i/m_XMax])*m_YMulLP/m_YDivLP[CurrentAxis];
			if(ptCurrentLP.y>m_YMinLP && ptCurrentLP.y<=m_YMaxLP)
				pDC->LineTo(ptCurrentLP);
			else
				pDC->MoveTo(ptCurrentLP);
		}
		else
		for(i=0;i<(pDoc->LPCount[CurrentAxis])*m_XMax;i+=(m_XDiv[CurrentAxis]*2))
		{
			if(ptCurrentLP.x++>=m_X0+m_XMax) break;
			ptCurrentLP.y = m_Y0LP - (pDoc->LPArray[CurrentAxis][i/m_XMax])*m_YMulLP/m_YDivLP[CurrentAxis];
			if(ptCurrentLP.y>m_YMinLP && ptCurrentLP.y<=m_YMaxLP)
				pDC->LineTo(ptCurrentLP);
			else
				pDC->MoveTo(ptCurrentLP);
		}
	}
}

void CSMT5KView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

	// Draw
	GetDlgItem(IDC_STATIC_DRAW_CV)->GetWindowRect(&m_RectCV);
	ScreenToClient(&m_RectCV);
	GetDlgItem(IDC_STATIC_DRAW_CA)->GetWindowRect(&m_RectCA);
	ScreenToClient(&m_RectCA);
	GetDlgItem(IDC_STATIC_DRAW_LP)->GetWindowRect(&m_RectLP);
	ScreenToClient(&m_RectLP);

	m_X0   = m_RectCV.left;
	m_XMax = m_RectCV.Width() ;

	m_YMinCV = m_RectCV.top +10 ;
	m_YMaxCV = m_RectCV.bottom -5;
	m_YMulCV = m_RectCV.Height()*4/5 ;
	m_Y0CV   = m_YMaxCV;

	m_YMinCA = m_RectCA.top +10 ;
	m_YMaxCA = m_RectCA.bottom -5;
	m_YMulCA = m_RectCA.Height()*4/5 ;
	m_Y0CA   = m_YMaxCA;

	m_YMinLP = m_RectLP.top +10 ;
	m_YMaxLP = m_RectLP.bottom -5;
	m_YMulLP = m_RectLP.Height()*2/5 ;
	m_Y0LP   = (m_RectLP.top + m_RectLP.bottom)/2;
	
	ptCurrentCV.x = m_X0;
	ptCurrentCV.y = m_Y0CV;
	ptCurrentCA.y = m_Y0CA;
	ptCurrentLP.y = m_Y0LP;
}

/////////////////////////////////////////////////////////////////////////////
// CSMT5KView printing

BOOL CSMT5KView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CSMT5KView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CSMT5KView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CSMT5KView diagnostics

#ifdef _DEBUG
void CSMT5KView::AssertValid() const
{
	CFormView::AssertValid();
}

void CSMT5KView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CSMT5KView message handlers

void CSMT5KView::AddPointToCVCurve(int lData)
{
	UpdateCurveRect(m_RectCV);

/*
	CString str;

	CClientDC ClientDC(this);
	OnPrepareDC(&ClientDC);

	ClientDC.MoveTo(ptCurrentCV);

	ptCurrentCV.x++;
	ptCurrentCV.y = m_Y0CV - lData*m_YMulCV/m_YDivCV[CurrentAxis];
	if(ptCurrentCV.y>m_YMinCV && ptCurrentCV.y<=m_YMaxCV && ptCurrentCV.x<m_X0+m_XMax)
		ClientDC.LineTo(ptCurrentCV);
	else
		ClientDC.MoveTo(ptCurrentCV);
*/
}


void CSMT5KView::AddPointToCACurve(int lData)
{
	UpdateCurveRect(m_RectCA);

/*
	CString str;

	CClientDC ClientDC(this);
	OnPrepareDC(&ClientDC);

	ClientDC.MoveTo(ptCurrentCA);

	ptCurrentCA.x++;
	ptCurrentCA.y = m_Y0CA - lData*m_YMulCA/m_YDivCA[CurrentAxis];
	if(ptCurrentCA.y>m_YMinCA && ptCurrentCA.y<=m_YMaxCA && ptCurrentCA.x<m_X0+m_XMax)
		ClientDC.LineTo(ptCurrentCA);
	else
		ClientDC.MoveTo(ptCurrentCA);
*/
}


void CSMT5KView::AddPointToLPCurve(int lData)
{
	UpdateCurveRect(m_RectLP);

/*
	CString str;

	CClientDC ClientDC(this);
	OnPrepareDC(&ClientDC);

	ClientDC.MoveTo(ptCurrentLP);

	ptCurrentLP.x++;
	ptCurrentLP.y = m_Y0LP - lData*m_YMulLP/m_YDivLP[CurrentAxis];
	if(ptCurrentLP.y>m_YMinLP && ptCurrentLP.y<=m_YMaxLP && ptCurrentLP.x<m_X0+m_XMax)
		ClientDC.LineTo(ptCurrentLP);
	else
		ClientDC.MoveTo(ptCurrentLP);
*/
}

LONG CSMT5KView::OnSm5kDataRead(WPARAM wData, LPARAM lData)
{
	CSMT5KDoc *pDoc = GetDocument();
	
	CString str;
	int AxisNo,RegNo;
	int AxisIsDrving;
	int CiplSeg;

	AxisNo = wData / 100;
	RegNo= wData % 100;

	if     (AxisNo==0 ) AxisIsDrving = m_DrvX;
	else if(AxisNo==1 ) AxisIsDrving = m_DrvY;
	else if(AxisNo==2 ) AxisIsDrving = m_DrvZ;
	else                AxisIsDrving = m_DrvU;

	switch(RegNo)
		{
		case 0 :
				m_DrvX = GetBit(lData,0);
				m_DrvY = GetBit(lData,1);
				m_DrvZ = GetBit(lData,2);
				m_DrvU = GetBit(lData,3);

				if(m_DrvX==0 && m_DrvY==0 && m_DrvZ==0 && m_DrvU==0 && g_ExppEn==0)
					AfxGetMainWnd()->SendMessage(WM_SM5K_TIMER_ON, 0, 0 );


				pMonitorAxis[0]->UpdateDRV(GetBit(lData,0+CurrentAxis));
				
				pMonitorAxis[0]->UpdateERR(GetBit(lData,4+CurrentAxis));
				
				pMonitorIPL->UpdateDRV(GetBit(lData,0,4));
				pMonitorIPL->UpdateIDRV(GetBit(lData,8));
				pMonitorIPL->UpdateCNEXT(GetBit(lData,9));
				pMonitorIPL->UpdateZONE(GetBit(lData,10,3));
				pMonitorIPL->UpdateBPSC(GetBit(lData,13,2));

				break;
		case 1 :
				if(AxisNo==CurrentAxis)
				{
				pMonitorAxis[0]->UpdateACC(GetBit(lData,0,8));
				pMonitorAxis[0]->UpdateWhyEnd(GetBit(lData,8,8));
				}
				
				if(AxisNo==pMonitorIPL->m_Axis[0])
					pMonitorIPL->UpdateACC(GetBit(lData,0,8));
				break;
		
		case 2 :
				if(AxisNo==CurrentAxis)
				{
				pMonitorAxis[0]->UpdateWhatErr(GetBit(lData,0,6));
				}
				if(AxisNo==0)
				{
					//pMonitorIPL->UpdateCiplSegNo(GetBit(lData,8,4));
					if(pIPLFuncTestDlg)
					{
						CiplSeg = ((CIPLFuncTest*)pIPLFuncTestDlg)->m_CiplCurrentSeg;
						pMonitorIPL->UpdateCiplSegNo(CiplSeg);
					}

⌨️ 快捷键说明

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