📄 e2prwdlg.cpp
字号:
// E2pRWDlg.cpp : implementation file
//
#include "stdafx.h"
#include "E2PRW.h"
#include "E2PRWDlg.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
// ON_MESSAGE(WM_PRO_MSG,OnProMsg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CE2PRWDlg dialog
CE2PRWDlg::CE2PRWDlg(CWnd* pParent /*=NULL*/)
: CDialog(CE2PRWDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CE2PRWDlg)
m_edit1 = _T("");
m_filepath = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CE2PRWDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CE2PRWDlg)
DDX_Control(pDX, IDC_PROGRESS1, m_ProgreessCtrl);
DDX_Control(pDX, IDC_COMBO1, m_combo1);
DDX_Text(pDX, IDC_EDIT1, m_edit1);
DDX_Text(pDX, IDC_EDIT2, m_filepath);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CE2PRWDlg, CDialog)
//{{AFX_MSG_MAP(CE2PRWDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, WriteButton)
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
ON_BN_CLICKED(IDC_BUTTON2, EaseButton)
ON_BN_CLICKED(IDC_BUTTON3, ReadButton)
ON_BN_CLICKED(IDC_BUTTON4, OpenfileButton)
ON_BN_CLICKED(IDC_BUTTON5, SaveFileButton)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_BUTTON6, CheckButton)
ON_BN_CLICKED(IDC_BUTTON7, CompButton)
ON_MESSAGE(WM_PRO_MSG,OnProMsg)
ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
//}}AFX_MSG_MAP
//ON_MESSAGE(WM_THREADENDED,OnPress)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CE2PRWDlg message handlers
BOOL CE2PRWDlg::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
E2p.InitPro();
m_combo1.AddString("24C01");
m_combo1.AddString("25C01A");
m_combo1.AddString("24C02");
m_combo1.AddString("24C04");
m_combo1.AddString("24C08");
m_combo1.AddString("24C16");
m_combo1.AddString("24C164");
m_combo1.AddString("24C32");
m_combo1.AddString("24C64");
m_combo1.AddString("24C128");
m_combo1.AddString("24C256");
m_combo1.AddString("24C512");
//m_combo1.AddString("24C1024");
m_combo1.SetCurSel(0);
//读取INI文件
IniFile.SetFileName("ini.ini");
CString ls;
ls= IniFile.GetString("Setup","TYPE","10");//里面的10表示该数据为空时的默认值
m_combo1.SetCurSel(atoi(ls));
ls= IniFile.GetString("Setup","SDAO","3");
E2p.SDAO=atoi(ls);
ls= IniFile.GetString("Setup","SDAI","15");
E2p.SDAI=atoi(ls);
ls= IniFile.GetString("Setup","SCL","2");
E2p.SCL=atoi(ls);
//ls= IniFile.GetString("Setup","YS","45");
//E2p.ys=atoi(ls);
UpdateData(false);
OnSelchangeCombo1();
m_ProgreessCtrl.SetRange(0,100);
m_ProgreessCtrl.SetPos(0);
E2p.close();
//下面是增加的一句加载真彩工具条,可以修改后3个参数看不同效果
/* m_wndToolBar.LoadTrueColorToolBar( 42, IDB_BITMAP2, IDB_BITMAP2, IDB_BITMAP2);
if (!m_wndStatusBar.Create(this) ||!m_wndStatusBar.SetIndicators(indicators,sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
//EnableDocking(CBRS_ALIGN_ANY);
//DockControlBar(&m_wndToolBar);*/
return TRUE; // return TRUE unless you set the focus to a control
}
void CE2PRWDlg::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 CE2PRWDlg::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 CE2PRWDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CE2PRWDlg::OnOK()
{
CDialog::OnOK();
}
void CE2PRWDlg::OnCancel()
{
CDialog::OnCancel();
}
void CE2PRWDlg::WriteButton()
{
int i;
E2p.open();
E2p.dealy(30);
for(i=0;i<E2p.size+1;i++)
{
if(E2p.i2c_read(i)!=E2p.m_pWriteBuf[i])
E2p.i2c_write(i,E2p.m_pWriteBuf[i]);
m_ProgreessCtrl.SetPos((i+1)*100/(E2p.size-1));
}
E2p.close();
m_ProgreessCtrl.SetPos(0);
AfxMessageBox("写入成功!");
}
void CE2PRWDlg::OnSelchangeCombo1()//改变组合框后执行
{
/*CString temp;
int a=m_combo1.GetCurSel();//获取选择的ID号
temp.Format("%d",a);
IniFile.SetString("Setup","TYPE",temp);
//AfxMessageBox(temp);*/
CString type;
m_combo1.GetLBText(m_combo1.GetCurSel(),type); //获取选择的文本
if (type=="24C01")
{
E2p.page=4;E2p.size=128;
}
else if (type=="25C01A")
{
E2p.page=8;E2p.size=256;
}
else if (type=="24C02")
{
E2p.page=8;E2p.size=256;
}
else if (type=="24C04")
{
E2p.page=16;E2p.size=512;
}
else if (type=="24C08")
{
E2p.page=16;E2p.size=1024;
}
else if (type=="24C16")
{
E2p.page=16;E2p.size=2048;
}
else if (type=="24C164")
{
E2p.page=16;E2p.size=2048;
}
else if (type=="24C32")
{
E2p.page=32;E2p.size=4096;
}
else if (type=="24C64")
{
E2p.page=32;E2p.size=8192;
}
else if (type=="24C128")
{
E2p.page=64;E2p.size=16384;
}
else if (type=="24C256")
{
E2p.page=64;E2p.size=32768;
}
else if (type=="24C512")
{
E2p.page=128;E2p.size=65536;
}
else if (type=="24C1024")
{
E2p.page=256;E2p.size=131072;
}
else
{
AfxMessageBox("选择错误!");
}
}
void CE2PRWDlg::EaseButton()
{
int i;
E2p.open();
E2p.dealy(30);
for(i=0;i<E2p.size+1;i++)
{
if(E2p.i2c_read(i)!=0xff)
E2p.i2c_write(i,0xff);
m_ProgreessCtrl.SetPos((i+1)*100/(E2p.size-1));
}
E2p.close();
m_ProgreessCtrl.SetPos(0);
AfxMessageBox("清空完毕!");
// CheckButton() ;
}
void CE2PRWDlg::ReadButton()
{
E2p.open();
E2p.dealy(30);
CString aa;
int i;
E2p.dealy(10);
for (i=0;i<E2p.size;i++)
{
E2p.dealy(30);
E2p.m_pWriteBuf[i]=E2p.i2c_read(i);
m_ProgreessCtrl.SetPos((i+1)*100/(E2p.size-1));
}
E2p.dealy(30);
E2p.close();
Diaply();
m_ProgreessCtrl.SetPos(0);
AfxMessageBox("读完毕!");
}
void CE2PRWDlg::write()
{
IniFile.SetString("Setup","SDAI","3");
IniFile.SetString("Setup","SDAO","15");
IniFile.SetString("Setup","SCL","2");
IniFile.SetString("Setup","TYPE","1");
}
void CE2PRWDlg::OpenfileButton()
{
CFileDialog dlg(TRUE, "EC", "*.bin",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"二进制文件(*.bin)|*.bin");
if ( dlg.DoModal()!=IDOK ) return;
{
sFileName=dlg.GetPathName();//获取文件的绝对路径
m_filepath=sFileName;
FilePath=m_filepath;
UpdateData(false);
OpenFile();
}
}
void CE2PRWDlg::SaveFileButton()
{
CFileDialog dlg(false, "EC", "*.bin",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"二进制文件(*.bin)|*.bin");
if ( dlg.DoModal()!=IDOK ) return;
{
CString sFileName=dlg.GetPathName();//获取文件的绝对路径
if(m_fileSave.Open(dlg.GetPathName(),CFile::shareCompat|CFile::modeCreate|CFile::modeWrite,NULL))
{
m_fileSave.Write(E2p.m_pWriteBuf,E2p.size);
m_fileSave.Close();
}
}
AfxMessageBox("保存完毕!");
}
bool CE2PRWDlg::OpenFile()
{
CFile m_fileOpen;
if(sFileName!="")
{
if(m_fileOpen.Open(sFileName,CFile::shareCompat|CFile::modeRead,NULL))
{
int nFileSize;
nFileSize=m_fileOpen.GetLength();
memset(E2p.m_pWriteBuf,0xff,0x10000);
m_fileOpen.Read(E2p.m_pWriteBuf,nFileSize);
//m_editBuf1.SetData(m_Pro.m_pWriteBuf,0x10000);
m_fileOpen.Close();
Diaply();
}
else
{
return FALSE;
}
}
else
{
ShowMsg("请先打开文件.");
return FALSE;
}
return TRUE;
/* FILE * file; //申明一个文件指针
//BYTE * psz=new BYTE[1002]; //申明一个数组大小为1000
memset(E2p.m_pWriteBuf,0,E2p.size); //清0
file=fopen(sFileName,"rb"); //以二进制只读打开
int frlens;
frlens=fread(E2p.m_pWriteBuf,sizeof(BYTE),1000,file); //读去数据返回实际读长度
fclose(file);*/ //关闭文件
}
void CE2PRWDlg::OnClose() //关闭前执行代码
{
CString b;
//保存配置到INI文件
int id=m_combo1.GetCurSel();//获取选择的ID号
b.Format("%d",id);
IniFile.SetString("Setup","TYPE",b);
b.Format("%d",E2p.page);
IniFile.SetString("Setup","page",b);
b.Format("%d",E2p.size);
IniFile.SetString("Setup","size",b);
b.Format("%d",E2p.SDAO);
IniFile.SetString("Setup","SDA0",b);
b.Format("%d",E2p.SDAI);
IniFile.SetString("Setup","SDAI",b);
b.Format("%d",E2p.SCL);
IniFile.SetString("Setup","SCL",b);
//b.Format("%d",E2p.ys);
//IniFile.SetString("Setup","YS",b);
CDialog::OnClose();
}
void CE2PRWDlg::CheckButton()
{
E2p.open();
CString aa;
int i;
for (i=0;i<E2p.size;i++)
{
E2p.open();
if(E2p.i2c_read(i)!=0xFF)
{
aa.Format("(0X%05X).",i);
AfxMessageBox("在地址"+aa+"非空!");
return;
}
m_ProgreessCtrl.SetPos((i+1)*100/(E2p.size-1));
E2p.close();
}
AfxMessageBox("查空OK!");
m_ProgreessCtrl.SetPos(0);
}
void CE2PRWDlg::Diaply()
{
int i;
m_edit1="";
CString lsbuffer,lsbuffer1,lsbuffer2,lsbuffer3,count;
for (i=1;i<E2p.size+1;i++) //将文件的二进制转换成文本送编辑框显示
{
lsbuffer.Format("%02X ",E2p.m_pWriteBuf[i-1]);
lsbuffer1+=lsbuffer;
if (E2p.m_pWriteBuf[i-1]!=0x0A||E2p.m_pWriteBuf[i-1]!=0x0A) lsbuffer.Format("%.1c",E2p.m_pWriteBuf[i-1]);
else lsbuffer='.';
if(lsbuffer=='?')lsbuffer3+=' ';
else lsbuffer3+=lsbuffer;
if(i%16==0)
{
lsbuffer2.Format(" %05X | ",i-16);
m_edit1+=lsbuffer2+lsbuffer1+" | "+lsbuffer3+"";
if(i!=E2p.size)m_edit1+="\r\n";
lsbuffer1="";lsbuffer3="";
}
}
UpdateData(false);
}
void CE2PRWDlg::CompButton()
{
E2p.open();
CString aa;
int i;
for (i=0;i<E2p.size;i++)
{
if(E2p.m_pWriteBuf[i]!=E2p.i2c_read(i))
{
bz=0;
break;
}
else bz=1;
m_ProgreessCtrl.SetPos((i+1)*100/(E2p.size-1));
}
E2p.close();
m_ProgreessCtrl.SetPos(0);
aa.Format("(0X%05X).",i);
if(bz==0)AfxMessageBox("在地址"+aa+"校验出错!");
else
AfxMessageBox("校验通过!");
}
void CE2PRWDlg::OnPress(UINT a)
{
//AfxMessageBox("收到消息!");
//m_ProgreessCtrl.SetPos(a*100/(E2p.size-1));
}
void CE2PRWDlg::ShowMsg(CString strMsg)
{
}
UINT CE2PRWDlg::OnProMsg(WPARAM dwMsg,LPARAM dwMsg2)
{
m_ProgreessCtrl.SetPos(dwMsg);
//AfxMessageBox("发送消息成功!"+dwMsg);
return 0;
}
void CE2PRWDlg::OnButton8()
{
E2p.open();
E2p.dealy(30);
E2p.i2c_pagewrite(0x00,1,1);
CString aa;
// aa.Format("(0X%02X).",E2p.ReadFm24c256(0x00));
AfxMessageBox("aa");
E2p.close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -