PDA

View Full Version : FInd Actice COM Port



bismitapadhy
19th March 2010, 06:28
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.

ChrisW67
19th March 2010, 07:31
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.

bismitapadhy
19th March 2010, 07:39
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.

squidge
19th March 2010, 08:13
The filename syntax is incorrect, you are using the old legacy format which only supports COM1 - COM9. The preferred format is:



com_port.sprintf("\\\\.\\COM%d",i);