📄 smt5kview.cpp.bak
字号:
// 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"
#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 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;
CMonitorAxis *pMonitorAxis[4];
/////////////////////////////////////////////////////////////////////////////
// CSMT5KView
IMPLEMENT_DYNCREATE(CSMT5KView, CFormView)
BEGIN_MESSAGE_MAP(CSMT5KView, CFormView)
//{{AFX_MSG_MAP(CSMT5KView)
// NOTE - the ClassWizard will add and remove mapping macros here.
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_COMMAND(ID_TEST_DRV_FUNCTION, OnTestDrvFunction)
ON_COMMAND(ID_TEST_IPL_FUNCTION, OnTestIplFunction)
ON_WM_CREATE()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
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)
{
//{{AFX_DATA_INIT(CSMT5KView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CSMT5KView::~CSMT5KView()
{
}
void CSMT5KView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSMT5KView)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}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);
}
void CSMT5KView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CSMT5KView drawing
void CSMT5KView::OnDraw(CDC* pDC)
{
// pDC->TextOut(0,0,"Display String");
}
// 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
LONG CSMT5KView::OnCommunication(WPARAM ch, LPARAM port)
{
//HWND hWndReadReg;
static int wData;
int lData;
CString str1;
if(port==1) //COM1接收到数据
{
switch(ch)
{
case '$':
bStart = TRUE;
break;
case '!': // for notes from serial port
bStart = FALSE;
//AfxMessageBox((LPCTSTR)m_strRXDataCOM1);
m_strRXDataCOM1.Empty();
break;
case '#':
wData = atoi((LPCTSTR)m_strRXDataCOM1);
//AfxMessageBox((LPCTSTR)m_strRXDataCOM1);
m_strRXDataCOM1.Empty();
break;
case '*':
bStart = FALSE;
lData = atoi((LPCTSTR)m_strRXDataCOM1);
//AfxMessageBox((LPCTSTR)m_strRXDataCOM1);
m_strRXDataCOM1.Empty();
if(pReadRegisterDlg!=NULL)
::SendMessage(pReadRegisterDlg->m_hWnd, WM_SM5K_DATA_READ, (WPARAM) wData, (LPARAM) lData );
break;
default:
if(bStart==TRUE)
{
m_strRXDataCOM1 += (char)ch;
}
}
}
return 0;
}
void CSMT5KView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
/*
int randdata=rand()%9000; //产生9000以内的随机数
CString strSendData;
strSendData.Format("%04d",randdata);
SendString(strSendData, 1); //串口1发送数据;
*/
/*
char str1[20];
sprintf(str1,"$%04d*%2d\r\n",randdata,nIDEvent);
m_ComPort1.WriteToPort(str1);
*/
/*
ReadReg (0, 1,0,0,0);
ReadReg (1, 0,0,1,0);
ReadReg (2, 0,0,0,1);
m_ComPort.WriteToPort((LPCTSTR)m_strTXDataCOM1);
*/
/*
if(pRegTestDlg != NULL)
::SetDlgItemText(pRegTestDlg->m_hWnd,ID_MONITOR,"My Monitor");
*/
m_strTXDataCOM1.Empty();
ReadReg (9);
m_ComPort.WriteToPort((LPCTSTR)m_strTXDataCOM1);
/*
*/
CFormView::OnTimer(nIDEvent);
}
void CSMT5KView::SendString(CString &str, int Port)
{
CString str1;
str1='$'+str+"*";
m_ComPort.WriteToPort((LPCTSTR)str1);
TRACE(str1);
}
void CSMT5KView::OnTestReg()
{
// TODO: Add your command handler code here
CRegTestDlg RegTestDlg;
pRegTestDlg = &RegTestDlg;
RegTestDlg.DoModal();
}
void CSMT5KView::OnTestConfig()
{
CConfigDlg ConfigDlg;
pConfigDlg = &ConfigDlg;
ConfigDlg.DoModal();
}
void CSMT5KView::OnTestDrvFunction()
{
CDrvFuncTest DrvFuncTestDlg;
pDrvFuncTestDlg = &DrvFuncTestDlg;
DrvFuncTestDlg.DoModal();
}
void CSMT5KView::OnTestIplFunction()
{
CIPLFuncTest IPLFuncTestDlg;
pIPLFuncTestDlg = &IPLFuncTestDlg;
IPLFuncTestDlg.DoModal();
}
int CSMT5KView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFormView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
pMonitorAxis[0] = new CMonitorAxis;
pMonitorAxis[0]->Create(IDD_MONITOR_AXIS_DLG,this);
pMonitorAxis[0]->MoveWindow(0,0,800,600);
pMonitorAxis[0]->ShowWindow(SW_SHOW);
return 0;
}
/*
*/
void CSMT5KView::OnButton1()
{
// TODO: Add your control notification handler code here
pMonitorAxis[0]->ShowWindow(SW_HIDE);
}
LONG CSMT5KView::OnSm5kDataRead(WPARAM ch, LPARAM port)
{
/*
*/
CString str;
str.Format("c=%c,port=%d,str=%s",ch,port,(LPCTSTR)m_strRXDataCOM1);
//AfxMessageBox(str);
//AfxGetMainWnd()->SetWindowText ((LPCTSTR)m_strRXDataCOM1);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -