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

📄 32bitout.cpp

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

#include "stdafx.h"
#include "pctest.h"
#include "32bitout.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "adc.h"
/////////////////////////////////////////////////////////////////////////////
// C32bitout dialog
extern PCHAR  mDynVxDName; //"\\\\.\\MatyDevice0";
#define LAS1BRD 0x2e
unsigned char vect[32]={0x00,  0x00,		//1
			   0x02,  0x00,		//2
			   0x02,  0x00,		//3
			   0x02,  0x10,		//4
			   0x3F,  0xF8,		//5
			   0x22,  0x10,		//6
			   0x22,  0x10,		//7
			   0x3F,  0xF0,		//8

			   0x22,  0x10,		//9
			   0x22,  0x10,		//10
			   0x3F,  0xF0,		//11
			   0x22,  0x10,		//12
			   0x02,  0x04,		//13
			   0x02,  0x04,		//14
			   0x03,  0xFC,		//15
			   0x00,  0x00};		//16
DWORD dis[8];
unsigned int a,b,i;
DWORD j=0,k=0x01010101;
BOOL inout=1;

UINT w;
unsigned short int w2,q1,w1;
char chl[2];
//FILE *fp;
CFile file;
C32bitout::C32bitout(CWnd* pParent /*=NULL*/)
	: CDialog(C32bitout::IDD, pParent)
{
	//{{AFX_DATA_INIT(C32bitout)
	m_word = _T("");
	//}}AFX_DATA_INIT
	hDevice=NULL;
}


void C32bitout::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(C32bitout)
	DDX_Text(pDX, IDC_EDIT1, m_word);
	DDV_MaxChars(pDX, m_word, 2);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(C32bitout, CDialog)
	//{{AFX_MSG_MAP(C32bitout)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_EN_KILLFOCUS(IDC_EDIT1, OnEnterEdit1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// C32bitout message handlers

BOOL C32bitout::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
    if(hDevice==NULL)
	{
		hDevice=CreateFile(mDynVxDName,
			       GENERIC_READ,
				   FILE_SHARE_READ,
				   NULL,
				   OPEN_EXISTING,
				   0,
				   NULL);

	}
   if (hDevice == INVALID_HANDLE_VALUE)
	{
		AfxMessageBox("请检查板卡和驱动程序");
          CDialog::OnCancel();
     	return FALSE;
	}

   W_Data=(Write_DATA*)malloc(sizeof(Write_DATA));
   W_AD=(Write_AD*)malloc(sizeof(Write_AD));
   W_AD->Address=LAS1BRD;
   W_AD->Data=0x80;
   BYTE offset=LAS1BRD;
    DeviceIoControl(hDevice,
	               IOCTL_IO0R,
				   &offset,
				   sizeof(BYTE),
                   &mode,
				   0,
			       &nRet,
				    NULL);

   DeviceIoControl(hDevice,
	               IOCTL_IO0W,
				   W_AD,
				   sizeof(W_AD)+1,
                   NULL,
				   0,
			       &nRet,
				    NULL);
    W_Data->Address=0xfc;
   //W_Data->Address=0x089898989;
   W_Data->dData=0x089898989; 
   DeviceIoControl(hDevice,
	               IOCTL_IOWD,
				   W_Data,
				   sizeof(Write_DATA)+1,
                   NULL,
				   0,
			       &nRet,
				    NULL);

	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void C32bitout::OnButton1() 
{
	// TODO: Add your control notification handler code here
	  W_Data->Address=0xfc;
   //W_Data->Address=0x089898989;
   W_Data->dData=0x089898989; 
   DeviceIoControl(hDevice,
	               IOCTL_IOWD,
				   W_Data,
				   sizeof(Write_DATA)+1,
                   NULL,
				   0,
			       &nRet,
				    NULL);

	UpdateData(true);
	strcpy(chl,m_word);
	q1=chl[0]&0x0ff;
	w1=chl[1]&0x0ff;
	q1=q1-0xa0;
	w1=w1-0xa0;
	CString spath;
	GetModuleFileName(NULL,spath.GetBufferSetLength(100),100);
	spath.ReleaseBuffer();
	int npos;
	npos=spath.ReverseFind('\\');
	spath=spath.Left(npos);
	CString filename=spath+"\\hzk16";
 
	file.Open(filename,CFile::modeRead);
	w=((q1-1)*94+w1-1)*32;
	file.Seek(w,CFile::begin);
	file.Read(vect,32);
	file.Close();
	for (i=0;i<8;i++)
	{
	
   dis[i]=~(vect[i*2]*0x1000000+vect[i*2+1]*0x10000+vect[i*2+16]*256+vect[i*2+17]);
  //	dis[i]=(vect[i*2]*0x1000000+vect[i*2+1]*0x10000+vect[i*2+16]*256+vect[i*2+17]);
	}
    //8255的工作方式
   W_Data->Address=0xfc;
   W_Data->dData=0x089898989; 
   DeviceIoControl(hDevice,
	               IOCTL_IOWD,
				   W_Data,
				   sizeof(Write_DATA)+1,
                   NULL,
				   0,
			       &nRet,
				   NULL);	
   
	for (j=0;j<3000;j++)
	{
       
		k=0x01010101;
		for(i=0;i<8;i++)
		{
			W_Data->Address=0xf4;
           W_Data->dData=0x0ffffffff; 
     DeviceIoControl(hDevice,
	               IOCTL_IOWD,
				   W_Data,
				   sizeof(Write_DATA)+1,
                   NULL,
				   0,
			       &nRet,
				   NULL);
		//	_outpd(pci->IOBase[1]+0xf4,0x0ffffffff);
		//	_outpd(pci->IOBase[1]+0xf0,k);
		 W_Data->Address=0xf0;
          W_Data->dData=k; 
         DeviceIoControl(hDevice,
	               IOCTL_IOWD,
				   W_Data,
				   sizeof(Write_DATA)+1,
                   NULL,
				   0,
			       &nRet,
				   NULL);
		//	_outpd(pci->IOBase[1]+0xf4,dis[i]);
		 W_Data->Address=0xf4;
          W_Data->dData=dis[i]; 
         DeviceIoControl(hDevice,
	               IOCTL_IOWD,
				   W_Data,
				   sizeof(Write_DATA)+1,
                   NULL,
				   0,
			       &nRet,
				   NULL);
			k=k<<1;
		
		}

	
	}

	//退出前关闭点阵
//	_outpd(pci->IOBase[1]+0xf4,0x0ffffffff);//
	W_Data->Address=0xf4;
          W_Data->dData=0x0ffffffff; 
         DeviceIoControl(hDevice,
	               IOCTL_IOWD,
				   W_Data,
				   sizeof(Write_DATA)+1,
                   NULL,
				   0,
			       &nRet,
				   NULL);

	
}

void C32bitout::OnCancel() 
{
	// TODO: Add extra cleanup here

	
	CDialog::OnCancel();
}

void C32bitout::OnEnterEdit1() 
{
	// TODO: Add your control notification handler code here
	
	
	
}

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

BOOL C32bitout::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
		//_outp(pci->IOBase[0]+LAS1BRD,mode);	//恢复原模式

			W_Data->Address=0xf4;
           W_Data->dData=0x0ffffffff; 
     DeviceIoControl(hDevice,
	               IOCTL_IOWD,
				   W_Data,
				   sizeof(Write_DATA)+1,
                   NULL,
				   0,
			       &nRet,
				   NULL);
	W_AD->Address=LAS1BRD;
   W_AD->Data=mode;
	DeviceIoControl(hDevice,
	               IOCTL_IO0W,
				   W_AD,
				   sizeof(W_AD)+1,
                   NULL,
				   0,
			       &nRet,
				    NULL);
	return CDialog::DestroyWindow();
}

void C32bitout::OnOK() 
{
	// TODO: Add extra validation here
	  OnButton1();
      return ;
//	CDialog::OnOK();
}

⌨️ 快捷键说明

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