Changeset - 0fba5e1a3d2e
[Not reviewed]
default
0 1 0
Hasan Yavuz ÖZDERYA - 7 years ago 2019-01-22 09:43:43
hy@ozderya.net
suppress "unknown" error messages when a pseudo terminal is opened
1 file changed with 18 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/portcontrol.cpp
Show inline comments
 
/*
 
  Copyright © 2017 Hasan Yavuz Özderya
 
  Copyright © 2019 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
  serialplot is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  serialplot is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU General Public License for more details.
 
@@ -357,24 +357,31 @@ void PortControl::openActionTriggered(bo
 
void PortControl::onCbPortListActivated(int index)
 
{
 
    tbPortList.setCurrentIndex(index);
 
}
 

	
 
void PortControl::onTbPortListActivated(int index)
 
{
 
    ui->cbPortList->setCurrentIndex(index);
 
}
 

	
 
void PortControl::onPortError(QSerialPort::SerialPortError error)
 
{
 
#ifdef Q_OS_UNIX
 
    // For suppressing "Invalid argument" errors that happens with pseudo terminals
 
    auto isPtsInvalidArgErr = [this] () -> bool {
 
        return serialPort->portName().contains("pts/") && serialPort->errorString().contains("Invalid argument");
 
    };
 
#endif
 

	
 
    switch(error)
 
    {
 
        case QSerialPort::NoError :
 
            break;
 
        case QSerialPort::ResourceError :
 
            qWarning() << "Port error: resource unavaliable; most likely device removed.";
 
            if (serialPort->isOpen())
 
            {
 
                qWarning() << "Closing port on resource error: " << serialPort->portName();
 
                togglePort();
 
            }
 
            loadPortList();
 
@@ -399,30 +406,40 @@ required privileges or device is already
 
            qCritical() << "Framing error detected.";
 
            break;
 
        case QSerialPort::BreakConditionError:
 
            qCritical() << "Break condition is detected.";
 
            break;
 
        case QSerialPort::WriteError:
 
            qCritical() << "An error occurred while writing data.";
 
            break;
 
        case QSerialPort::ReadError:
 
            qCritical() << "An error occurred while reading data.";
 
            break;
 
        case QSerialPort::UnsupportedOperationError:
 
#ifdef Q_OS_UNIX
 
            // Qt 5.5 gives "Invalid argument" with 'UnsupportedOperationError'
 
            if (isPtsInvalidArgErr())
 
                break;
 
#endif
 
            qCritical() << "Operation is not supported.";
 
            break;
 
        case QSerialPort::TimeoutError:
 
            qCritical() << "A timeout error occurred.";
 
            break;
 
        case QSerialPort::UnknownError:
 
#ifdef Q_OS_UNIX
 
            // Qt 5.2 gives "Invalid argument" with 'UnknownError'
 
            if (isPtsInvalidArgErr())
 
                break;
 
#endif
 
            qCritical() << "Unknown error! Error: " << serialPort->errorString();
 
            break;
 
        default:
 
            qCritical() << "Unhandled port error: " << error;
 
            break;
 
    }
 
}
 

	
 
void PortControl::updatePinLeds(void)
 
{
 
    auto pins = serialPort->pinoutSignals();
 
    ui->ledDCD->setOn(pins & QSerialPort::DataCarrierDetectSignal);
0 comments (0 inline, 0 general)