Results 1 to 4 of 4

Thread: FInd Actice COM Port

  1. #1
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default FInd Actice COM Port

    QString com_port;
    HANDLE hComPort;

    for (int i=1;i<=16;i++)
    {
    com_port.clear();
    com_port.sprintf("COM%d",i);
    //hComPort= CreateFile(com_port.utf16(), GENERIC_READ |GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
    hComPort= CreateFile(com_port.utf16(), GENERIC_READ |GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
    if (hComPort == INVALID_HANDLE_VALUE)
    {
    hComPort= 0;
    }
    else
    {
    m_ledBoardCOMPort->addItem(com_port);
    m_irBoardCOMPort->addItem(com_port);
    }

    CloseHandle(hComPort);
    }

    I have writtern the code to find the acive COM port, But if the COM Port name is COM11, COM12 then it is unable to find. Only upto COM9 it is able to find.
    Please help me that how to get evn if the COM Port is COM10 or COM11 also.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: FInd Actice COM Port

    Nothing to do with Qt I expect. I assume this is Windows API code.

    Are you sure they actually exist? Does Windows show them in the command prompt "mode" command output? There's no standard naming for serial ports, so your extra ports might be COM48 and COM56. Also, inserting and removing USB-serial adapters can leave phantom COM ports that Windows thinks are still in use.

  3. #3
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Post Re: FInd Actice COM Port

    Quote Originally Posted by ChrisW67 View Post
    Nothing to do with Qt I expect. I assume this is Windows API code.

    Are you sure they actually exist? Does Windows show them in the command prompt "mode" command output? There's no standard naming for serial ports, so your extra ports might be COM48 and COM56. Also, inserting and removing USB-serial adapters can leave phantom COM ports that Windows thinks are still in use.
    Any two digigit COM port is there it is not coming.It is showing in the command prompt, i checked with hyper terminal also. It is showing as expected. Only this code fail to get COM port containaing two digit code. Else let me know any other way to find the number of COM port available.

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: FInd Actice COM Port

    The filename syntax is incorrect, you are using the old legacy format which only supports COM1 - COM9. The preferred format is:

    Qt Code:
    1. com_port.sprintf("\\\\.\\COM%d",i);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Port Qt to ARC Processor
    By jim_king_2000 in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 19th January 2010, 21:22
  2. Port connection
    By bindushree in forum Qt Programming
    Replies: 1
    Last Post: 14th July 2009, 05:24
  3. Qt and COM port access
    By bnilsson in forum Qt Programming
    Replies: 8
    Last Post: 7th June 2009, 15:58
  4. Com Port
    By bismitapadhy in forum Qt Programming
    Replies: 4
    Last Post: 6th June 2009, 12:17
  5. trayicon port to QT4
    By ykohn in forum Qt Programming
    Replies: 10
    Last Post: 21st April 2006, 15:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.