📄 master104_demodlg.cpp
字号:
// Master104_DemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Master104_Demo.h"
#include "Master104real.h"
#include "Master104_DemoDlg.h"
#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()
/////////////////////////////////////////////////////////////////////////////
// CMaster104_DemoDlg dialog
CMaster104_DemoDlg::CMaster104_DemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMaster104_DemoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMaster104_DemoDlg)
m_conn = FALSE;
m_start = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMaster104_DemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMaster104_DemoDlg)
DDX_Control(pDX, IDC_IPADDRESS1, m_ip);
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_Check(pDX, IDC_CHECKconn, m_conn);
DDX_Check(pDX, IDC_CHECKstarted, m_start);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMaster104_DemoDlg, CDialog)
//{{AFX_MSG_MAP(CMaster104_DemoDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTONstart, OnBUTTONstart)
ON_BN_CLICKED(IDC_BUTTONstop, OnBUTTONstop)
ON_BN_CLICKED(IDC_BUTTONreqcall, OnBUTTONreqcall)
ON_BN_CLICKED(IDC_BUTTONreqcallgrp1, OnBUTTONreqcallgrp1)
ON_BN_CLICKED(IDC_BUTTONreadfunc, OnBUTTONreadfunc)
ON_BN_CLICKED(IDC_BUTTONcontrolselect, OnBUTTONcontrolselect)
ON_BN_CLICKED(IDC_BUTTONcontroloperate, OnBUTTONcontroloperate)
ON_BN_CLICKED(IDC_BUTTONcontroldeact, OnBUTTONcontroldeact)
ON_BN_CLICKED(IDC_BUTTONitfreeze, OnBUTTONitfreeze)
ON_BN_CLICKED(IDC_BUTTONitreqcall, OnBUTTONitreqcall)
ON_BN_CLICKED(IDC_BUTTONitreqcallgrp1, OnBUTTONitreqcallgrp1)
ON_BN_CLICKED(IDC_BUTTONresetproc, OnBUTTONresetproc)
ON_BN_CLICKED(IDC_BUTTONresetdata, OnBUTTONresetdata)
ON_BN_CLICKED(IDC_BUTTONtest, OnBUTTONtest)
ON_BN_CLICKED(IDC_BUTTONsetME_NA, OnBUTTONsetMENA)
ON_BN_CLICKED(IDC_BUTTONsetpMENA, OnBUTTONsetpMENA)
ON_BN_CLICKED(IDC_BUTTONsyncolock, OnBUTTONsyncolock)
ON_BN_CLICKED(IDC_BUTTONU_start, OnBUTTONUstart)
ON_BN_CLICKED(IDC_BUTTONU_stop, OnBUTTONUstop)
ON_BN_CLICKED(IDC_BUTTONconnect, OnBUTTONconnect)
ON_BN_CLICKED(IDC_BUTTONdisconn, OnBUTTONdisconn)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMaster104_DemoDlg message handlers
BOOL CMaster104_DemoDlg::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
real=0;
m_ip.SetAddress(192,168,0,145);
UpdateData(0);
SetTimer(1,1000,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CMaster104_DemoDlg::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 CMaster104_DemoDlg::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 CMaster104_DemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMaster104_DemoDlg::OnBUTTONstart()
{
// TODO: Add your control notification handler code here
if(real) return;
real=new CMaster104real() ;
real->dlg=this;
BYTE fd0,fd1,fd2,fd3;
UpdateData(1);
m_ip.GetAddress(fd0,fd1,fd2,fd3);
sprintf(serverIP,"%d.%d.%d.%d",fd0,fd1,fd2,fd3);
real->Init_SockServerIP(serverIP);
real->Init_Linkpara();
real->master_start();
}
void CMaster104_DemoDlg::OnBUTTONstop()
{
// TODO: Add your control notification handler code here
if(real)
{
real->master_close();
delete real;
real=NULL;
}
}
void CMaster104_DemoDlg::SendMsg(BYTE *txbuf,int txlen)
{
real->Send_ASDU_Msg(txbuf,txlen);
CString ch, str;
str="Tx:";
for(int i=0;i<txlen;i++)
{
ch.Format(" %02x",txbuf[i]);
str+=ch;
}
//m_list.AddString(str);
if(m_list.GetCount()>100)
m_list.DeleteString(0);
int count=m_list.GetCount();
m_list.SetCurSel(count-1);
}
void CMaster104_DemoDlg::OnBUTTONreqcall()
{
// TODO: Add your control notification handler code here
BYTE buf[]={100,1,6,0,1,0,0,0,0,20};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
SendMsg(buf,sizeof(buf));
}
void CMaster104_DemoDlg::OnBUTTONreqcallgrp1()
{
// TODO: Add your control notification handler code here
BYTE buf[]={100,1,6,0,1,0,0,0,0,21};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
SendMsg(buf,sizeof(buf));
}
void CMaster104_DemoDlg::OnBUTTONreadfunc()
{
// TODO: Add your control notification handler code here
BYTE buf[]={102,1,5,0,1,0,0x01,0x00,0x00};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
//BYTE buf[]={102,1,5,0,1,0,0x01,0x40,0x00};//读遥测量
SendMsg(buf,sizeof(buf));
}
void CMaster104_DemoDlg::OnBUTTONcontrolselect()
{
// TODO: Add your control notification handler code here
BYTE buf[]={45,1,6,0,1,0,0x01,0x60,0x00,0x81};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
SendMsg(buf,sizeof(buf));
}
void CMaster104_DemoDlg::OnBUTTONcontroloperate()
{
// TODO: Add your control notification handler code here
BYTE buf[]={45,1,6,0,1,0,0x01,0x60,0x00,0x01};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
SendMsg(buf,sizeof(buf));
}
void CMaster104_DemoDlg::OnBUTTONcontroldeact()
{
// TODO: Add your control notification handler code here
BYTE buf[]={45,1,8,0,1,0,0x01,0x60,0x00,0x81};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
SendMsg(buf,sizeof(buf));
}
void CMaster104_DemoDlg::OnBUTTONitfreeze()
{
// TODO: Add your control notification handler code here
BYTE buf[]={101,1,6,0,1,0,0x00,0x00,0x00,0x45};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
SendMsg(buf,sizeof(buf));
}
void CMaster104_DemoDlg::OnBUTTONitreqcall()
{
// TODO: Add your control notification handler code here
BYTE buf[]={101,1,6,0,1,0,0x00,0x00,0x00,0x05};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
SendMsg(buf,sizeof(buf));
}
void CMaster104_DemoDlg::OnBUTTONitreqcallgrp1()
{
// TODO: Add your control notification handler code here
BYTE buf[]={101,1,6,0,1,0,0x00,0x00,0x00,0x01};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
SendMsg(buf,sizeof(buf));
}
void CMaster104_DemoDlg::OnBUTTONresetproc()
{
// TODO: Add your control notification handler code here
BYTE buf[]={105,1,6,0,1,0,0x00,0x00,0x00,0x01};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
SendMsg(buf,sizeof(buf));
}
void CMaster104_DemoDlg::OnBUTTONresetdata()
{
// TODO: Add your control notification handler code here
BYTE buf[]={105,1,6,0,1,0,0x00,0x00,0x00,0x02};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
SendMsg(buf,sizeof(buf));
}
void CMaster104_DemoDlg::OnBUTTONtest()
{
// TODO: Add your control notification handler code here
BYTE buf[]={104,1,6,0,1,0,0x00,0x00,0x00,0xaa,0x55};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
SendMsg(buf,sizeof(buf));
}
void CMaster104_DemoDlg::OnBUTTONsetMENA()
{
// TODO: Add your control notification handler code here
BYTE buf[]={48,1,6,0,1,0,0x01,0x62,0x00,0x01,0x02,0x00};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
SendMsg(buf,sizeof(buf));
}
void CMaster104_DemoDlg::OnBUTTONsetpMENA()
{
// TODO: Add your control notification handler code here
BYTE buf[]={110,1,6,0,1,0,0x01,0x50,0x00,0x05,0x00,0x01};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
SendMsg(buf,sizeof(buf));
}
void CMaster104_DemoDlg::OnBUTTONsyncolock()
{
// TODO: Add your control notification handler code here
BYTE Txbuf[256];
BYTE *buff=Txbuf;
BYTE *csbuff;
*buff++=103; //type
*buff++=1;
*buff++=6;
*buff++=1; //address
*buff++=0;
*buff++=0;
SYSTEMTIME ctim;
GetLocalTime(&ctim);
*((WORD*)buff)=ctim.wMilliseconds+ctim.wSecond*1000;
buff++;
buff++;
*buff++=ctim.wMinute;
*buff++=ctim.wHour;
*buff++=ctim.wDay;//(ctim.wDay&0x1f)|((ctim.wDayOfWeek<<5)&0xe0);
*buff++=ctim.wMonth;
*buff++=ctim.wYear-2000;
int Txlen=buff-Txbuf;
SendMsg(Txbuf,Txlen);
}
void CMaster104_DemoDlg::OnBUTTONUstart()
{
// TODO: Add your control notification handler code here
if(real)
real->Send_ASDU_Ucommand(CMD_USTART);
}
void CMaster104_DemoDlg::OnBUTTONUstop()
{
// TODO: Add your control notification handler code here
if(real)
real->Send_ASDU_Ucommand(CMD_USTOP);
}
void CMaster104_DemoDlg::OnBUTTONconnect()
{
// TODO: Add your control notification handler code here
if(real)
real->Send_ASDU_Ucommand(CMD_CONN);
}
void CMaster104_DemoDlg::OnBUTTONdisconn()
{
// TODO: Add your control notification handler code here
if(real)
real->Send_ASDU_Ucommand(CMD_DISCONN);
}
void CMaster104_DemoDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(real)
{
m_conn=real->GetSockConnectStatus();
m_start=real->GetUstartStatus();
UpdateData(0);
}
CDialog::OnTimer(nIDEvent);
}
//DEL void CMaster104_DemoDlg::OnSize(UINT nType, int cx, int cy)
//DEL {
//DEL CDialog::OnSize(nType, cx, cy);
//DEL
//DEL // TODO: Add your message handler code here
//DEL
//DEL m_list.SetWindowPos(this,
//DEL 0,0,cx,cy,SWP_NOZORDER);
//DEL }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -