bool SerialPortInfo::isValid() const
{
    if (!loadDevices())
        return false;

    RCommServ server;
    TInt r = server.Connect();
    if (r != KErrNone)
        return false;

    RComm port;
    TPtrC portName(static_cast<const TUint16*>(systemLocation().utf16()), systemLocation().length());
    r = port.Open(server, portName, ECommExclusive);
    if (r == KErrNone)
        port.Close();
    return r == KErrNone || r == KErrLocked;
}
Exemple #2
0
bool QSerialPortInfo::isValid() const
{
    const HANDLE descriptor = ::CreateFile(reinterpret_cast<const wchar_t*>(systemLocation().utf16()),
                                           GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

    if (descriptor == INVALID_HANDLE_VALUE) {
        if (::GetLastError() != ERROR_ACCESS_DENIED)
            return false;
    } else {
        ::CloseHandle(descriptor);
    }
    return true;
}
SelectSerialPortDlg::SelectSerialPortDlg(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::SelectSerialPortDlg)
{
    ui->setupUi(this);

    // Add all serial devices to list UI.
    QList<QSerialPortInfo> devices(QSerialPortInfo::availablePorts());
    for (auto iter = devices.begin(); devices.end() != iter; ++iter)
    {
        ui->serialDeviceListWidget->addItem(iter->systemLocation());
    }

    // Prevent window from being resized.
    setFixedSize(size().width(), size().height());

    syncUiWidgets();
}
bool QSerialPortInfo::isValid() const
{
    QFile f(systemLocation());
    return f.exists();
}