⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ram.cpp

📁 有关树WDM 驱动的编程.里面包含了许多实例,学习硬件的可以参考哦
💻 CPP
字号:
// Ram.cpp : implementation file
//

#include "stdafx.h"
#include "pctest.h"
#include "Ram.h"
#include "HexEdit.h"
#include "adc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CHexEdit m_date1,m_date2;
/////////////////////////////////////////////////////////////////////////////
// CRam dialog
extern HANDLE	hDevice;
extern HANDLE	hDevice1;
extern  PCHAR mDynVxDName ;

CRam::CRam(CWnd* pParent /*=NULL*/)
	: CDialog(CRam::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRam)
	m_size = 0;
	m_way = -1;
	//}}AFX_DATA_INIT


	hDevice1=NULL;
	addoff=0x0000;
}


void CRam::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRam)
	DDX_Text(pDX, IDC_EDIT3, m_size);
	DDX_Radio(pDX, IDC_RADIO1, m_way);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CRam, CDialog)
	//{{AFX_MSG_MAP(CRam)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
	ON_BN_CLICKED(IDC_BUTTON1, OnWrite)
	ON_BN_CLICKED(IDC_BUTTON2, OnRead)
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRam message handlers

BOOL CRam::OnInitDialog() 
{
	CDialog::OnInitDialog();
	// TODO: Add extra initialization here
	UpdateData(FALSE);
	m_date1.SubclassDlgItem(IDC_EDIT1, this );
	m_date1.m_bShowAddress=FALSE;
	m_date1.m_bShowHex=FALSE;
	
	m_date2.SubclassDlgItem(IDC_EDIT2, this );
	m_date2.m_bShowAddress=FALSE;
	m_date2.m_bShowHex=FALSE;
	if(hDevice==NULL)
	{
	hDevice = CreateFile(mDynVxDName,
					  GENERIC_READ | GENERIC_WRITE,
					  FILE_SHARE_READ,
					  NULL,
					  OPEN_EXISTING,
					  0,
					  NULL);
	if(hDevice==INVALID_HANDLE_VALUE)
	{
		AfxMessageBox("请检查板卡和驱动程序");
		CDialog::OnCancel();
		return FALSE;
	}
			pMem=(Mem_Param*)malloc(sizeof(Mem_Param));
			BOOL status =  DeviceIoControl(
					hDevice, 
			    	IOCTL_MEM, 
					NULL, 
					0,
					pMem, 
					sizeof(pMem), 
					&nRet, 
 					NULL);
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


void CRam::OnRadio1() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_date1.m_length=128;
	m_date1.m_pData =(LPBYTE)malloc(m_date1.m_length);
	for(int x=0;x<128;x++)
	{
      m_date1.m_pData [x]=0;
	}
   m_date1.m_bUpdate=TRUE;
   m_date1.m_bShowAddress=TRUE;
   m_date1.m_bShowHex=TRUE;
    m_date1.SetScrollPos(SB_VERT,0);
   m_date1.Invalidate ();
}
  


void CRam::OnRadio2() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
		m_date1.m_length=128;
	m_date1.m_pData =(LPBYTE)malloc(m_date1.m_length);
	for(int x=0;x<128;x++)
	{
      m_date1.m_pData [x]=0xff;
	}
    m_date1.m_bUpdate=TRUE;
    m_date1.m_bShowAddress=TRUE;
	m_date1.m_bShowHex=TRUE;
	m_date1.SetScrollPos(SB_VERT,0);
    m_date1.Invalidate ();
}

void CRam::OnRadio3() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_date1.m_length=128;
	m_date1.m_pData =(LPBYTE)malloc(m_date1.m_length);
	for(int x=0;x<128;x++)
	{
      m_date1.m_pData [x]=(BYTE)rand();
	}
    m_date1.m_bUpdate=TRUE;
    m_date1.m_bShowAddress=TRUE;
	m_date1.m_bShowHex=TRUE;
	 m_date1.SetScrollPos(SB_VERT,0);
    m_date1.Invalidate ();
}

void CRam::OnOK() 
{
	// TODO: Add extra validation here
	if(hDevice1!=NULL)
	{
	CloseHandle( hDevice1);
	hDevice1=NULL;
	}
	if(hDevice!=NULL)
	{
	CloseHandle( hDevice);
	hDevice=NULL;
	}
	
	CDialog::OnOK();
}

void CRam::OnWrite() 
{
	// TODO: Add your control notification handler code here
//memcpy((PBYTE)pci->MemBase,&m_date1.m_pData [0],m_date1.m_length);
  // BYTE a;
  // a=m_date1.m_pData [0];
	PBYTE m_d;
	m_d=(PBYTE)pMem->mdr_LinearAddress+addoff;
	for(int x=0;x<m_date1.m_length;x++)
	{
	  *m_d=m_date1.m_pData [x];
	  m_d=m_d+1;
	  
     }
}

void CRam::OnRead() 
{
	// TODO: Add your control notification handler code here
	m_date2.m_length=m_date1.m_length;
	PBYTE m_d;
	m_d=(PBYTE)pMem->mdr_LinearAddress+addoff;
	m_date2.m_pData =(LPBYTE)malloc(m_date2.m_length);
	for(int x=0;x<m_date2.m_length;x++)
	{
    m_date2.m_pData [x]=*m_d;
	m_d=m_d+1;
	}
    m_date2.m_bUpdate=TRUE;
    m_date2.m_bShowAddress=TRUE;
    m_date2.m_bShowHex=TRUE;
	m_date2.SetScrollPos(SB_VERT,0);
    m_date2.Invalidate ();
	
}

void CRam::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnClose();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -