comsetdlg.cpp

来自「监视Modbus规约的通讯程序」· C++ 代码 · 共 78 行

CPP
78
字号
// ComSetDlg.cpp : implementation file
//

#include "stdafx.h"
#include "dongmo.h"
#include "ComSetDlg.h"

#include "Com.h"

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

 CCom g_Com;
extern int g_Address;
/////////////////////////////////////////////////////////////////////////////
// CComSetDlg dialog


CComSetDlg::CComSetDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CComSetDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CComSetDlg)
	m_port = 0;
	m_baud = 3;
	//}}AFX_DATA_INIT
}


void CComSetDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CComSetDlg)
	DDX_CBIndex(pDX, IDC_COMBO_PORT, m_port);
	DDX_CBIndex(pDX, IDC_COMBO_BAUD, m_baud);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CComSetDlg, CDialog)
	//{{AFX_MSG_MAP(CComSetDlg)
	ON_CBN_EDITCHANGE(IDC_COMBO_PORT, OnEditchangeComboPort)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CComSetDlg message handlers

void CComSetDlg::OnOK() 
{

	// TODO: Add extra validation here
	if (!UpdateData())
		return;
   
	CString csPort;
	csPort.Format("COM%d", m_port + 1);
     g_Com.Close();
	if (!g_Com.Open(csPort, 1200 * (1 << m_baud)))
	{
		MessageBox("无法打开通讯口" + csPort + "!", NULL, MB_OK | MB_ICONSTOP);
		return;
	}

//	g_Address = m_Address;


	CDialog::OnOK();
}

void CComSetDlg::OnEditchangeComboPort() 
{
	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

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