Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > USB Controllers > CyUSB DeviceIOControl returns TRUE if device is unexpectedly disconnected

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



CyUSB DeviceIOControl returns TRUE if device is unexpectedly disconnected
Moderator:
RSKV

Post Reply
Follow this topic



CyUSB DeviceIOControl returns TRUE if device is unexpectedly disconnected

arturasi posted on 06 Sep 2011 2:25 AM PST
Member
6 Forum Posts

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




Re: CyUSB DeviceIOControl returns TRUE if device is unexpectedly disconnected

aasi posted on 06 Sep 2011 10:46 AM PST
Cypress Employee
1090 Forum Posts

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



Re: CyUSB DeviceIOControl returns TRUE if device is unexpectedly disconnected

arturasi posted on 07 Sep 2011 12:28 AM PST
Member
6 Forum Posts

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.



Re: CyUSB DeviceIOControl returns TRUE if device is unexpectedly disconnected

aasi posted on 08 Sep 2011 10:49 PM PST
Cypress Employee
1090 Forum Posts

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






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: KXP; Secondary Owner: VWA; Sunset Date: 01/01/20