3 Replies Latest reply on Sep 8, 2011 12:49 AM by ananda_26

    CyUSB DeviceIOControl returns TRUE if device is unexpectedly disconnected

    user_119991230

      Hi,

         
         

      In my Win32 application I use direct calls to CyUSB driver via DeviceIOControl. The problem is that if I read from pipe (read is blocking, synchronous) and during it device is unexpectedly disconnected, DeviceIOControl returns true. Returning false in such case seems to be more logical I think. Also, when I used older version of FX2 driver EzUSB behaviour in same situation was correct - in case of disconnection DeviceIOControl returned me false.

         
         

      Is this a bug in driver implementation? If no, please advise how to determine such sudden device disconnections. Thank you.

         
         

      Technical details: I use Windows 7 32 bit and the latest driver version at the moment ( from     CySuiteUSB_3_4_6_B203.exe , driver version 3.4.6.0 ). Parts of my code for driver opening & read:

         
         

      //open

         
         

      DeviceHandle = ::CreateFile (functionClassDeviceData->DevicePath,

       
      GENERIC_WRITE | GENERIC_READ,

       
      FILE_SHARE_WRITE | FILE_SHARE_READ,

        NULL,

        OPEN_EXISTING,

        NULL,

        NULL);

         
         

      //...

         
         

      //read

         
         

      unsigned long BytesReturned=0;

      bool result=::DeviceIoControl (DeviceHandle, IOCTL_ADAPT_SEND_NON_EP0_DIRECT,

        &Request, sizeof(Request), buf, buflen,

        &BytesReturned, NULL);

         
         

      Best regards,

         
         

      Arturas

        • 1. Re: CyUSB DeviceIOControl returns TRUE if device is unexpectedly disconnected
          ananda_26

          Returning true would be the right behavior because if it returns false you'll lose the packets that were sent before the removal. If data was sent the host is expected not to lose them.

             

          Any I'll double check to see if there is any host controller spec on this.

             

          Please let me know the value of BytesReturned and the buffer. Is it reflecting the packets that were sent till the point of disconnect?

             

          Regards,

             

          Anand

          • 2. Re: CyUSB DeviceIOControl returns TRUE if device is unexpectedly disconnected
            user_119991230

            Yes, indeed, you are right. I have rechecked everything once again, driver works correctly - if I plug off USB cable during transfer in progress, it returns true + number of bytes actually read, and it is less than number of bytes requested. So I can see that device was suddenly disconnected.

               

            Problem I described in my first post appears only when I power off device by switching it off, not by unplugging USB cable. It seems to be hardware related - when power disappears part of hardware that provides data "dies" faster than FX2 chip, so FX2 transfer all data requested but data is invalid. That is why I have got TRUE from driver and BytesReturned==BytesRequested but data were invalid.

            • 3. Re: CyUSB DeviceIOControl returns TRUE if device is unexpectedly disconnected
              ananda_26

              The OS won't really know the difference between a powered-off device and a disconnected device. It will just realize that a device has been disconnected.

                 

              When you say you're getting invalid data, is the entire data invalid or just the last part. Did you hook up a CATC to correlate what is going on in the USB bus?

                 

              Regards,

                 

              Anand