none
How do I open a USB Device (FTDI Device) with CreateFile in a C program? RRS feed

  • Question

  • Hi,

         Using Device Manager, on the Serial port COM3, under properties and under "Device Instance path", I got the value: "FTDIBUS\VID_0403+PID_6001+AL05HPWVA\0000". I tried plugging this into CreateFile and I keep getting Invalid File Name or File Not Found, etc. I'm not sure what I'm missing or doing wrong. 

    char CommPortName[] = "FTDIBUS\VID_0403+PID_6001+AL05HPWVA\0000";
    DCB dcbSerialParams = {0};
    COMMTIMEOUTS timeouts = {0};
    DWORD dLastError;

    hSerial = CreateFile(CommPortName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

            if (hSerial == INVALID_HANDLE_VALUE ){
    dLastError = GetLastError();

                    etc........

    Thank You,

    Paul Jacques

    Tuesday, August 20, 2019 5:34 PM

Answers

  • Hi Paul,

    The name to use with CreateFile is  R"(\\.\COM3)". Or just "COM3" for COM numbers small enough.

    Nothing in the documentation says that instance names can be used to open the device. 

    You can also use the obscure SetupDi functions to retrieve the Windows info about the device and finally call SetupDiGetDeviceInterfaceDetail - that will provide the name for CreateFile. TL;DR.

    But you already know the "legacy" alias which is simply COM3.

    -- pa

    Tuesday, August 20, 2019 6:38 PM

All replies

  • Hi,

         Using Device Manager, on the Serial port COM3, under properties and under "Device Instance path", I got the value: "FTDIBUS\VID_0403+PID_6001+AL05HPWVA\0000". I tried plugging this into CreateFile and I keep getting Invalid File Name or File Not Found, etc. I'm not sure what I'm missing or doing wrong. 

    char CommPortName[] = "FTDIBUS\VID_0403+PID_6001+AL05HPWVA\0000";
    DCB dcbSerialParams = {0};
    COMMTIMEOUTS timeouts = {0};
    DWORD dLastError;

    hSerial = CreateFile(CommPortName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

            if (hSerial == INVALID_HANDLE_VALUE ){
    dLastError = GetLastError();

                    etc........

    Thank You,

    Paul Jacques

    Try with -

    char CommPortName[] = "FTDIBUS\\VID_0403+PID_6001+AL05HPWVA\\0000";


    Tuesday, August 20, 2019 5:47 PM
  • Hi Paul,

    The name to use with CreateFile is  R"(\\.\COM3)". Or just "COM3" for COM numbers small enough.

    Nothing in the documentation says that instance names can be used to open the device. 

    You can also use the obscure SetupDi functions to retrieve the Windows info about the device and finally call SetupDiGetDeviceInterfaceDetail - that will provide the name for CreateFile. TL;DR.

    But you already know the "legacy" alias which is simply COM3.

    -- pa

    Tuesday, August 20, 2019 6:38 PM