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

📄 smt5k.cpp

📁 一个很好的VC++程序
💻 CPP
字号:
// SMT5K.cpp : Defines the class behaviors for the application.
//

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

#include "MainFrm.h"
#include "SMT5KDoc.h"
#include "SMT5KView.h"
#include "SerialPort.h"
#include "SM5000.h"

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

extern int SerialPortNo ;
extern int BusWidth ;
extern int ChipSel ;
extern CSerialPort m_ComPort; 
extern CString m_strTXDataCOM1; //COM1发送数据
extern CView   * pMyView;

/////////////////////////////////////////////////////////////////////////////
// CSMT5KApp

BEGIN_MESSAGE_MAP(CSMT5KApp, CWinApp)
	//{{AFX_MSG_MAP(CSMT5KApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	ON_COMMAND(ID_OPTION_COM1, OnOptionCom1)
	ON_UPDATE_COMMAND_UI(ID_OPTION_COM1, OnUpdateOptionCom1)
	ON_COMMAND(ID_OPTION_COM2, OnOptionCom2)
	ON_UPDATE_COMMAND_UI(ID_OPTION_COM2, OnUpdateOptionCom2)
	ON_COMMAND(ID_OPTION_BUS16, OnOptionBus16)
	ON_UPDATE_COMMAND_UI(ID_OPTION_BUS16, OnUpdateOptionBus16)
	ON_COMMAND(ID_OPTION_BUS8, OnOptionBus8)
	ON_UPDATE_COMMAND_UI(ID_OPTION_BUS8, OnUpdateOptionBus8)
	ON_COMMAND(ID_OPTION_SM5002, OnOptionSm5002)
	ON_UPDATE_COMMAND_UI(ID_OPTION_SM5002, OnUpdateOptionSm5002)
	ON_COMMAND(ID_OPTION_SM5004, OnOptionSm5004)
	ON_UPDATE_COMMAND_UI(ID_OPTION_SM5004, OnUpdateOptionSm5004)
	ON_COMMAND(ID_HELP_CONTENT, OnHelpContent)
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSMT5KApp construction

CSMT5KApp::CSMT5KApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CSMT5KApp object

CSMT5KApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CSMT5KApp initialization

BOOL CSMT5KApp::InitInstance()
{
	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CSMT5KDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CSMT5KView));
	AddDocTemplate(pDocTemplate);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The one and only window has been initialized, so show and update it.
	m_pMainWnd->SetWindowText("THUYK-1型 嵌入式运动控制器功能演示程序");
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();


	// Serial Port Initialization
	if (m_ComPort.InitPort(pMyView,SerialPortNo,115200,'N',8,1,EV_RXFLAG | EV_RXCHAR,8192))
		//dwCommEvents=EV_RXCHAR|EV_RXFLAG,nBufferSize=512
	{
		m_ComPort.StartMonitoring(); //启动串口监视线程
	}
	else
	{
		CString str;
		str.Format("COM%d 没有发现,或被其它设备占用",SerialPortNo);
		AfxMessageBox(str);
	}

	return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	afx_msg void OnPaint();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CSMT5KApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CSMT5KApp message handlers


void CSMT5KApp::OnOptionCom1() 
{
	SerialPortNo = 1;

	if (m_ComPort.InitPort(pMyView,SerialPortNo,115200,'N',8,1,EV_RXFLAG | EV_RXCHAR,8192))
		//dwCommEvents=EV_RXCHAR|EV_RXFLAG,nBufferSize=512
	{
		m_ComPort.StartMonitoring(); //启动串口监视线程
	}
	else
	{
		CString str;
		str.Format("COM%d 没有发现,或被其它设备占用",SerialPortNo);
		AfxMessageBox(str);
	}
}

void CSMT5KApp::OnUpdateOptionCom1(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(SerialPortNo == 1);	
}

void CSMT5KApp::OnOptionCom2() 
{
	SerialPortNo = 2;

	//m_ComPort.StopMonitoring(); //启动串口监视线程

	if (m_ComPort.InitPort(pMyView,SerialPortNo,115200,'N',8,1,EV_RXFLAG | EV_RXCHAR,8192))
		//dwCommEvents=EV_RXCHAR|EV_RXFLAG,nBufferSize=512
	{
		m_ComPort.StartMonitoring(); //启动串口监视线程
	}
	else
	{
		CString str;
		str.Format("COM%d 没有发现,或被其它设备占用",SerialPortNo);
		AfxMessageBox(str);
	}
}

void CSMT5KApp::OnUpdateOptionCom2(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(SerialPortNo == 2);	
}

void CSMT5KApp::OnOptionBus16() 
{
	// TODO: Add your command handler code here
	BusWidth = 16;

	m_strTXDataCOM1.Empty();
	WriteIO( 9, 16 );
	m_ComPort.WriteToPort((LPCTSTR)m_strTXDataCOM1);
}

void CSMT5KApp::OnUpdateOptionBus16(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(BusWidth == 16);	
}

void CSMT5KApp::OnOptionBus8() 
{
	// TODO: Add your command handler code here
	BusWidth = 8;

	m_strTXDataCOM1.Empty();
	WriteIO( 9, 8 );
	m_ComPort.WriteToPort((LPCTSTR)m_strTXDataCOM1);
}

void CSMT5KApp::OnUpdateOptionBus8(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(BusWidth == 8);	
}

void CSMT5KApp::OnOptionSm5002() 
{
	ChipSel = 2;
}

void CSMT5KApp::OnUpdateOptionSm5002(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(ChipSel == 2);	
}

void CSMT5KApp::OnOptionSm5004() 
{
	ChipSel = 4;
}

void CSMT5KApp::OnUpdateOptionSm5004(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(ChipSel == 4);	
}

void CSMT5KApp::OnHelpContent() 
{
	HtmlHelp(NULL, "SMP860_HELP.chm::/a1.htm", HH_DISPLAY_TOPIC, 0);
}

void CAboutDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	CPen pen(PS_SOLID,1,RGB(236,233,216));
	CBrush brush(RGB(236,233,216));
	dc.SelectObject(pen);
	dc.SelectObject(brush);
	CRect rect;
	GetClientRect(&rect);
	dc.Rectangle(rect);
	// Do not call CDialog::OnPaint() for painting messages
}

⌨️ 快捷键说明

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