📄 testicandlldlg.cpp
字号:
// testicandllDlg.cpp : implementation file
//
#include "stdafx.h"
#include "testicandll.h"
#include "testicandllDlg.h"
#include "DlgSysCfg.h"
#include <vector>
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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
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)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTesticandllDlg dialog
CTesticandllDlg::CTesticandllDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTesticandllDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTesticandllDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTesticandllDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTesticandllDlg)
DDX_Control(pDX, IDC_LIST_DATA, m_ctlListData);
DDX_Control(pDX, IDC_COMBO_DISCONNECTSLAVEID, m_ctlComboDisconnectSlaveID);
DDX_Control(pDX, IDC_COMBO_DATATYPE, m_ctlComboDataType);
DDX_Control(pDX, IDC_COMBO_CONNECTEDSLAVEID, m_ctlComboConnectedSlaveID);
DDX_Control(pDX, IDC_COMBO_MASTERID, m_ctlComboMasterID);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTesticandllDlg, CDialog)
//{{AFX_MSG_MAP(CTesticandllDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_SYSCFG, OnButtonSyscfg)
ON_BN_CLICKED(IDC_BUTTON_SETMASTER, OnButtonSetmaster)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON_CONNECT, OnButtonConnect)
ON_NOTIFY(NM_RCLICK, IDC_LIST_DATA, OnRclickListData)
ON_COMMAND(ID_MENU_DISCONNECT, OnMenuDisconnect)
ON_UPDATE_COMMAND_UI(ID_MENU_DISCONNECT, OnUpdateMenuDisconnect)
ON_BN_CLICKED(IDC_BUTTON_SENDDATA, OnButtonSenddata)
ON_CBN_SELCHANGE(IDC_COMBO_MASTERID, OnSelchangeComboMasterid)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTesticandllDlg message handlers
BOOL CTesticandllDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
Init();
return TRUE; // return TRUE unless you set the focus to a control
}
void CTesticandllDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTesticandllDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTesticandllDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTesticandllDlg::OnOK()
{
// TODO: Add extra validation here
// CDialog::OnOK();
}
void CTesticandllDlg::OnCancel()
{
// TODO: Add extra cleanup here
ClearList();
CDialog::OnCancel();
}
void CTesticandllDlg::OnButtonSyscfg()
{
// TODO: Add your control notification handler code here
CDlgSysCfg dlg;
dlg.DoModal();
}
void CTesticandllDlg::OnButtonSetmaster()
{
// TODO: Add your control notification handler code here
m_ctlComboMasterID.EnableWindow(FALSE);
CString strcap[2]={"停止","启动"};
if(Mgr_IsStarted())
{
KillTimer(TIMERID_REFRESHDATA);
Mgr_StopSys();
DelAllFromList();
}
else
{
CString strtmp1;
int oldmasterid,newmasterid,icycle;
newmasterid=m_ctlComboMasterID.GetCurSel();
GetDlgItem(IDC_EDIT_MASTERCYCLE)->GetWindowText(strtmp1);
sscanf(strtmp1,"%d",&icycle);
m_global.m_syscfg.routecfg.wMasterID=m_ctlComboMasterID.GetCurSel();
m_global.m_syscfg.routecfg.iMasterCycle=icycle;
ROUTECFG cfg;
Route_GetConfig(m_global.m_hRoute,&cfg);
oldmasterid=cfg.wMasterID;
cfg.iCardType=m_global.m_syscfg.routecfg.iCardType;
cfg.iCardInd=m_global.m_syscfg.routecfg.iCardInd;
cfg.iCANInd=m_global.m_syscfg.routecfg.iCANInd;
cfg.wCANBaud=m_global.m_syscfg.routecfg.wCANBaud;
cfg.iMasterCycle=icycle/MASTER_CYCLEUNIT;
cfg.wMasterID=newmasterid;
Route_SetConfig(m_global.m_hRoute,cfg);
//当设备型号为CANET时,需要设置以下参数
if(cfg.iCardType==VCI_CANETE)
{
DWORD srcport,canetport;
BYTE canetip[4];
srcport=4001;//本地端口,可根据实际情况修改,现假设为4001
canetport=4001;//CANET工作端口,可根据实际情况修改,现假设为4001
canetip[3]=192;//CANET的IP地址,可根据实际情况修改,现假设为192.168.0.178
canetip[2]=168;
canetip[1]=0;
canetip[0]=178;
Route_IOCtl(m_global.m_hRoute,IOCTL_ROUTE_SETSRCPORT,(BYTE*)&srcport,4,0,0);
Route_IOCtl(m_global.m_hRoute,IOCTL_ROUTE_SETDESIP,(BYTE*)canetip,4,0,0);
Route_IOCtl(m_global.m_hRoute,IOCTL_ROUTE_SETDESPORT,(BYTE*)&canetport,4,0,0);
}
m_global.m_syscfg.routecfg.wMasterID=newmasterid;
m_global.m_syscfg.routecfg.iMasterCycle=icycle;
if(Mgr_StartSys()!=ICANOK)
{
MessageBox("启动失败");
goto ext;
}
SetDisconnectCombo(oldmasterid,newmasterid);
SetBtnStatus();
SetTimer(TIMERID_REFRESHDATA,m_global.m_syscfg.routecfg.iMasterCycle,NULL);
}
GetDlgItem(IDC_BUTTON_SETMASTER)->SetWindowText(
strcap[!Mgr_IsStarted()]);
ext:
SetBtnStatus();
}
void CTesticandllDlg::Init()
{
CString str1;
for(int i=0;i<0xff;i++)
{
str1.Format("%d",i);
m_ctlComboMasterID.SetItemData(m_ctlComboMasterID.AddString(str1),i);
}
m_ctlComboMasterID.SetCurSel(m_global.m_syscfg.routecfg.wMasterID);
str1.Format("%d",m_global.m_syscfg.routecfg.iMasterCycle);
GetDlgItem(IDC_EDIT_MASTERCYCLE)->SetWindowText(str1);
for(i=0;i<0xff;i++)
{
str1.Format("%d",i);
m_ctlComboDisconnectSlaveID.SetItemData(m_ctlComboDisconnectSlaveID.AddString(str1),i);
}
m_ctlComboDataType.SetCurSel(0);
m_ctlListData.InsertColumn(0,"从站地址",LVCFMT_LEFT,60,0);
m_ctlListData.InsertColumn(1,"数据类型",LVCFMT_LEFT,60,1);
m_ctlListData.InsertColumn(2,"刷新时间",LVCFMT_LEFT,90,2);
m_ctlListData.InsertColumn(3,"数据",LVCFMT_LEFT,450,3);
m_ctlListData.SetExtendedStyle(LVS_EX_FULLROWSELECT);
m_ctlListData.ModifyStyleEx(0,WS_EX_CLIENTEDGE);
SetBtnStatus();
}
void CTesticandllDlg::SetDisconnectCombo(int oldmasterid, int newmasterid)
{
AddItemToCombo(m_ctlComboDisconnectSlaveID,oldmasterid);
CString str1;
str1.Format("%d",newmasterid);
int ifind=m_ctlComboDisconnectSlaveID.FindStringExact(0,str1);
if(ifind!=-1)
{
m_ctlComboDisconnectSlaveID.DeleteString(ifind);
}
if(m_ctlComboDisconnectSlaveID.GetCurSel()==-1)
m_ctlComboDisconnectSlaveID.SetCurSel(0);
}
void CTesticandllDlg::SetBtnStatus()
{
GetDlgItem(IDC_BUTTON_CONNECT)->EnableWindow(
Mgr_IsStarted());
GetDlgItem(IDC_BUTTON_SENDDATA)->EnableWindow(
Mgr_IsStarted());
}
void CTesticandllDlg::OnTimer(UINT nIDEvent)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -