1 Reply Latest reply on Mar 8, 2018 9:18 PM by srnt

    Qt crash on USB unplug


      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


      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?

        • 1. Re: Qt crash on USB unplug

          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