728x90
void Comsetting::getSerialPortList()
{
    TCHAR lpTargetPath[5000]; // buffer to store the path of the COMPORTS
    DWORD test;

    for (int i = 0; i < 255; i++) // checking ports from COM0 to COM255
    {
        QString str = "COM" + QString::number(i); // converting to COM0, COM1, COM2
        wchar_t* wstr = new wchar_t[str.length() + 1];
        str.toWCharArray(wstr);
        wstr[str.length()] = 0;
        test = QueryDosDevice(wstr, lpTargetPath, 5000);

        if (test != 0)
        {
            ui->cbPortName->addItem(QString::fromWCharArray(wstr));
        }
    }
}

 

728x90

+ Recent posts