FTDI Community

Please login or register.

Login with username, password and session length.
Advanced Search  


Welcome to the FTDI Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ FTDI Support

New Bridgetek Community is now open

Please note that we have created the Bridgetek Community to discuss all Bridgetek products e.g. EVE, MCU.

Please follow this link and create a new user account to get started.

Bridgetek Community

Author Topic: D2XX and FT4222 - how to detect USB cable unplugged? (I2C)  (Read 330 times)


  • Newbie
  • *
  • Posts: 15
    • View Profile
D2XX and FT4222 - how to detect USB cable unplugged? (I2C)
« on: April 30, 2020, 04:12:50 PM »

I have a C# wrapper for the LibFT4222 and D2XX DLLs. The PC is acting as an I2C slave, and we have another project where the PC is the master.

I am trying to add recovery code to detect if the I2C connection is lost due to a USB cable unplug. Currently, we have close/reopen manually.

I have a loop that checks for data using FT4222_I2CSlave_GetRxStatus() and does a read if the expected bytes are available, then I do a FT4222_I2CSlave_Read().

I have noticed that the status returned from FT4222_I2CSlave_GetRxStatus continues to be FT4222_OK even if I unplug the USB cable.

I am trying to find a clue in these two manuals for how to detect a lost connection:


My app also talks to a GPIB interface to a signal generator and have detection code for that working as expected. It returns an error when the device is turned off or unplugged.

Thanks for any pointers to what I need to be looking for in the manual.
« Last Edit: April 30, 2020, 04:16:23 PM by allenhuffman »

FTDI Community

  • Administrator
  • Sr. Member
  • *****
  • Posts: 443
    • View Profile
Re: D2XX and FT4222 - how to detect USB cable unplugged? (I2C)
« Reply #1 on: May 01, 2020, 05:18:50 PM »


Curiously neither FT4222_I2CSlave_GetRxStatus() or FT4222_I2CSlave_Read() are denoted as allowing for return codes which would indicate a USB disconnected.

In this case I would suggest calling  the D2XX function FT_GetStatus(), this will also return the number of bytes in the RX queue, but it should throw an FT_DEVICE_NOT_FOUND or FT_IO_ERROR on a USB disconnect.

Best Regards,
FTDI community