// 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
IMPLEMENT_DYNCREATE(control, CFormView)
control::control()
: CFormView(control::IDD)
{
//{{AFX_DATA_INIT(control)
// NOTE: the ClassWizard will add member initialization here
m_work_m =0;
m_work_s = 0;
m_work_up = 0;
//}}AFX_DATA_INIT
}
control::~control()
{
}
void control::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(control)
// NOTE: the ClassWizard will add DDX and DDV calls here
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, CFormView)
//{{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 diagnostics
#ifdef _DEBUG
void control::AssertValid() const
{
CFormView::AssertValid();
}
void control::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// 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::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 ;
}
}
void control::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
char devicename[]="Ezusb-0";
if(!bOpenDriver(&phand,devicename))
{
MessageBox("打开设备出错","信息提示",49);
return ;
}
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 ;
}
// TODO: Add your specialized code here and/or call the base class
}