QT c++ open Serial port more than once

704 Views Asked by At

I search an example to open multiple serial ports in qt.

My open port function settings forward from other class

void MainWindow::openSerialPort(){
    SettingsDialog::Settings p = settings->settings();
    serial->setPortName(p.name);
    serial->setBaudRate(QSerialPort::Baud9600);
    serial->setDataBits(QSerialPort::Data8);
    serial->setParity(QSerialPort::NoParity);
    serial->setStopBits(QSerialPort::OneStop);
    serial->setFlowControl(QSerialPort::NoFlowControl);

if (serial->open(QIODevice::ReadWrite)) { 
    ui->connectAction->setEnabled(false);
    ui->disconnectAction->setEnabled(true);
    ui->settingsAction->setEnabled(false);
    showStatusMessage(tr("Connected to %1 : OK")
                      .arg(p.name));
} else { //gdy sie nie udalo error
    QMessageBox::critical(this, tr("Error"), serial->errorString());

    showStatusMessage(tr("Open error"));
}
}
1

There are 1 best solutions below

0
On

As far as I remember single instance of QSerialPort if opened does it exclusively so no other instance has access to this port. I guess creating other QSP and opening other port would do the thing.