📄 comdlgdlg.cpp
字号:
// ComDlgDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ComDlg.h"
#include "ComDlgDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CComDlgDlg dialog
CComDlgDlg::CComDlgDlg(CWnd* pParent /*=NULL*/)
: CDialog(CComDlgDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CComDlgDlg)
m_e = _T("");
m_strSend = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CComDlgDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CComDlgDlg)
DDX_Text(pDX, IDC_EDIT1, m_e);
DDX_Text(pDX, IDC_EDIT2, m_strSend);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CComDlgDlg, CDialog)
//{{AFX_MSG_MAP(CComDlgDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnSend)
ON_BN_CLICKED(IDC_BUTTON4, OnButtonVAG)
ON_BN_CLICKED(IDC_BUTTON5, OnButtonAV)
ON_BN_CLICKED(IDC_BUTTON6, OnButtonBAOXIAN)
ON_BN_CLICKED(IDC_BUTTON7, OnButtonKAIPAO)
ON_BN_CLICKED(IDC_BUTTON_BAOSHAN_OPEN, OnButtonBaoshanOpen)
ON_BN_CLICKED(IDC_BUTTON_BAOSHAN_CLOSE, OnButtonBaoshanClose)
ON_BN_CLICKED(IDC_BUTTON_COMPUTER_POWER, OnButtonComputerPower)
ON_BN_CLICKED(IDC_BUTTON_POWER, OnButtonPower)
ON_BN_CLICKED(IDC_BUTTON_YUYIN_CLOSE, OnButtonYuyinClose)
ON_BN_CLICKED(IDC_BUTTON_YUYIN_OPEN, OnButtonYuyinOpen)
ON_BN_CLICKED(IDC_JIANSHI_DOWN, OnJianshiDown)
ON_BN_CLICKED(IDC_JIANSHI_JIN, OnJianshiJin)
ON_BN_CLICKED(IDC_JIANSHI_LEFT, OnJianshiLeft)
ON_BN_CLICKED(IDC_JIANSHI_RIGHT, OnJianshiRight)
ON_BN_CLICKED(IDC_JIANSHI_UP, OnJianshiUp)
ON_BN_CLICKED(IDC_JIANSHI_YUAN, OnJianshiYuan)
ON_BN_CLICKED(IDC_MIAOZHUN_DOWN, OnMiaozhunDown)
ON_BN_CLICKED(IDC_MIAOZHUN_LEFT, OnMiaozhunLeft)
ON_BN_CLICKED(IDC_MIAOZHUN_RIGHT, OnMiaozhunRight)
ON_BN_CLICKED(IDC_MIAOZHUN_UP, OnMiaozhunUp)
//}}AFX_MSG_MAP
ON_MESSAGE(ON_COM_RECEIVE, On_Receive)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CComDlgDlg message handlers
BOOL CComDlgDlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CComDlgDlg::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 CComDlgDlg::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 CComDlgDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CComDlgDlg::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
LRESULT CComDlgDlg::On_Receive(WPARAM wp, LPARAM lp)
{
int len;
char str[100];
len = com2.read(str, 100);
if(len > 0)
{
char com_str[10];
strcpy(com_str, "COM");
ltoa((long)wp, com_str + 3, 10); // WPARAM 保存端口号
m_e += com_str;
m_e += " : ";
m_e += str;
m_e += "\r\n";
UpdateData(false);
}
return 0;
}
void CComDlgDlg::OnButton1()
{
//API函数应该默认就是字符方式传送的???
char str[]="19200,e,7,2";//定义波特率什么的
if(!com2.open(1,str)) //打开第一个com口。
MessageBox("open fail", "COM1", MB_OK);
else
com2.set_hwnd(m_hWnd); //设置接受消息的窗口
}
void CComDlgDlg::OnButton2()
{
com2.close();
}
void CComDlgDlg::SendTest(char * str)
{
char TData[300];
int Count= strlen(str);
for(int i=0;i<Count;i++)
TData[i]=str[i];
FCScheck(TData,Count);//给要发送的命令帧添加校验码以及结束符
MessageBox(TData, "TData:", MB_OK);//???
Count=Count+4;
com2.write(TData,Count);
}
void CComDlgDlg::FCScheck(char senddata[], int i)
{
//不校验了,直接加上两个字符55,行不行?不行,这样发plc没有反应。
int j;
BYTE STR[300];
BYTE sum=0x00, c1=0x0f,c2=0xf0;
for(j=0;j<i;j++)
STR[j]=senddata[j];
for(j=0;j<i;j++)
sum^=STR[j]; //异或操作
c1=c1∑
c2=c2∑
c2=c2>>4;
if(c2<=9)
STR[j]=c2+48;
else
STR[j]=c2+55;
if(c1<=9)
STR[j+1]=c1+48;
else
STR[j+1]=c1+55;
STR[j+2]='*';//添加结束符
STR[j+3]=13; //回车符号
i=j+3;
for(j=0;j<=i;j++)
senddata[j]=(char)STR[j];
}
void CComDlgDlg::OnSend()
{
UpdateData(TRUE);
//MessageBox(m_strSend);
SendTest( (char*) m_strSend.GetBuffer(m_strSend.GetLength()) );
}
void CComDlgDlg::OnButtonVAG()
{
//VGA
char TData[]={0x88,0x08,0};
com2.write(TData,2);
}
void CComDlgDlg::OnButtonAV()
{
char TData[]={0x88,0x04,0};
com2.write(TData,2);
}
void CComDlgDlg::OnButtonBAOXIAN()
{
//开炮保险
char str[]="@00WR02080008";
SendTest(str);
Sleep(10);
char str2[]="@00WR02080000";
SendTest(str2);
}
void CComDlgDlg::OnButtonKAIPAO()
{
//开炮按钮
char str[]="@00WR02080010";
SendTest(str);
Sleep(10);
char str2[]="@00WR02080000";
SendTest(str2);
}
void CComDlgDlg::OnButtonBaoshanOpen()
{
//爆闪灯开
char str[]="@00WR02080020";
SendTest(str);
Sleep(10);
char str2[]="@00WR02080000";
SendTest(str2);
}
void CComDlgDlg::OnButtonBaoshanClose()
{
//爆闪灯关
char str[]="@00WR02080040";
SendTest(str);
Sleep(10);
char str2[]="@00WR02080000";
SendTest(str2);
}
void CComDlgDlg::OnButtonComputerPower()
{
//计算机电源
char str[]="@00WR02080400";
SendTest(str);
Sleep(10);
char str2[]="@00WR02080000";
SendTest(str2);
}
void CComDlgDlg::OnButtonPower()
{
//总电源
char str[]="@00WR02080200";
SendTest(str);
Sleep(10);
char str2[]="@00WR02080000";
SendTest(str2);
}
void CComDlgDlg::OnButtonYuyinClose()
{
//语音系统关
char str[]="@00WR02080100";
SendTest(str);
Sleep(10);
char str2[]="@00WR02080000";
SendTest(str2);
}
void CComDlgDlg::OnButtonYuyinOpen()
{
//语音系统关
char str[]="@00WR02080080";
SendTest(str);
Sleep(10);
char str2[]="@00WR02080000";
SendTest(str2);
}
void CComDlgDlg::OnJianshiDown()
{
//监视云台下
char str[]="@00WR02081000";
SendTest(str);
Sleep(10);
char str2[]="@00WR02080000";
SendTest(str2);
}
void CComDlgDlg::OnJianshiJin()
{
//监视云台近
char str[]="@00WR02090010";
SendTest(str);
Sleep(10);
char str2[]="@00WR02090000";
SendTest(str2);
}
void CComDlgDlg::OnJianshiLeft()
{
//监视云台左
char str[]="@00WR02082000";
SendTest(str);
Sleep(10);
char str2[]="@00WR02080000";
SendTest(str2);
}
void CComDlgDlg::OnJianshiRight()
{
//监视云台右
char str[]="@00WR02084000";
SendTest(str);
Sleep(10);
char str2[]="@00WR02080000";
SendTest(str2);
}
void CComDlgDlg::OnJianshiUp()
{
//监视云台上
char str[]="@00WR02080800";
SendTest(str);
Sleep(10);
char str2[]="@00WR02080000";
SendTest(str2);
}
void CComDlgDlg::OnJianshiYuan()
{
//监视云台远
char str[]="@00WR02090008";
SendTest(str);
Sleep(10);
char str2[]="@00WR02090000";
SendTest(str2);
}
void CComDlgDlg::OnMiaozhunDown()
{
//瞄准云台下
char str[]="@00WR02090001";
SendTest(str);
Sleep(10);
char str2[]="@00WR02090000";
SendTest(str2);
}
void CComDlgDlg::OnMiaozhunLeft()
{
//瞄准云台左
char str[]="@00WR02090002";
SendTest(str);
Sleep(10);
char str2[]="@00WR02090000";
SendTest(str2);
}
void CComDlgDlg::OnMiaozhunRight()
{
//瞄准云台右
char str[]="@00WR02090004";
SendTest(str);
Sleep(10);
char str2[]="@00WR02090000";
SendTest(str2);
}
void CComDlgDlg::OnMiaozhunUp()
{
//瞄准云台上
char str[]="@00WR02088000";
SendTest(str);
Sleep(10);
char str2[]="@00WR02080000";
SendTest(str2);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -