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

📄 control1.cpp

📁 USB低层驱动程序设计
💻 CPP
字号:
// control.cpp : implementation file
//

#include "stdafx.h"
#include "display.h"
#include "control.h"
#include "ezusbsys.h"
#include "winioctl.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// control dialog


control::control(CWnd* pParent /*=NULL*/)
	: CDialog(control::IDD, pParent)
{
	//{{AFX_DATA_INIT(control)
	m_work_m =0;
	m_work_s = 0;
	m_work_up = 0;
	//}}AFX_DATA_INIT
}


void control::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(control)
	DDX_Control(pDX, IDOK, m_down);
	DDX_Control(pDX, IDC_UPDOWN, m_up);
	DDX_Radio(pDX, IDC_M1_R1, m_work_m);
	DDX_Radio(pDX, IDC_SPEED_L, m_work_s);
	DDX_Radio(pDX, IDC_UP_R, m_work_up);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(control, CDialog)
	//{{AFX_MSG_MAP(control)
	ON_BN_CLICKED(IDC_DOWN_R, OnDownR)
	ON_BN_CLICKED(IDC_UPDOWN, OnUpdown)
	ON_BN_CLICKED(IDC_UP_R, OnUpR)
	ON_BN_CLICKED(IDC_M1_R1, OnM1R1)
	ON_BN_CLICKED(IDC_M2_R2, OnM2R2)
	ON_BN_CLICKED(IDC_M3_R3, OnM3R3)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// control message handlers









void control::OnOK() 
{
	// TODO: Add extra validation here
//启动	

	BULK_TRANSFER_CONTROL  bulk;
	WORD	inPacketSize=4;
	//		   int		i;
	int     sucess;
	unsigned char  write_buf[64];
	ULONG   nBytes=0;
	bulk.pipeNum=0;	 
	write_buf[0]=0X5A;
	sucess=DeviceIoControl
		(phand,IOCTL_EZUSB_BULK_WRITE,
		&bulk,
		sizeof(BULK_TRANSFER_CONTROL),
		write_buf,
		inPacketSize,
		&nBytes,
		NULL);
	if(!sucess)
	{
		MessageBox("写数据错误!","信息提示",MB_OK);	
		return ;
	}
//	CDialog::OnOK();
}











void control::OnDownR() 
{
	// TODO: Add your control notification handler code here
	//反转
		   BULK_TRANSFER_CONTROL  bulk;
		   WORD	inPacketSize=64;
//		   int		i;
		   int     sucess;
		   unsigned char  write_buf[64];
		   ULONG   nBytes=0;
		   bulk.pipeNum=0;	 
		   write_buf[0]=0x5B;


		   sucess=DeviceIoControl
			   (phand,IOCTL_EZUSB_BULK_WRITE,
			   &bulk,
			   sizeof(BULK_TRANSFER_CONTROL),
			   write_buf,
			   inPacketSize,
			   &nBytes,
			   NULL);
		   if(!sucess)
		   {
				   MessageBox("写数据错误!","信息提示",MB_OK);
				   return ;
		   }

}

void control::OnUpdown() 
{
	// TODO: Add your control notification handler code here
//停止

		   BULK_TRANSFER_CONTROL  bulk;
		   WORD	inPacketSize=64;
//		   int		i;
		   int     sucess;
		   unsigned char  write_buf[64];
		   ULONG   nBytes=0;
		   bulk.pipeNum=0;	 
		   write_buf[0]=0x59;


		   sucess=DeviceIoControl
			   (phand,IOCTL_EZUSB_BULK_WRITE,
			   &bulk,
			   sizeof(BULK_TRANSFER_CONTROL),
			   write_buf,
			   inPacketSize,
			   &nBytes,
			   NULL);
		   if(!sucess)
		   {
				   MessageBox("写数据错误!","信息提示",MB_OK);
				   return ;
		   }
}


void control::OnUpR() 
{
	// TODO: Add your control notification handler code here
	//正转
		   BULK_TRANSFER_CONTROL  bulk;
		   WORD	inPacketSize=64;
//		   int		i;
		   int     sucess;
		   unsigned char  write_buf[64];
		   ULONG   nBytes=0;
		   bulk.pipeNum=0;	 
		   write_buf[0]=0x5B;


		   sucess=DeviceIoControl
			   (phand,IOCTL_EZUSB_BULK_WRITE,
			   &bulk,
			   sizeof(BULK_TRANSFER_CONTROL),
			   write_buf,
			   inPacketSize,
			   &nBytes,
			   NULL);
		   if(!sucess)
		   {
				   MessageBox("写数据错误!","信息提示",MB_OK);
				   return ;
		   }

}

BOOL control::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

	char  devicename[]="Ezusb-0";
	if(!bOpenDriver(&phand,devicename))
	{	
		MessageBox("打开设备出错","信息提示",49);	
		return  false ;
	}
		   BULK_TRANSFER_CONTROL  bulk;
		   WORD	inPacketSize=64;
//		   int		i;
		   int     sucess;
		   unsigned char  write_buf[64];
		   ULONG   nBytes=0;
		   bulk.pipeNum=0;	 
		   write_buf[0]=0x5C;


		   sucess=DeviceIoControl
			   (phand,IOCTL_EZUSB_BULK_WRITE,
			   &bulk,
			   sizeof(BULK_TRANSFER_CONTROL),
			   write_buf,
			   inPacketSize,
			   &nBytes,
			   NULL);
		   if(!sucess)
		   {
				   MessageBox("写数据错误!","信息提示",MB_OK);
				   return false;
		   }




	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
bool control::bOpenDriver (HANDLE * phDeviceHandle, PCHAR devname)
{
   char completeDeviceName[64] = "";
   char pcMsg[64] = "";
   
   strcat (completeDeviceName,
      "\\\\.\\"
      );
   
   strcat (completeDeviceName,
		    devname
          );
   
   *phDeviceHandle = CreateFile(   completeDeviceName,
      GENERIC_WRITE,
      FILE_SHARE_WRITE,
      NULL,
      OPEN_EXISTING,
      0,
      NULL);
   
   if (*phDeviceHandle == INVALID_HANDLE_VALUE) {
      return (FALSE);
   } else {
      return (TRUE);
   } /*else*/
}

void control::OnM1R1() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	BULK_TRANSFER_CONTROL  bulk;
	WORD	inPacketSize=4;
	//		   int		i;
	int     sucess;
	unsigned char  write_buf[64];
	ULONG   nBytes=0;
	bulk.pipeNum=0;	 
	write_buf[0]=0X5C;
	sucess=DeviceIoControl
		(phand,IOCTL_EZUSB_BULK_WRITE,
		&bulk,
		sizeof(BULK_TRANSFER_CONTROL),
		write_buf,
		inPacketSize,
		&nBytes,
		NULL);
	if(!sucess)
	{
		MessageBox("写数据错误!","信息提示",MB_OK);	
		return ;
	}

	
}

void control::OnM2R2() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	BULK_TRANSFER_CONTROL  bulk;
	WORD	inPacketSize=4;
	//		   int		i;
	int     sucess;
	unsigned char  write_buf[64];
	ULONG   nBytes=0;
	bulk.pipeNum=0;	 
	write_buf[0]=0X5D;
	sucess=DeviceIoControl
		(phand,IOCTL_EZUSB_BULK_WRITE,
		&bulk,
		sizeof(BULK_TRANSFER_CONTROL),
		write_buf,
		inPacketSize,
		&nBytes,
		NULL);
	if(!sucess)
	{
		MessageBox("写数据错误!","信息提示",MB_OK);	
		return ;
	}
	
}

void control::OnM3R3() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	BULK_TRANSFER_CONTROL  bulk;
	WORD	inPacketSize=4;
	//		   int		i;
	int     sucess;
	unsigned char  write_buf[64];
	ULONG   nBytes=0;
	bulk.pipeNum=0;	 
	write_buf[0]=0X5E;
	sucess=DeviceIoControl
		(phand,IOCTL_EZUSB_BULK_WRITE,
		&bulk,
		sizeof(BULK_TRANSFER_CONTROL),
		write_buf,
		inPacketSize,
		&nBytes,
		NULL);
	if(!sucess)
	{
		MessageBox("写数据错误!","信息提示",MB_OK);	
		return ;
	}
	
}

void control::OnButton1() 
{
	// TODO: Add your control notification handler code here
	BULK_TRANSFER_CONTROL  bulk;
	WORD	inPacketSize=4;
	//		   int		i;
	int     sucess;
	unsigned char  write_buf[64];
	ULONG   nBytes=0;
	bulk.pipeNum=0;	 
	write_buf[0]=0X55;
	sucess=DeviceIoControl
		(phand,IOCTL_EZUSB_BULK_WRITE,
		&bulk,
		sizeof(BULK_TRANSFER_CONTROL),
		write_buf,
		inPacketSize,
		&nBytes,
		NULL);
	if(!sucess)
	{
		MessageBox("写数据错误!","信息提示",MB_OK);	
		return ;
	}
	
	
}

void control::OnButton2() 
{
	// TODO: Add your control notification handler code here
	BULK_TRANSFER_CONTROL  bulk;
	WORD	inPacketSize=4;
	//		   int		i;
	int     sucess;
	unsigned char  write_buf[64];
	ULONG   nBytes=0;
	bulk.pipeNum=0;	 
	write_buf[0]=0X56;
	sucess=DeviceIoControl
		(phand,IOCTL_EZUSB_BULK_WRITE,
		&bulk,
		sizeof(BULK_TRANSFER_CONTROL),
		write_buf,
		inPacketSize,
		&nBytes,
		NULL);
	if(!sucess)
	{
		MessageBox("写数据错误!","信息提示",MB_OK);	
		return ;
	}
	
	
}

⌨️ 快捷键说明

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