Basically iterate through a list of available ports and add them as a kind of radio button checkable actions or as a QComboBox
. Then when one gets selected, change your self.portName
to reflect the new one.
The example in pure Qt for doing this is under the Terminal Qt Serial Port example, under the SettingsDialog
.
http://doc.qt.io/qt-5/qtserialport-terminal-settingsdialog-cpp.html
void SettingsDialog::fillPortsInfo()
{
ui->serialPortInfoListBox->clear();
static const QString blankString = QObject::tr("N/A");
QString description;
QString manufacturer;
QString serialNumber;
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
QStringList list;
description = info.description();
manufacturer = info.manufacturer();
serialNumber = info.serialNumber();
list << info.portName()
<< (!description.isEmpty() ? description : blankString)
<< (!manufacturer.isEmpty() ? manufacturer : blankString)
<< (!serialNumber.isEmpty() ? serialNumber : blankString)
<< info.systemLocation()
<< (info.vendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : blankString)
<< (info.productIdentifier() ? QString::number(info.productIdentifier(), 16) : blankString);
ui->serialPortInfoListBox->addItem(list.first(), list);
}
}
It doesn't look like PyQt
has the QtSerialPort
library (probably because pySerial
and similar libraries are already available).
Hope that helps.