Changeset - 797268305b37
[Not reviewed]
default
0 1 0
Hasan Yavuz Ă–ZDERYA - 11 years ago 2015-03-07 17:12:40
hy@ozderya.net
close port on resource error, aka device removed
1 file changed with 17 insertions and 1 deletions:
0 comments (0 inline, 0 general)
mainwindow.cpp
Show inline comments
 
@@ -164,13 +164,29 @@ void MainWindow::onDataReady()
 
    QByteArray data = serialPort.readAll();
 
    addData((unsigned char)(data[0]));
 
}
 

	
 
void MainWindow::onPortError(QSerialPort::SerialPortError error)
 
{
 
    qDebug() << "Port error happened: " << serialPort.error();
 
    switch(error)
 
    {
 
        case QSerialPort::NoError :
 
            break;
 
        case QSerialPort::ResourceError :
 
            qDebug() << "Port error: resource unavaliable; most likely device removed.";
 
            if (serialPort.isOpen())
 
            {
 
                qDebug() << "Closing port on resource error: " << serialPort.portName();
 
                togglePort();
 
            }
 
            break;
 
        default:
 
            qDebug() << "Unhandled port error: " << error;
 
            break;
 
    }
 

	
 
}
 

	
 
void MainWindow::addData(double data)
 
{
 
    // shift data array and place new data at the end
 
    for (int i = 0; i < dataArray.size()-1; i++)
0 comments (0 inline, 0 general)