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

📄 mty.cpp

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

#include "stdafx.h"
#include "pctest.h"
#include "mty.h"
#include "adc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define IC_8259_A0   0x90
#define IC_8259_A1   0x91
#define IC_ADC0809   0x80
extern  PCHAR mDynVxDName ;
/////////////////////////////////////////////////////////////////////////////
// Cmty dialog


Cmty::Cmty(CWnd* pParent /*=NULL*/)
	: CDialog(Cmty::IDD, pParent)
{
	//{{AFX_DATA_INIT(Cmty)
	m_date = 0;
	//}}AFX_DATA_INIT
hDevice=NULL;
}


void Cmty::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Cmty)
	DDX_Text(pDX, IDC_EDIT1, m_date);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Cmty, CDialog)
	//{{AFX_MSG_MAP(Cmty)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Cmty message handlers
BOOL Cmty::OnInitDialog() 
{
	CDialog::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));
		W_AD->Data=0;
    W_AD->Address=0x4c;
    DeviceIoControl(
					hDevice, 
					IOCTL_OPEN_ISR,
					W_AD, 
					sizeof(W_AD)+1, 
					NULL, 
					0,
					&nRet, 
 					NULL);
	hEvent=CreateEvent(NULL, FALSE, FALSE, NULL);
    DeviceIoControl(
					hDevice, 
					IOCTL_TRS_EVENT,
					&hEvent, 
					sizeof(hEvent), 
					NULL, 
					0,
					&nRet, 
 					NULL);

	 }
    W_AD->Data=0x00;
    W_AD->Address=IC_ADC0809;
    DeviceIoControl(
					hDevice, 
					IOCTL_IOW,
					W_AD, 
					sizeof(W_AD)+1, 
					NULL, 
					0,
					&nRet, 
 					NULL);

	W_AD->Data=0x12;
    W_AD->Address=IC_8259_A0;
    DeviceIoControl(
					hDevice, 
					IOCTL_IOW,
					W_AD, 
					sizeof(W_AD)+1, 
					NULL, 
					0,
					&nRet, 
 					NULL);
	W_AD->Data=0x08;
    W_AD->Address=IC_8259_A1;
			DeviceIoControl(
					hDevice, 
					IOCTL_IOW,
					W_AD, 
					sizeof(W_AD)+1, 
					NULL, 
					0,
					&nRet, 
 					NULL);
 W_AD->Data=0x08;
    W_AD->Address=IC_8259_A1;
			DeviceIoControl(
					hDevice, 
					IOCTL_IOW,
					W_AD, 
					sizeof(W_AD)+1, 
					NULL, 
					0,
					&nRet, 
 					NULL);
	W_AD->Data=0x09;
    W_AD->Address=IC_8259_A1;
			DeviceIoControl(
					hDevice, 
					IOCTL_IOW,
					W_AD, 
					sizeof(W_AD)+1, 
					NULL, 
					0,
					&nRet, 
 					NULL);
			W_AD->Data=0xff;
            W_AD->Address=IC_8259_A1;
			DeviceIoControl(
					hDevice, 
					IOCTL_IOW,
					W_AD, 
					sizeof(W_AD)+1, 
					NULL, 
					0,
					&nRet, 
 					NULL);

	return TRUE;  // return TRUE  unless you set the focus to a controlet the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
void Cmty::OnButton1() 
{
	// TODO: Add your control notification handler code here
   W_AD=(Write_AD*)malloc(sizeof(Write_AD));
	W_AD->Data=0x12;
    W_AD->Address=IC_8259_A0;
    DeviceIoControl(
					hDevice, 
					IOCTL_IOW,
					W_AD, 
					sizeof(W_AD)+1, 
					NULL, 
					0,
					&nRet, 
 					NULL);
	W_AD->Data=0x08;
    W_AD->Address=IC_8259_A1;
			DeviceIoControl(
					hDevice, 
					IOCTL_IOW,
					W_AD, 
					sizeof(W_AD)+1, 
					NULL, 
					0,
					&nRet, 
 					NULL);
 W_AD->Data=0x08;
    W_AD->Address=IC_8259_A1;
			DeviceIoControl(
					hDevice, 
					IOCTL_IOW,
					W_AD, 
					sizeof(W_AD)+1, 
					NULL, 
					0,
					&nRet, 
 					NULL);
	W_AD->Data=0x09;
    W_AD->Address=IC_8259_A1;
			DeviceIoControl(
					hDevice, 
					IOCTL_IOW,
					W_AD, 
					sizeof(W_AD)+1, 
					NULL, 
					0,
					&nRet, 
 					NULL);
			W_AD->Data=0xff;
            W_AD->Address=IC_8259_A1;
			DeviceIoControl(
					hDevice, 
					IOCTL_IOW,
					W_AD, 
					sizeof(W_AD)+1, 
					NULL, 
					0,
					&nRet, 
 					NULL);
    W_AD->Data=0x00;
    W_AD->Address=IC_ADC0809;
    DeviceIoControl(
					hDevice, 
					IOCTL_IOW,
					W_AD, 
					sizeof(W_AD)+1, 
					NULL, 
					0,
					&nRet, 
 					NULL);
   SetTimer(1,50,NULL);
  // free(W_AD);	
}

void Cmty::OnOK() 
{
	// TODO: Add extra validation here
      W_AD->Address=0x4c;
	  W_AD->Data=0;
	 DeviceIoControl(hDevice,
			            IOCTL_CLOSE_ISR,
						W_AD,
						sizeof(W_AD)+1,
						NULL,
						0,
						&nRet,
						NULL);
		if(hDevice!=NULL)
	{
		CloseHandle( hDevice);
		hDevice=NULL;
	}
	KillTimer(1);
	CDialog::OnOK();
}

void Cmty::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(WAIT_OBJECT_0==WaitForSingleObject(hEvent,1000))
	{
		BYTE data;
		BYTE OffSet=0x80;
		BOOL status = DeviceIoControl(
									hDevice, 
									IOCTL_IOR,
									&OffSet, 
									sizeof(BYTE), 
									&data, 
									0, 
									&nRet, 
 									NULL);
		m_date=data;
		UpdateData(FALSE);
		KillTimer(1);
    W_AD->Data=0x00;
    W_AD->Address=IC_ADC0809;
    DeviceIoControl(
					hDevice, 
					IOCTL_IOW,
					W_AD, 
					sizeof(W_AD)+1, 
					NULL, 
					0,
					&nRet, 
 					NULL);
		OnButton1()  ;                                //重新启动0809的AD转换。
	}	
	CDialog::OnTimer(nIDEvent);
}


⌨️ 快捷键说明

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