1 Reply Latest reply on Jul 6, 2016 7:54 PM by 449267640_1704601

    Xferdata timeout and no response

    449267640_1704601

      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!