Changeset - 73abbe942246
[Not reviewed]
default
0 1 0
Hasan Yavuz Ă–ZDERYA - 11 years ago 2015-03-16 18:27:43
hy@ozderya.net
discard all received data when paused
1 file changed with 4 insertions and 0 deletions:
0 comments (0 inline, 0 general)
mainwindow.cpp
Show inline comments
 
@@ -209,48 +209,52 @@ void MainWindow::onPortToggled(bool open
 

	
 
void MainWindow::onDataReady()
 
{
 
    if (!ui->actionPause->isChecked())
 
    {
 
        int bytesAvailable = serialPort.bytesAvailable();
 
        if (bytesAvailable < sampleSize)
 
        {
 
            return;
 
        }
 
        else
 
        {
 
            int numOfSamplesToRead =
 
                (bytesAvailable - (bytesAvailable % sampleSize)) / sampleSize;
 
            QVector<double> samples(numOfSamplesToRead);
 
            int i = 0;
 
            while(i < numOfSamplesToRead)
 
            {
 
                samples.replace(i, (this->*readSample)());
 
                i++;
 
            }
 
            addData(samples);
 
        }
 
    }
 
    else
 
    {
 
        serialPort.clear(QSerialPort::Input);
 
    }
 
}
 

	
 
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;
 
    }
 

	
 
}
 

	
0 comments (0 inline, 0 general)