看看有没有高手指点 ezusb->cyusb

yingbinchina 2010-01-19 06:12:22
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),
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;
}

可就是卡死在这里,请指教。
...全文
225 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yingbinchina 2010-01-26
  • 打赏
  • 举报
回复

这从usb设备中读不到数据,老返回false,是为什么呢?
yingbinchina 2010-01-22
  • 打赏
  • 举报
回复

仍在研究中。。。
kyzf 2010-01-19
  • 打赏
  • 举报
回复
帮顶下。

21,595

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 驱动开发/核心开发
社区管理员
  • 驱动开发/核心开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧