Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Enumerating COM port

Enumerating COM port

Scheduled Pinned Locked Moved C / C++ / MFC
helpsharepointdatabasecom
1 Posts 1 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bhanu_8509
    wrote on last edited by
    #1

    Dear All, I am having a USB serial device and I want to create handle to the device whenever the device is connected. I want to open the handle using VID and PID of the USB serial device. I tried using SetupDi calls but not detecting the ports. The below is my code snippet. Please help me to solve this issue.

    //GUID is DEFINE_GUID(GUID_DEVINTERFACE_COMPORT, 0x4d36e978, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18);
    bool status = false;
    bool bRet = false;
    HDEVINFO devInfoSet = INVALID_HANDLE_VALUE;
    SP_DEVICE_INTERFACE_DATA pDeviceData;
    SP_DEVINFO_DATA devInfoData;
    devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
    DWORD index = 0;
    ULONG i=0;
    ULONG requiredLength=0;
    pDeviceData.cbSize = sizeof(SP_INTERFACE_DEVICE_DATA);
    devInfoSet =SetupDiGetClassDevs(&GUID_DEVINTERFACE_COMPORT,NULL,NULL,(DIGCF_PRESENT | DIGCF_DEVICEINTERFACE) );
    if(devInfoSet!=INVALID_HANDLE_VALUE)
    {
    while(TRUE)
    {
    bRet = SetupDiEnumDeviceInterfaces(devInfoSet, /* HDEVINFO DeviceInfoSet */NULL, /* PSP_DEVINFO_DATA DeviceInfoData */
    &GUID_DEVINTERFACE_COMPORT, /* CONST GUID * InterfaceClassGuid */index,
    &pDeviceData /* PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData */);
    int x = GetLastError();
    if(bRet)
    index++;
    else
    break;// finally the index is zero only
    }

    }
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups