首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 嵌入开发 > 驱动开发 >

看看有没有 ezusb->cyusb

2012-04-21 
看看有没有高手指点 ezusb-cyusbbool ReadData(int count,unsigned char *buf){boolSuccess BULK_TRANSF

看看有没有高手指点 ezusb->cyusb
bool ReadData(int count,unsigned char *buf)
{

  bool Success ;
  BULK_TRANSFER_CONTROL BR;
  VENDOR_OR_CLASS_REQUEST_CONTROL VR;
  unsigned long nBytes;
intbc,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),


  inbuf,
  bc,
  &nBytes,
  NULL);
  */
  UCHAR *inContext = USBDevice->BulkInEndPt->BeginDataXfer(inbuf,bc,&inOvLap);
  //UCHAR *outContext = USBDevice->BulkOutEndPt->BeginDataXfer(outbuf,bc,&outOvLap);

  //USBDevice->BulkOutEndPt->WaitForXfer(&outOvLap,100);
  USBDevice->BulkInEndPt->WaitForXfer(&inOvLap,100);

  //Success = USBDevice->BulkOutEndPt->FinishDataXfer(outbuf,bc,&outOvLap,outContext);
  Success = USBDevice->BulkInEndPt->FinishDataXfer(inbuf,bc,&inOvLap,inContext);

  //if(bc>nBytes)bc=nBytes;
  bout-=bc;
  inbuf+=bc;
}
  //CloseHandle(outOvLap.hEvent);
  CloseHandle(inOvLap.hEvent);
}
  return Success;
}

可就是卡死在这里,请指教。


[解决办法]
帮顶下。

热点排行