diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -179,10 +179,6 @@ MainWindow::MainWindow(QWidget *parent) QObject::connect(snapshotMan.takeSnapshotAction(), &QAction::triggered, plotMan, &PlotManager::flashSnapshotOverlay); - // init port signals - QObject::connect(&(this->serialPort), SIGNAL(error(QSerialPort::SerialPortError)), - this, SLOT(onPortError(QSerialPort::SerialPortError))); - // init data format and reader QObject::connect(&channelMan, &ChannelManager::dataAdded, plotMan, &PlotManager::replot); @@ -372,64 +368,6 @@ void MainWindow::onPortToggled(bool open ui->actionDemoMode->setEnabled(!open); } -void MainWindow::onPortError(QSerialPort::SerialPortError error) -{ - 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(); - portControl.togglePort(); - } - portControl.loadPortList(); - break; - case QSerialPort::DeviceNotFoundError: - qCritical() << "Device doesn't exists: " << serialPort.portName(); - break; - case QSerialPort::PermissionError: - qCritical() << "Permission denied. Either you don't have \ -required privileges or device is already opened by another process."; - break; - case QSerialPort::OpenError: - qWarning() << "Device is already opened!"; - break; - case QSerialPort::NotOpenError: - qCritical() << "Device is not open!"; - break; - case QSerialPort::ParityError: - qCritical() << "Parity error detected."; - break; - case QSerialPort::FramingError: - 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: - qCritical() << "Operation is not supported."; - break; - case QSerialPort::TimeoutError: - qCritical() << "A timeout error occurred."; - break; - case QSerialPort::UnknownError: - qCritical() << "Unknown error! Error: " << serialPort.errorString(); - break; - default: - qCritical() << "Unhandled port error: " << error; - break; - } -} - void MainWindow::clearPlot() { for (unsigned ci = 0; ci < channelMan.numOfChannels(); ci++) diff --git a/src/mainwindow.h b/src/mainwindow.h --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -112,7 +112,6 @@ private: private slots: void onPortToggled(bool open); - void onPortError(QSerialPort::SerialPortError error); void onNumOfSamplesChanged(int value); void onNumOfChannelsChanged(unsigned value); diff --git a/src/portcontrol.cpp b/src/portcontrol.cpp --- a/src/portcontrol.cpp +++ b/src/portcontrol.cpp @@ -48,6 +48,8 @@ PortControl::PortControl(QSerialPort* po ui->setupUi(this); serialPort = port; + connect(serialPort, SIGNAL(error(QSerialPort::SerialPortError)), + this, SLOT(onPortError(QSerialPort::SerialPortError))); // setup actions openAction.setCheckable(true); @@ -362,6 +364,64 @@ void PortControl::onTbPortListActivated( ui->cbPortList->setCurrentIndex(index); } +void PortControl::onPortError(QSerialPort::SerialPortError error) +{ + 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(); + break; + case QSerialPort::DeviceNotFoundError: + qCritical() << "Device doesn't exists: " << serialPort->portName(); + break; + case QSerialPort::PermissionError: + qCritical() << "Permission denied. Either you don't have \ +required privileges or device is already opened by another process."; + break; + case QSerialPort::OpenError: + qWarning() << "Device is already opened!"; + break; + case QSerialPort::NotOpenError: + qCritical() << "Device is not open!"; + break; + case QSerialPort::ParityError: + qCritical() << "Parity error detected."; + break; + case QSerialPort::FramingError: + 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: + qCritical() << "Operation is not supported."; + break; + case QSerialPort::TimeoutError: + qCritical() << "A timeout error occurred."; + break; + case QSerialPort::UnknownError: + qCritical() << "Unknown error! Error: " << serialPort->errorString(); + break; + default: + qCritical() << "Unhandled port error: " << error; + break; + } +} + void PortControl::updatePinLeds(void) { auto pins = serialPort->pinoutSignals(); diff --git a/src/portcontrol.h b/src/portcontrol.h --- a/src/portcontrol.h +++ b/src/portcontrol.h @@ -92,6 +92,7 @@ private slots: void openActionTriggered(bool checked); void onCbPortListActivated(int index); void onTbPortListActivated(int index); + void onPortError(QSerialPort::SerialPortError error); void updatePinLeds(void); signals: