Qt crash on USB unplug

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

cross mob
Anonymous
Not applicable

I'm using Cypress FX2LP chip(CY7C68013A) on my board to communicate trough USB with Qt using CyAPI library. I Should read 1 KByte data every 100 ms(infinitive) and it should be possible to user to send special commands through buttons during data receiving. So i create another thread other than MainWindow and run it every 100 ms using a timer. My code is something like: Project.pro:

LIBS += -L$$PWD/CyAPI_lib_cpp -lCyAPI

my_thread.cpp:

CCyUSBDevice USBDevice; unsigned char xferBuffer_in[1024];  void my_thread::Receive_new_set_of_Data(){//Runs very 100 ms USBDevice.Open(0); bool is_ok=false; if(USBDevice.IsOpen()){ LONG length=1024; USBDevice.BulkInEndPt->TimeOut=30;// wait 30 ms at max  is_ok=USBDevice.BulkInEndPt->XferData((PUCHAR)xferBuffer_in, length , (CCyIsoPktInfo*)0,false); } }

My problem is that when user removes USB between data receiving, it crashes and debugger stop at set time out line. How can i detect USB unplug? Is there any event for USB unplug?

0 Likes
1 Solution
SrinathS_16
Moderator
Moderator
Moderator
1000 replies posted 750 replies posted 500 replies posted

Hello Javad Habibi,

The CyUSB namespace has an event handler for attachment and detachment of USB device. The USBDeviceList.DeviceRemoved is an event handler for USB removal.

Please refer to the source code of Cypress USB Control Center, which can be found in the below path after the installation of CY3684 EZ-USB FX2LP Development Kit (Rev. *B)  .

C:\Cypress\USB\CY3684\CY3684_EZ-USB_FX2LP_DVK\1.1\Windows Applications\Application Source files\c_sharp\controlcenter

This has got the implementation of event handling during the attachment and detachment of USB device.

Best regards,

Srinath S

View solution in original post

0 Likes
1 Reply
SrinathS_16
Moderator
Moderator
Moderator
1000 replies posted 750 replies posted 500 replies posted

Hello Javad Habibi,

The CyUSB namespace has an event handler for attachment and detachment of USB device. The USBDeviceList.DeviceRemoved is an event handler for USB removal.

Please refer to the source code of Cypress USB Control Center, which can be found in the below path after the installation of CY3684 EZ-USB FX2LP Development Kit (Rev. *B)  .

C:\Cypress\USB\CY3684\CY3684_EZ-USB_FX2LP_DVK\1.1\Windows Applications\Application Source files\c_sharp\controlcenter

This has got the implementation of event handling during the attachment and detachment of USB device.

Best regards,

Srinath S

0 Likes