Xferdata timeout and no response

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi guys, i'm doing a img processing project.

   

i need "read" data from USB device.

   

My colleage gave me a "precode" USB device that will generate 512bytes data about per 40 microsecond.

   

so i wrote some data to keep reading it.

   

here is the code, i hope it easy to read.

   

int main()
{

   

    CCyUSBDevice *USBDevice = new CCyUSBDevice(NULL);

   

    CCyBulkEndPoint *bulkIn = NULL;

   

    bulkIn = (CCyBulkEndPoint *)USBDevice->EndPoints[3];

   

    bulkIn->TimeOut=500;    //rewrite it for saving time

   

   

   

    LONG len =512;

   

    unsigned char data2[512]={0};

   

    int flag = 0;

   

    while(true)

   

    {

   

        while(!flag)

   

        {

   

        flag = bulkIn->XferData(data2,len);

   

if(!flag)

   

{

   

flag = bulkIn->XferData(data2,len);

   

std::cout<<"failed ";

   

}

   

else

   

{
    flag = false;
   }

   

}

   

}

   

return 0;

   

}

   

 

   

basically the code using a flag to determinate run xferdata() again or nor.

   

the problem i met is, when xferdata() return false to var flag.

   

system will call xferdata() agian. since then, my system will keep return false.

   

 

   

i have tried delete the CCyUSBDevice intances and create a new one to connect the same endpoint again.

   

code:

   

if(!flag)

   

{

   

          delete USBDevice;

   

USBDevice = NULL;

   

CCyUSBDevice *USBDevice = new CCyUSBDevice(NULL);

   

CCyBulkEndPoint *bulkIn = NULL;

   

bulkIn = (CCyBulkEndPoint *)USBDevice->EndPoints[3];

   

flag = bulkIn->XferData(data2,len);

   

std::cout<<"failed ";

   

}

   

seems like new intances still unable to read data from the same endpoint.

   

ps:lasterror is 997

   

 

   

anyone know how to deal with the "return false" situation?

   

Thanks!

0 Likes
1 Reply
Anonymous
Not applicable

by the way,

   

my colleague used some packet catching device catched the data between host and usb.

   

he said normally one transaction should be like this,

   

SOF IN DATA1/DATA0 ACK.

   

since xferdata() return false, host never send SOF again. so the USB didn't reply data to host.

0 Likes