102 lines
2.1 KiB
C++
102 lines
2.1 KiB
C++
// PlcDeviceDlg.cpp : 实现文件
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "ConfigDlg.h"
|
|
#include "afxdialogex.h"
|
|
#include "PluginPlc.h"
|
|
#include "resource.h"
|
|
|
|
#define TIMER_UPDATE_TOPLC 1
|
|
#define TIMER_UPDATE_TODLG 2
|
|
#define TIMER_UPDATE_FROMPLC 3
|
|
|
|
|
|
// CPlcDeviceDlg 对话框
|
|
|
|
IMPLEMENT_DYNAMIC(CConfigDlg, CDialogEx)
|
|
|
|
CConfigDlg::CConfigDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialogEx(IDD_CONFIG_DLG, pParent)
|
|
{
|
|
|
|
|
|
}
|
|
|
|
CConfigDlg::~CConfigDlg()
|
|
{
|
|
}
|
|
|
|
|
|
void CConfigDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialogEx::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_IPADDRESS, m_ipAddrCtrl);
|
|
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CConfigDlg, CDialogEx)
|
|
ON_BN_CLICKED(IDC_BTN_SET, &CConfigDlg::OnBnClickedBtnSet)
|
|
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
// CPlcDeviceDlg 消息处理程序
|
|
|
|
BOOL CConfigDlg::OnInitDialog()
|
|
{
|
|
CDialogEx::OnInitDialog();
|
|
|
|
//读取配置文件
|
|
ReadConfigFromIni();
|
|
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// 异常: OCX 属性页应返回 FALSE
|
|
}
|
|
|
|
void CConfigDlg::ReadConfigFromIni()
|
|
{
|
|
CString strIniPath = theApp.m_strModulePath + "\\config.ini";
|
|
// 初始化设备配置
|
|
|
|
char acValue[32] = "";
|
|
GetPrivateProfileString("CORE", "IP", "", acValue, 32, strIniPath);
|
|
//m_strIpAddr = acValue;
|
|
DWORD dwIP = inet_addr(acValue);
|
|
unsigned char *pIP = (unsigned char*)&dwIP;
|
|
m_ipAddrCtrl.SetAddress(*pIP, *(pIP + 1), *(pIP + 2), *(pIP + 3));
|
|
|
|
|
|
|
|
int nPort = GetPrivateProfileInt("CORE", "PORT", 0, strIniPath);
|
|
CString strPort;
|
|
strPort.Format("%d", nPort);
|
|
GetDlgItem(IDC_EDIT_PORT)->SetWindowText(strPort);
|
|
|
|
|
|
return; // return TRUE unless you set the focus to a control
|
|
// 异常: OCX 属性页应返回 FALSE
|
|
}
|
|
|
|
|
|
void CConfigDlg::OnBnClickedBtnSet()
|
|
{
|
|
CString strIniPath = theApp.m_strModulePath + "\\config.ini";
|
|
BYTE nFild[4];
|
|
m_ipAddrCtrl.GetAddress(nFild[0], nFild[1], nFild[2], nFild[3]);
|
|
CString strIpAddr;
|
|
strIpAddr.Format("%d.%d.%d.%d", nFild[0], nFild[1], nFild[2], nFild[3]);
|
|
WritePrivateProfileString("CORE", "IP", strIpAddr, strIniPath);
|
|
|
|
CString strPort;
|
|
GetDlgItem(IDC_EDIT_PORT)->GetWindowText(strPort);
|
|
WritePrivateProfileString("CORE", "PORT", strPort, strIniPath);
|
|
|
|
MessageBox("配置已更新, 请重启核心控制器.");
|
|
|
|
|
|
}
|
|
|