📄 111copy3dlg.cpp
字号:
// 111copy3Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "111copy3.h"
#include "111copy3Dlg.h"
#include "ch365dll.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()
/////////////////////////////////////////////////////////////////////////////
// CMy111copy3Dlg dialog
CMy111copy3Dlg::CMy111copy3Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CMy111copy3Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMy111copy3Dlg)
m_oIoBase = _T("");
m_oMemBase = _T("");
m_oIntLine = 0;
m_cAddr = _T("");
m_cAddrR = _T("");
m_cAddrW = _T("");
m_mAddr = _T("");
m_mAddrR = _T("");
m_mAddrW = _T("");
m_d = _T("");
m_data = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMy111copy3Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMy111copy3Dlg)
DDX_Text(pDX, IDC_EDIT1, m_oIoBase);
DDX_Text(pDX, IDC_EDIT2, m_oMemBase);
DDX_Text(pDX, IDC_EDIT3, m_oIntLine);
DDX_Text(pDX, IDC_EDIT4, m_cAddr);
DDX_Text(pDX, IDC_EDIT5, m_cAddrR);
DDX_Text(pDX, IDC_EDIT6, m_cAddrW);
DDX_Text(pDX, IDC_EDIT7, m_mAddr);
DDX_Text(pDX, IDC_EDIT8, m_mAddrR);
DDX_Text(pDX, IDC_EDIT9, m_mAddrW);
DDX_Text(pDX, IDC_EDIT10, m_d);
DDX_Text(pDX, IDC_EDIT11, m_data);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMy111copy3Dlg, CDialog)
//{{AFX_MSG_MAP(CMy111copy3Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_BUTTON1, OnOpen)
ON_EN_CHANGE(IDC_EDIT1, OnIoEdit1)
ON_EN_CHANGE(IDC_EDIT2, OnMemEdit2)
ON_EN_CHANGE(IDC_EDIT3, OnIntEdit3)
ON_EN_CHANGE(IDC_EDIT4, OnChAddrEdit4)
ON_EN_CHANGE(IDC_EDIT5, OnChAddrREdit5)
ON_EN_CHANGE(IDC_EDIT6, OnChAddrWEdit6)
ON_BN_CLICKED(IDC_BUTTON2, OnChRead)
ON_BN_CLICKED(IDC_BUTTON3, OnChWrite)
ON_EN_CHANGE(IDC_EDIT7, OnMemAddrEdit7)
ON_EN_CHANGE(IDC_EDIT8, OnMemAddrREdit8)
ON_EN_CHANGE(IDC_EDIT9, OnMemAddrWEdit9)
ON_BN_CLICKED(IDC_BUTTON4, OnMemRead)
ON_BN_CLICKED(IDC_BUTTON5, OnMemWrite)
ON_BN_CLICKED(IDC_BUTTON6, OnSelectFile)
ON_BN_CLICKED(IDC_BUTTON7, OnShowFile)
ON_EN_CHANGE(IDC_EDIT10, OnDataShowEdit10)
ON_BN_CLICKED(IDC_BUTTON8, OnDateTran)
ON_BN_CLICKED(IDC_BUTTON9, OnMcuInt)
ON_BN_CLICKED(IDC_BUTTON10, OnDataBack)
ON_EN_CHANGE(IDC_EDIT11, OnDataBackEdit11)
ON_BN_CLICKED(IDC_BUTTON11, OnOK)
ON_BN_CLICKED(IDC_BUTTON12, OnCancel)
ON_BN_CLICKED(IDC_BUTTON13, OnClose)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy111copy3Dlg message handlers
BOOL CMy111copy3Dlg::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 CMy111copy3Dlg::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 CMy111copy3Dlg::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 CMy111copy3Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMy111copy3Dlg::OnRadio1()
{
iIndex=0;
}
void CMy111copy3Dlg::OnRadio2()
{
iIndex=1;
}
void CMy111copy3Dlg::OnOpen()
{
if(LoadLibrary("CH365DLL.DLL")==NULL)return;
if(CH365mOpenDevice(iIndex,TRUE,TRUE)==INVALID_HANDLE_VALUE) return;
CH365mGetIoBaseAddr(iIndex,&oIoBase);
m_oIoBase.Format(_T("%X\x0"),oIoBase);
CH365mGetMemBaseAddr(iIndex,&oMemBase);
m_oMemBase.Format(_T("%X\x0"),oMemBase);
CH365mGetIntLine(iIndex,&oIntLine );
m_oIntLine=oIntLine;
UpdateData(FALSE);
}
void CMy111copy3Dlg::OnIoEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CMy111copy3Dlg::OnMemEdit2()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CMy111copy3Dlg::OnIntEdit3()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
USHORT CMy111copy3Dlg::Ctom(CString str) //ASCII码字符转化为十六进制
{
USHORT num1,num2,num;
UCHAR cha1,cha2;
cha1=str[0];
cha2=str[1];
if ( cha1 >= '0' && cha1 <= '9' ) num1 = cha1 -'0';
else if ( cha1 >= 'A' && cha1 <= 'F' ) num1= cha1 - 'A' + 0x0a;
else if ( cha1 >= 'a' && cha1 <= 'f' ) num1 = cha1 - 'a' + 0x0a;
else
{
AfxMessageBox("请输入正确地址");
num1=0;
}
if ( cha2 >= '0' && cha2 <= '9' ) num2 = cha2 -'0';
else if ( cha2 >= 'A' && cha2 <= 'F' ) num2= cha2 - 'A' + 0x0a;
else if ( cha2 >= 'a' && cha2 <= 'f' ) num2= cha2- 'a' + 0x0a;
else
{
AfxMessageBox("请输入正确地址,否则将显示00H的值");
num2=0;
}
num=num1*16+num2;
return num;
}
void CMy111copy3Dlg::OnChAddrEdit4()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CMy111copy3Dlg::OnChAddrREdit5()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CMy111copy3Dlg::OnChAddrWEdit6()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CMy111copy3Dlg::OnChRead()
{
UpdateData(TRUE);
cAddr=Ctom(m_cAddr);
CH365mReadConfig(iIndex,(PVOID)cAddr,&cAddrR);
m_cAddrR.Format(_T("%X"),cAddrR);
UpdateData(FALSE);
}
void CMy111copy3Dlg::OnChWrite()
{
UpdateData(TRUE);
cAddr=Ctom(m_cAddr);
cAddrW=Ctom(m_cAddrW);
CH365mWriteConfig(iIndex,(PVOID)cAddr, cAddrW);
}
void CMy111copy3Dlg::OnMemAddrEdit7()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CMy111copy3Dlg::OnMemAddrREdit8()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CMy111copy3Dlg::OnMemAddrWEdit9()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CMy111copy3Dlg::OnMemRead()
{
if(LoadLibrary("CH365DLL.DLL")==NULL)return;
if(CH365mOpenDevice(iIndex,TRUE,TRUE)==INVALID_HANDLE_VALUE) return;
UpdateData(TRUE);
mAddr=Ctom(m_mAddr);
CH365mReadMemByte(iIndex, &oMemBase->mCh365MemPort[0x00+mAddr],&mAddrR);
m_mAddrR.Format(_T("%X"),mAddrR);
UpdateData(FALSE);
}
void CMy111copy3Dlg::OnMemWrite()
{
UpdateData(TRUE);
mAddr=Ctom(m_mAddr);
mAddrW=Ctom(m_mAddrW);
CH365mWriteMemByte(iIndex,&oMemBase->mCh365MemPort[0x00+mAddr], mAddrW);
}
void CMy111copy3Dlg::OnSelectFile()
{
CFileDialog FileDlg (TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"ALL Files (*.*)|*.*| |",AfxGetMainWnd());
if(FileDlg.DoModal()==IDOK)
{
sFileName = FileDlg.GetPathName();
CString strFile="选择文件"+FileDlg.GetFileName();
AfxMessageBox(strFile);
}
}
void CMy111copy3Dlg::OnShowFile()
{
CFile mFile(sFileName,CFile::modeRead);
j=mFile.GetLength();
d=new char[j];
mFile.Read(d,j);
mFile.Close();
for(i=0;i<j;i++)
{
m_d=m_d+d[i];
UpdateData(FALSE);
}
}
void CMy111copy3Dlg::OnDataShowEdit10()
{
// m_d=d;
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CMy111copy3Dlg::OnDateTran()
{
CH365mWriteIoByte(iIndex,&oIoBase->mCh365IoPort[0x00FA],0x00); /*设定读写脉冲宽度为30ns*/
for(i=0;i<j;i++)
{
CH365mWriteMemByte(iIndex,&oMemBase->mCh365MemPort[0x000+i],d[i]);
}
delete [] d;
}
void CMy111copy3Dlg::OnMcuInt()
{
CH365mWriteIoByte(iIndex,&oIoBase->mCh365IoPort[0x0000],0x00);
Sleep(100);
}
void CMy111copy3Dlg::OnDataBack()
{
dback=new char[j];
for(i=0;i<j;i++)
{
CH365mReadMemByte(iIndex, &oMemBase->mCh365MemPort[0x4000+i],&mdata);
dback[i]=mdata;
m_data=m_data+dback[i];
UpdateData(FALSE);
}
delete [] dback;
}
void CMy111copy3Dlg::OnDataBackEdit11()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CMy111copy3Dlg::OnOK()
{
CDialog::OnOK();
}
void CMy111copy3Dlg::OnCancel()
{
CDialog::OnCancel();
}
void CMy111copy3Dlg::OnClose()
{
CH365mCloseDevice(iIndex);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -