bool ReadData(int count,unsigned char *buf)
{
bool Success ;
BULK_TRANSFER_CONTROL BR;
VENDOR_OR_CLASS_REQUEST_CONTROL VR;
unsigned long nBytes;
int bc,bout;
unsigned char* inbuf=buf;
if (hUsbDevice != INVALID_HANDLE_VALUE )
{
VR.direction = 0; // (0=host to device, 1=device to host)
VR.requestType = 2;
VR.recepient = 0;
VR.request = VX_GPIFREAD;
VR.requestTypeReservedBits = 0;
VR.value = *((unsigned short*)(&count));
VR.index = *(((unsigned short*)(&count))+1); //SETUPDAT[5:4]
Success = DeviceIoControl (hUsbDevice,
IOCTL_EZUSB_VENDOR_OR_CLASS_REQUEST,
&VR,
sizeof(VENDOR_OR_CLASS_REQUEST_CONTROL),
NULL,
0,
&nBytes,
NULL);
BR.pipeNum = 1;
bout=count*2;
while (bout){
if(bout>0x8000)bc=0x8000;
else bc=bout;
Success = DeviceIoControl (hUsbDevice,
IOCTL_EZUSB_BULK_READ,
&BR,
sizeof(BULK_TRANSFER_CONTROL),
inbuf,
bc,
&nBytes,
NULL);
if(bc>nBytes)bc=nBytes;
bout-=bc;
inbuf+=bc;
}
}
return Success;
}
上边是以前的程序,由于要用cyusb,我把它改成了下边的样子:
bool ReadData(int count,unsigned char *buf)
{
bool Success ;
//BULK_TRANSFER_CONTROL BR;
//VENDOR_OR_CLASS_REQUEST_CONTROL VR;
long bc;
int bout;
unsigned char* inbuf=buf;
// PUCHAR outbuf = new UCHAR[count];
// ZeroMemory(outbuf,count);
//PUCHAR inbuf = new UCHAR[count];
//ZeroMemory(inbuf,count);
//inbuf = buf;
OVERLAPPED inOvLap;//,outOvLap;
//outOvLap.hEvent = CreateEvent(NULL,false,false,"CYUSB_OUT");
inOvLap.hEvent = CreateEvent(NULL,false,false,"CYUSB_IN");
if (hUsbDevice != INVALID_HANDLE_VALUE )
{
// VR.direction = 0; // (0=host to device, 1=device to host)
// VR.requestType = 2;
// VR.recepient = 0;
// VR.request = VX_GPIFREAD;
// VR.requestTypeReservedBits = 0;
// VR.value = *((unsigned short*)(&count));
/*
Success = DeviceIoControl (hUsbDevice,
IOCTL_EZUSB_VENDOR_OR_CLASS_REQUEST,
&VR,
sizeof(VENDOR_OR_CLASS_REQUEST_CONTROL),
NULL,
0,
&nBytes,
NULL);
*/
// BR.pipeNum = 1;
ept->Direction = DIR_TO_DEVICE;
ept->ReqType = REQ_VENDOR;
ept->Target = TGT_DEVICE;
ept->ReqCode = VX_GPIFREAD;
ept->Value = *((unsigned short*)(&count));
ept->Index = *(((unsigned short*)(&count))+1); //SETUPDAT[5:4]
//PUCHAR readbuf = new char[2];
//Success = ept->Read(readbuf,2);
Success = ept->Write(NULL,0);
ept->Address = 0x01;
bout=count*2;
while (bout)
{
if(bout>0x8000) bc=0x8000;
else bc=bout;
/*
Success = DeviceIoControl (hUsbDevice,
IOCTL_EZUSB_BULK_READ,
&BR,
sizeof(BULK_TRANSFER_CONTROL),