Changeset - 4c9e48a45ddf
[Not reviewed]
default
0 1 0
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-07-26 15:12:41
hy@ozderya.net
show device information in port name list (such as USB devices)
1 file changed with 16 insertions and 2 deletions:
0 comments (0 inline, 0 general)
portcontrol.cpp
Show inline comments
 
@@ -35,12 +35,14 @@ PortControl::PortControl(QSerialPort* po
 
    QObject::connect(ui->pbReloadPorts, &QPushButton::clicked,
 
                     this, &PortControl::loadPortList);
 

	
 
    QObject::connect(ui->pbOpenPort, &QPushButton::clicked,
 
                     this, &PortControl::togglePort);
 

	
 
    // TODO: port name coming from combobox is dirty, create a separate layer of signals
 
    //       that will sanitize this information
 
    QObject::connect(ui->cbPortList,
 
                     SELECT<const QString&>::OVERLOAD_OF(&QComboBox::activated),
 
                     this, &PortControl::selectPort);
 

	
 
    QObject::connect(ui->cbPortList,
 
                     SELECT<const QString&>::OVERLOAD_OF(&QComboBox::activated),
 
@@ -109,13 +111,21 @@ void PortControl::loadPortList()
 

	
 
    ui->cbPortList->clear();
 

	
 
    discoveredPorts.clear();
 
    for (auto port : QSerialPortInfo::availablePorts())
 
    {
 
        ui->cbPortList->addItem(port.portName());
 
        QString pName = port.portName();
 
        if (!port.description().isEmpty()) pName += QString(" ") + port.description();
 
        if (port.hasProductIdentifier())
 
        {
 
            QString vID = QString("%1").arg(port.vendorIdentifier(), 4, 16, QChar('0'));
 
            QString pID = QString("%1").arg(port.productIdentifier(), 4, 16, QChar('0'));
 
            pName = pName + " [" + vID + ":" + pID + "]";
 
        }
 
        ui->cbPortList->addItem(pName);
 
        discoveredPorts << port.portName();
 
    }
 

	
 
    ui->cbPortList->addItems(userEnteredPorts);
 

	
 
    // find current selection in the new list, maybe it doesn't exist anymore?
 
@@ -206,13 +216,15 @@ void PortControl::togglePort()
 
        serialPort->close();
 
        qDebug() << "Closed port:" << serialPort->portName();
 
        emit portToggled(false);
 
    }
 
    else
 
    {
 
        serialPort->setPortName(ui->cbPortList->currentText());
 
        // port name may contain description
 
        QString portName = ui->cbPortList->currentText().split(" ")[0];
 
        serialPort->setPortName(portName);
 

	
 
        // open port
 
        if (serialPort->open(QIODevice::ReadWrite))
 
        {
 
            // set port settings
 
            selectBaudRate(ui->cbBaudRate->currentText());
 
@@ -227,12 +239,14 @@ void PortControl::togglePort()
 
    }
 
    ui->pbOpenPort->setChecked(serialPort->isOpen());
 
}
 

	
 
void PortControl::selectPort(QString portName)
 
{
 
    // portName may be coming from combobox
 
    portName = portName.split(" ")[0];
 
    // has selection actually changed
 
    if (portName != serialPort->portName())
 
    {
 
        // if another port is already open, close it by toggling
 
        if (serialPort->isOpen())
 
        {
0 comments (0 inline, 0 general)