📄 usb.~cpp
字号:
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
#pragma hdrstop
#include "windows.h"
#include "ezusbsys.h"
#include "usb.h"
#define VR_SEND_COMMAND 0xa2 // Send Command
#define VR_RESET_FIFO 0xa3 // Get Image
//---------------------------------------------------------------------------
bool TUSB::OpenDevice()
{
hDevice = CreateFile("\\\\.\\Ezusb-0",
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
0);
if (hDevice == INVALID_HANDLE_VALUE)
return false;
else
return true;
}
//---------------------------------------------
bool TUSB::CloseDevice()
{
if (hDevice != INVALID_HANDLE_VALUE)
{
CloseHandle(hDevice);
return true;
}
else
return false;
}
//---------------------------------------------
bool TUSB::SendCommand(unsigned char command)
{
bool Success ;
VENDOR_OR_CLASS_REQUEST_CONTROL VR;
unsigned long nBytes;
if (hDevice != INVALID_HANDLE_VALUE )
{
VR.direction = 0;
VR.requestType = 2;
VR.recepient = 0;
VR.request = VR_SEND_COMMAND;
VR.requestTypeReservedBits = 0;
VR.value = command;
Success = DeviceIoControl (hDevice,
IOCTL_EZUSB_VENDOR_OR_CLASS_REQUEST,
&VR,
sizeof(VENDOR_OR_CLASS_REQUEST_CONTROL),
NULL,
0,
&nBytes,
NULL);
}
return Success;
}
bool TUSB::ResetFifo()
{
bool Success ;
VENDOR_OR_CLASS_REQUEST_CONTROL VR;
unsigned long nBytes;
if (hDevice != INVALID_HANDLE_VALUE )
{
VR.direction = 0;
VR.requestType = 2;
VR.recepient = 0;
VR.request = VR_RESET_FIFO;
VR.requestTypeReservedBits = 0;
Success = DeviceIoControl (hDevice,
IOCTL_EZUSB_VENDOR_OR_CLASS_REQUEST,
&VR,
sizeof(VENDOR_OR_CLASS_REQUEST_CONTROL),
NULL,
0,
&nBytes,
NULL);
}
return Success;
}
bool TUSB::GetImage(unsigned char *buf)
{
bool Success ;
VENDOR_OR_CLASS_REQUEST_CONTROL VR;
BULK_TRANSFER_CONTROL BR;
unsigned long nBytes;
BR.pipeNum = 2;
Success = DeviceIoControl (hDevice,
IOCTL_EZUSB_BULK_READ,
&BR,
sizeof(BULK_TRANSFER_CONTROL),
&buf[0],
32768,
&nBytes,
NULL);
Success = DeviceIoControl (hDevice,
IOCTL_EZUSB_BULK_READ,
&BR,
sizeof(BULK_TRANSFER_CONTROL),
&buf[32768],
32768,
&nBytes,
NULL);
return Success;
}
bool TUSB::GetCardResponse(unsigned char *buf)
{
bool Success ;
VENDOR_OR_CLASS_REQUEST_CONTROL VR;
BULK_TRANSFER_CONTROL BR;
unsigned long nBytes;
BR.pipeNum = 3; //Ep8
Success = DeviceIoControl (hDevice,
IOCTL_EZUSB_BULK_READ,
&BR,
sizeof(BULK_TRANSFER_CONTROL),
&buf[0],
512,
&nBytes,
NULL);
return Success;
}
bool TUSB::SendCardCommand(unsigned char *buf)
{
bool Success ;
VENDOR_OR_CLASS_REQUEST_CONTROL VR;
BULK_TRANSFER_CONTROL BR;
unsigned long nBytes;
BR.pipeNum = 1; //Ep4
Success = DeviceIoControl (hDevice,
IOCTL_EZUSB_BULK_WRITE,
&BR,
sizeof(BULK_TRANSFER_CONTROL),
&buf[0],
512,
&nBytes,
NULL);
return Success;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -