Changeset - a20eb6fea911
[Not reviewed]
default
0 1 0
Hasan Yavuz Ă–ZDERYA - 11 years ago 2015-03-07 17:18:26
hy@ozderya.net
update port list on resource error
1 file changed with 1 insertions and 0 deletions:
0 comments (0 inline, 0 general)
mainwindow.cpp
Show inline comments
 
@@ -157,45 +157,46 @@ void MainWindow::selectBaudRate(QString 
 
void MainWindow::onPortToggled(bool open)
 
{
 
    ui->pbOpenPort->setChecked(open);
 
}
 

	
 
void MainWindow::onDataReady()
 
{
 
    QByteArray data = serialPort.readAll();
 
    addData((unsigned char)(data[0]));
 
}
 

	
 
void MainWindow::onPortError(QSerialPort::SerialPortError 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();
 
            }
 
            loadPortList();
 
            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++)
 
    {
 
        dataArray[i] = dataArray[i+1];
 
    }
 
    dataArray.last() = data;
 

	
 
    // update plot
 
    curve.setSamples(dataX, dataArray);
 
    ui->plot->replot();
 
}
0 comments (0 inline, 0 general)