📄 tkdlg.cpp
字号:
// TKDLG.cpp : implementation file
//
#include "stdafx.h"
#include "小车控制程序.h"
#include "TKDLG.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTKDLG dialog
CTKDLG::CTKDLG(CWnd* pParent /*=NULL*/)
: CDialog(CTKDLG::IDD, pParent)
{
//{{AFX_DATA_INIT(CTKDLG)
//}}AFX_DATA_INIT
}
void CTKDLG::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTKDLG)
DDX_Control(pDX, IDC_BUTTON3, m_bt3);
DDX_Control(pDX, IDC_GIF2, m_gif2);
DDX_Control(pDX, IDC_BUTTON2, m_stop_button);
DDX_Control(pDX, IDC_BUTTON1, m_start_button);
DDX_Control(pDX, IDC_MSCOMM1, m_tk_com);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTKDLG, CDialog)
//{{AFX_MSG_MAP(CTKDLG)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTKDLG message handlers
void CTKDLG::OnButton3()
{
// TODO: Add your control notification handler code here
OnOK();
}
void CTKDLG::OPEN_TK_COM()
{
m_tk_com.SetCommPort(2);
//m_com.SetInBufferSize(1024);
//m_com.SetOutBufferCount(512);
if (!m_tk_com.GetPortOpen()) m_tk_com.SetPortOpen(true);
m_tk_com.SetInputMode(1); //设置输入为二进制方式
m_tk_com.SetSettings("9600,n,8,1");
m_tk_com.SetRThreshold(1); //一个字符引发一个事件
m_tk_com.SetInputLen(0);
}
BOOL CTKDLG::OnInitDialog()
{
CDialog::OnInitDialog();
m_start_button.EnableWindow(true);
m_stop_button.EnableWindow(false);
tk_send_data[0]='#';
tk_send_data[1]='t';
tk_send_data[2]='k';
tk_send_data[4]='*';
OPEN_TK_COM();
// TODO: Add extra initialization here
if (m_gif2.Load(MAKEINTRESOURCE(IDR_GIF_XUXIAN_S),_T("Gif")))
m_gif2.Draw();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CTKDLG::OnButton1()
{
// TODO: Add your control notification handler code here
int i;
m_start_button.EnableWindow(FALSE);
m_stop_button.EnableWindow(true);
m_stop_button.SetFocus();
if (m_gif2.Load(MAKEINTRESOURCE(IDR_GIF3),_T("Gif")))
m_gif2.Draw();
tk_send_data[3]='1';
CByteArray send;
send.RemoveAll();
send.SetSize(5);
for(i = 0; i <5; i++)
send.SetAt(i, tk_send_data[i]);
//Sleep(5000);
m_tk_com.SetOutput(COleVariant(send));
}
void CTKDLG::OnButton2()
{
// TODO: Add your control notification handler code here
if (m_gif2.Load(MAKEINTRESOURCE(IDR_GIF_XUXIAN_STOP),_T("Gif")))
m_gif2.Draw();
int i;
m_start_button.EnableWindow(true);
m_start_button.SetFocus();
m_stop_button.EnableWindow(false);
tk_send_data[3]='2';
CByteArray send;
send.RemoveAll();
send.SetSize(5);
for(i = 0; i <5; i++)
send.SetAt(i, tk_send_data[i]);
m_tk_com.SetOutput(COleVariant(send));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -