📄 pdcwannewdlg.cpp
字号:
// PDCWanNewDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PDCWanNew.h"
#include "PDCWanNewDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "PDC4000SupportFunctions.h" //引用PDC4000函数库
#include "Cx10macro.h"
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CPDCWanNewDlg dialog
CPDCWanNewDlg::CPDCWanNewDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPDCWanNewDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPDCWanNewDlg)
m_EndAddress = _T("F");
m_StartAddtess = _T("0");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CPDCWanNewDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPDCWanNewDlg)
DDX_Control(pDX, IDC_StartAddress, m_CEStartAddress);
DDX_Control(pDX, IDC_EndAddress, m_CEEndAddress);
DDX_Text(pDX, IDC_EndAddress, m_EndAddress);
DDX_Text(pDX, IDC_StartAddress, m_StartAddtess);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPDCWanNewDlg, CDialog)
//{{AFX_MSG_MAP(CPDCWanNewDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BtnWriteRAM, OnBtnWriteRAM)
ON_BN_CLICKED(IDC_BtnReadRAM, OnBtnReadRAM)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPDCWanNewDlg message handlers
BOOL CPDCWanNewDlg::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
//Connect to PDC4000.
if(!ConnectToPDC4000(GetSafeHwnd()))
{
AfxMessageBox("Can't connect to PDC4000.");
CDialog::OnCancel();
return TRUE;
}
m_EndAddress = _T("F");
m_StartAddtess = _T("0");
return TRUE; // return TRUE unless you set the focus to a control
}
void CPDCWanNewDlg::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 CPDCWanNewDlg::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 CPDCWanNewDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//写RAM数据
void CPDCWanNewDlg::OnBtnWriteRAM()
{
// int s=0;
// s = pCommProc.strHexToInt("4f");
CString strStartAddress,strTemp;
CString strEndAddress;
int istartAddress =0; //起始地址
int iEndAddress = 0; //截止地址
int i = 0;
int k = 0;
int sTotal = 0;
unsigned char ordest[MAX_ARRAY_LIMIT],brec[MAX_ARRAY_LIMIT],wbrec[MAX_ARRAY_LIMIT];
unsigned char pbySendFrameData[MAX_ARRAY_LIMIT],pbySourData[MAX_ARRAY_LIMIT],pbyDestData[MAX_ARRAY_LIMIT];
memset(pbySendFrameData,0x00,MAX_ARRAY_LIMIT);
memset(pbySourData,0x00,MAX_ARRAY_LIMIT);
memset(pbyDestData,0x00,MAX_ARRAY_LIMIT);
memset(ordest,0x00,MAX_ARRAY_LIMIT);
memset(brec,0x00,MAX_ARRAY_LIMIT);
memset(wbrec,0x00,MAX_ARRAY_LIMIT);
GetDlgItemText(IDC_StartAddress,strStartAddress); //设定的帧头数据
if (strStartAddress == "")
{
MessageBox("起始地址数据不能为空","提示",MB_ICONINFORMATION);
return;
}
if ( strlen(strStartAddress) > 4 )
{
MessageBox("输入起始地址错误","提示",MB_ICONINFORMATION);
return;
}
else
{
if (strlen(strStartAddress)<2)
{
strStartAddress = "0" + strStartAddress;
}
}
GetDlgItemText(IDC_EndAddress,strEndAddress); //设定的帧头数据
if (strEndAddress == "")
{
MessageBox("截止地址不能为空","提示",MB_ICONINFORMATION);
return;
}
if ( strlen(strEndAddress) > 4 )
{
MessageBox("输入截止地址错误","提示",MB_ICONINFORMATION);
return;
}
else
{
if (strlen(strEndAddress)<2)
{
strEndAddress = "0" + strEndAddress;
}
}
//*****************************************
//***将起始地址的十六进制转换为int
istartAddress = pCommProc.strHexToInt(strStartAddress);
//***********************************************
//***将截止地址strEndAddress的十六进制转换为int
iEndAddress = pCommProc.strHexToInt(strEndAddress);
//*************************************************
if (iEndAddress>MAX_ARRAY_LIMIT-1)
{
MessageBox("截止地址不能大于16K字节","提示",MB_ICONINFORMATION);
return;
}
else
{
if(iEndAddress<16)
{
}
}
if (istartAddress>MAX_ARRAY_LIMIT-1)
{
MessageBox("起始地址不能大于16K字节","提示",MB_ICONINFORMATION);
return;
}
else
{
if(istartAddress<16)
{
}
}
if (istartAddress > iEndAddress)
{
MessageBox("起始地址不能大于截止地址","提示",MB_ICONINFORMATION);
return;
}
//写入RAM地址的数据
unsigned char cRam[MAX_ARRAY_LIMIT];
ULONG lRam[2];
k = 16;
for ( i = istartAddress; i <= iEndAddress; i++)
{
lRam[0] = i;
//lRam[1] = 0x0a0 + k;
lRam[1] = k;
WriteDataToPDC4000(lRam);
cRam[i] = k;
k++;
}
//****************显示写RAM的数据*****************************************
CEdit *pResultEdit;
pResultEdit=(CEdit*)GetDlgItem(IDC_edWrite);
strTemp=pCommProc.ByteToStrHexNew(cRam,iEndAddress+1-istartAddress,istartAddress);
CString strContent;
strContent=strTemp+"\n";
pCommProc.WriteString(strContent,pResultEdit,"\n");
MessageBox("数据已经写入局部总线的SRAM!", "块写操作结束");
}
void CPDCWanNewDlg::OnBtnReadRAM()
{
CString strStartAddress,strTemp;
CString strEndAddress;
int istartAddress =0; //起始地址
int iEndAddress = 0; //截止地址
int i = 0;
int k = 0;
int sTotal = 0;
unsigned char ordest[MAX_ARRAY_LIMIT],brec[MAX_ARRAY_LIMIT],wbrec[MAX_ARRAY_LIMIT];
unsigned char pbySendFrameData[MAX_ARRAY_LIMIT],pbySourData[MAX_ARRAY_LIMIT],pbyDestData[MAX_ARRAY_LIMIT];
memset(pbySendFrameData,0x00,MAX_ARRAY_LIMIT);
memset(pbySourData,0x00,MAX_ARRAY_LIMIT);
memset(pbyDestData,0x00,MAX_ARRAY_LIMIT);
memset(ordest,0x00,MAX_ARRAY_LIMIT);
memset(brec,0x00,MAX_ARRAY_LIMIT);
memset(wbrec,0x00,MAX_ARRAY_LIMIT);
GetDlgItemText(IDC_StartAddress,strStartAddress); //设定的帧头数据
if (strStartAddress == "")
{
MessageBox("起始地址数据不能为空","提示",MB_ICONINFORMATION);
return;
}
if ( strlen(strStartAddress) > 4 )
{
MessageBox("输入起始地址错误","提示",MB_ICONINFORMATION);
return;
}
else
{
if (strlen(strStartAddress)<2)
{
strStartAddress = "0" + strStartAddress;
}
}
GetDlgItemText(IDC_EndAddress,strEndAddress); //设定的帧头数据
if (strEndAddress == "")
{
MessageBox("截止地址不能为空","提示",MB_ICONINFORMATION);
return;
}
if ( strlen(strEndAddress) > 4 )
{
MessageBox("输入截止地址错误","提示",MB_ICONINFORMATION);
return;
}
else
{
if (strlen(strEndAddress)<2)
{
strEndAddress = "0" + strEndAddress;
}
}
//*****************************************
//***将起始地址的十六进制转换为int
istartAddress = pCommProc.strHexToInt(strStartAddress);
//***********************************************
//***将截止地址strEndAddress的十六进制转换为int
iEndAddress = pCommProc.strHexToInt(strEndAddress);
//*************************************************
if (iEndAddress>MAX_ARRAY_LIMIT-1)
{
MessageBox("截止地址不能大于16K字节","提示",MB_ICONINFORMATION);
return;
}
else
{
if(iEndAddress<16)
{
}
}
if (istartAddress>MAX_ARRAY_LIMIT-1)
{
MessageBox("起始地址不能大于16K字节","提示",MB_ICONINFORMATION);
return;
}
else
{
if(istartAddress<16)
{
}
}
if (istartAddress > iEndAddress)
{
MessageBox("起始地址不能大于截止地址","提示",MB_ICONINFORMATION);
return;
}
//读RAM地址的数据
unsigned char cRam[MAX_ARRAY_LIMIT];
ULONG lRam;
for (i = istartAddress; i <= iEndAddress; i++)
{
lRam = i;
ReadDataFromPDC4000(&lRam);
TRACE("The read value is %x.\n", lRam);
cRam[i] = lRam;
pbySendFrameData[i] = cRam[i];
}
//****************显示读RAM的数据*****************************************
CEdit *pResultEdit;
pResultEdit=(CEdit*)GetDlgItem(IDC_edRead);
strTemp=pCommProc.ByteToStrHexNew(pbySendFrameData,iEndAddress+1-istartAddress,istartAddress);
CString strContent;
strContent=strTemp+"\n";
pCommProc.WriteString(strContent,pResultEdit,"\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -