📄 ch372dbgdlg.cpp
字号:
// CH372DBGDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CH372DBG.h"
#include "CH372DBGDlg.h"
#include "CH375DLL.h"
#define _CRTDBG_MAP_ALLOC
#include<stdlib.h>
#include<crtdbg.h>
//#include "debug_new.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()
/////////////////////////////////////////////////////////////////////////////
// CCH372DBGDlg dialog
CCH372DBGDlg::CCH372DBGDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCH372DBGDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCH372DBGDlg)
m_Index = 0;
m_Sendbox = _T("");
m_Len = 0;
m_ms = 0;
m_16JIN = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCH372DBGDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCH372DBGDlg)
DDX_Control(pDX, IDC_MO, m_MoList);
DDX_Text(pDX, IDC_INDEX, m_Index);
DDX_Text(pDX, IDC_SENDBOX, m_Sendbox);
DDX_Text(pDX, IDC_LEN, m_Len);
DDX_Text(pDX, IDC_MSEN, m_ms);
DDX_Check(pDX, IDC_CHECK1, m_16JIN);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCH372DBGDlg, CDialog)
//{{AFX_MSG_MAP(CCH372DBGDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_OPEN, OnOpen)
ON_BN_CLICKED(IDC_SEND, OnSend)
ON_BN_CLICKED(IDC_CLEAN, OnClean)
ON_LBN_DBLCLK(IDC_MO, OnDblclkMo)
ON_BN_CLICKED(IDC_TIMERON, OnTimeron)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_TIMEROFF, OnTimeroff)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCH372DBGDlg message handlers
BOOL CCH372DBGDlg::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
IsOpen=FALSE;
return TRUE; // return TRUE unless you set the focus to a control
}
void CCH372DBGDlg::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 CCH372DBGDlg::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();
}
_CrtDumpMemoryLeaks();
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CCH372DBGDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCH372DBGDlg::OnOpen()
{
// TODO: Add your control notification handler code here
if(IsOpen)
{
CH375CloseDevice(CH372_Index);
IsOpen=FALSE;
}
UpdateData();
CH372_Index=m_Index;
if(CH375OpenDevice( CH372_Index ) !=INVALID_HANDLE_VALUE)
{
IsOpen=TRUE;
}
else
{
MessageBox(_T("打开设备出错!"));
}
}
void CCH372DBGDlg::OnSend()
{
// TODO: Add your control notification handler code here
UCHAR SendPKT[150];
UCHAR GetPKT[150];
ULONG GetLen;
CString ShowGet;
m_Sendbox.Empty();
UpdateData();
for(int i=0;i<m_Sendbox.GetLength();i++)
{
if(m_Sendbox.GetAt(i)>='a'&&m_Sendbox.GetAt(i)<='z')
m_Sendbox.SetAt(i,m_Sendbox.GetAt(i)-32);
}
for( i=0;i<(int)m_Len;i++)
{
if(!((m_Sendbox.GetAt(i*3)>='A'&&m_Sendbox.GetAt(i*3)<='F')||(m_Sendbox.GetAt(i*3)>='0'&&m_Sendbox.GetAt(i*3)<='9')))
{
m_Sendbox.SetAt(i*3,'E');
}
if(!((m_Sendbox.GetAt(i*3+1)>='A'&&m_Sendbox.GetAt(i*3+1)<='F')||(m_Sendbox.GetAt(i*3+1)>='0'&&m_Sendbox.GetAt(i*3+1)<='9')))
{
m_Sendbox.SetAt(i*3+1,'E');
}
SendPKT[i]=m_StrToNum(m_Sendbox.GetAt(i*3),m_Sendbox.GetAt(i*3+1));
}
CH375WriteData(CH372_Index , SendPKT , &m_Len);
CH375ReadData(CH372_Index , GetPKT , &GetLen);
if(GetLen==0)
{
KillTimer(0);
OnOpen();
return;
}
CString TemStr;
for(i=0;i<(int)GetLen;i++)
{
if(m_16JIN)
{
char buffer[3];
ltoa(GetPKT[i],buffer,16);
buffer[2]='\0';
ShowGet=ShowGet+"0x";
ShowGet=ShowGet+buffer;
ShowGet=ShowGet+' ';
}
else
{
TemStr.Format("%d ",GetPKT[i]);
ShowGet=ShowGet+TemStr+' ';
}
}
m_MoList.InsertString(-1,ShowGet);
UpdateData(FALSE);
}
UCHAR CCH372DBGDlg::m_StrToNum(char H, char L)
{
UINT m;
UINT s;
if(H>='0'&&H<='9')
m=(H-'0')*16;
else
m=(H-'A'+10)*16;
if(L>='0'&&L<='9')
s=(L-'0');
else
s=(L-'A'+10);
return (UCHAR)(m+s);
}
void CCH372DBGDlg::OnClean()
{
// TODO: Add your control notification handler code here
m_MoList.ResetContent();
}
void CCH372DBGDlg::OnDblclkMo()
{
// TODO: Add your control notification handler code here
CString Str;
m_MoList.GetText(m_MoList.GetCurSel(),Str);
MessageBox(Str);
}
void CCH372DBGDlg::OnTimeron()
{
// TODO: Add your control notification handler code here
UpdateData();
SetTimer(0,m_ms,NULL);
}
void CCH372DBGDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
OnSend();
CDialog::OnTimer(nIDEvent);
}
void CCH372DBGDlg::OnTimeroff()
{
// TODO: Add your control notification handler code here
KillTimer(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -