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

📄 wen.cpp

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

#include "stdafx.h"
#include "pctest.h"
#include "wen.h"
#include "adc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define io_3 0x60
#define io_2 0x080
#define io_1 0x080
extern  PCHAR mDynVxDName ;

/////////////////////////////////////////////////////////////////////////////
// Cwen dialog


Cwen::Cwen(CWnd* pParent /*=NULL*/)
	: CDialog(Cwen::IDD, pParent)
{
	//{{AFX_DATA_INIT(Cwen)
		// NOTE: the ClassWizard will add member initialization here
	m_3 = 0;
	//}}AFX_DATA_INIT
data1=0;
hDevice1=hDevice=NULL;
}


void Cwen::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Cwen)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	DDX_Text(pDX, IDC_EDIT1, m_3);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Cwen, CDialog)
	//{{AFX_MSG_MAP(Cwen)
		// NOTE: the ClassWizard will add message map macros here
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Cwen message handlers
void Cwen::OnButton1() 
{
	// TODO: Add your control notification handler code here
	W_AD->Data=0X08;
    W_AD->Address=io_3;
    DeviceIoControl(
					hDevice, 
					IOCTL_IOW,
					W_AD, 
					sizeof(W_AD)+1, 
					NULL, 
					0,
					&nRet, 
 					NULL);	
}

void Cwen::OnButton3() 
{
	// TODO: Add your control notification handler code here
  yali();		

}

void Cwen::yali()
{
	W_AD->Data=0x00;
    W_AD->Address=io_1;
    DeviceIoControl(
					hDevice, 
					IOCTL_IOW,
					W_AD, 
					sizeof(W_AD)+1, 
					NULL, 
					0,
					&nRet, 
 					NULL);
    SetTimer(2,100,NULL);
}

BOOL Cwen::OnInitDialog() 
{
  	 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_AD=(Write_AD*)malloc(sizeof(Write_AD));
	 }
	return TRUE;
}

void Cwen::OnTimer(UINT nIDEvent) 
{
			switch(nIDEvent)
	{
case 2:
	BYTE data=0;
/*DeviceIoControl(
		            hDevice, 
					DIOC_IO_READ,
					pci, 
					0x080, 
					&data, 
					NULL, 
					NULL,
 					NULL);*/
//////////////////////////////////////////////////////
	BYTE OffSet=io_1;
	BOOL status = DeviceIoControl(
									hDevice, 
									IOCTL_IOR,
									&OffSet, 
									sizeof(BYTE), 
									&data, 
									0, 
									&nRet, 
 									NULL);
///////////////////////////////////////////////////////      
     m_3=data-0x10;//&0x0ff;
	 if(m_3>=0x69)
     /*	BOOL status=DeviceIoControl(
					hDevice, 
					DIOC_IO_WRITE,
					pci, 
					io_3,
					NULL,
					0x00,
					NULL,
 					NULL);*/
	 /////////////////////////////////////////////////
	{
	W_AD->Data=0x00;
    W_AD->Address=io_3;
    DeviceIoControl(
					hDevice, 
					IOCTL_IOW,
					W_AD, 
					sizeof(W_AD)+1, 
					NULL, 
					0,
					&nRet, 
 					NULL);
	 }
	 /////////////////////////////////////////////////
      UpdateData(FALSE);  
   // KillTimer(2);
   yali();
   break;
	}
	CDialog::OnTimer(nIDEvent);
}

void Cwen::OnButton2() 
{
/*		BOOL status=DeviceIoControl(
					hDevice, 
					DIOC_IO_WRITE,
					pci, 
					io_3,
					NULL,
					0x00,
					NULL,
 					NULL);*/
	W_AD->Data=0x00;
    W_AD->Address=io_3;
    DeviceIoControl(
					hDevice, 
					IOCTL_IOW,
					W_AD, 
					sizeof(W_AD)+1, 
					NULL, 
					0,
					&nRet, 
 					NULL);
}

⌨️ 快捷键说明

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