2

I am using FTDI D2XX Programmer's Guide to interact with FTDI serial-to-usb converter. The following code is used to open the USB port.

      bool CUsbPort::OpenIOHandle()
      {
        m_hComm = FT_W32_CreateFile(m_SerialNumberBuf,
        GENERIC_READ | GENERIC_WRITE,
        0,
        0,
        OPEN_EXISTING, 
        FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED |         FT_OPEN_BY_SERIAL_NUMBER,
        0);
        return m_hComm == INVALID_HANDLE_VALUE ? false : true ;
     }

We have a service application to open the port every 5 or 10 minutes to read from and write to our devices. This is a multi-threaded application. I may have more than two devices connected to this application at the same time. When the application runs overnight, I observed there are several cases where FT_W32_CreateFile function failed for all of the threads. Then, they worked again. There may be 2 or 3 times in a overnight run. I want to know what conditions may cause the function failing. Thanks in advance.

user3097695
  • 1,152
  • 2
  • 16
  • 42
  • Have you tried opening the com port directly, using the [CreateFile API](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx), instead of going through their API? I'm guessing that they're automatically opening the COM port that maps to their adapter, but that could just be a configuration setting... – Lynn Crumbling Feb 02 '17 at 16:02
  • "m_SerialNumberBuf" is the serial number for FTDI USB serial converter. There are two drivers for the FTDI USB serial converter. In one project, we use the virtual port. In this project, we use USB driver, and have to stick to it. It works pretty good so far. There is a very low failure rate. I need to find the reasons why it fails sometimes. I am thinking there may be a timing issue. – user3097695 Feb 02 '17 at 16:27

1 Answers1

0

It's possible that Windows is suspending the hardware.
Try turning off USB suspend:

Control Panel ->
    Power Options ->
        Change plan settings ->
           Change advanced power settings

 Under that:
     USB Settings ->
         USB selective suspend setting ->
             Set to Disabled

enter image description here

Lynn Crumbling
  • 12,985
  • 8
  • 57
  • 95
  • I have disabled the setting already, but I still have the problem. However, If I retry the function call, it will succeed. Right now, I have a retry loop to have a good handle. – user3097695 Feb 07 '17 at 19:41