Changeset - bcd6b30d01d1
[Not reviewed]
default
0 2 0
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-04-07 05:00:45
hy@ozderya.net
implemented skip byte function
2 files changed with 22 insertions and 0 deletions:
0 comments (0 inline, 0 general)
mainwindow.cpp
Show inline comments
 
@@ -118,12 +118,17 @@ MainWindow::MainWindow(QWidget *parent) 
 
    QObject::connect(&(this->serialPort), SIGNAL(error(QSerialPort::SerialPortError)),
 
                     this, SLOT(onPortError(QSerialPort::SerialPortError)));
 

	
 
    QObject::connect(&(this->serialPort), &QSerialPort::readyRead,
 
                     this, &MainWindow::onDataReady);
 

	
 
    // init skip byte button
 
    skipByteRequested = false;
 
    QObject::connect(ui->pbSkipByte, &QPushButton::clicked,
 
                     this, &MainWindow::skipByte);
 

	
 
    loadPortList();
 
    loadBaudRateList();
 
    ui->cbBaudRate->setCurrentIndex(ui->cbBaudRate->findText("9600"));
 

	
 
    // set limits for axis limit boxes
 
    ui->spYmin->setRange((-1) * std::numeric_limits<double>::max(),
 
@@ -311,12 +316,20 @@ void MainWindow::onPortToggled(bool open
 

	
 
void MainWindow::onDataReady()
 
{
 
    if (!ui->actionPause->isChecked())
 
    {
 
        int bytesAvailable = serialPort.bytesAvailable();
 

	
 
        if (bytesAvailable > 0 && skipByteRequested)
 
        {
 
            serialPort.read(1);
 
            skipByteRequested = false;
 
            bytesAvailable--;
 
        }
 

	
 
        if (bytesAvailable < sampleSize)
 
        {
 
            return;
 
        }
 
        else
 
        {
 
@@ -357,12 +370,17 @@ void MainWindow::onPortError(QSerialPort
 
            qDebug() << "Unhandled port error: " << error;
 
            break;
 
    }
 

	
 
}
 

	
 
void MainWindow::skipByte()
 
{
 
    skipByteRequested = true;
 
}
 

	
 
void MainWindow::addData(QVector<double> data)
 
{
 
    int offset = numOfSamples - data.size();
 

	
 
    if (offset < 0)
 
    {
mainwindow.h
Show inline comments
 
@@ -70,12 +70,14 @@ private:
 
    unsigned int sampleSize; // number of bytes in the selected number format
 
    double (MainWindow::*readSample)();
 

	
 
    // note that serialPort should already have enough bytes present
 
    template<typename T> double readSampleAs();
 

	
 
    bool skipByteRequested;
 

	
 
private slots:
 
    void loadPortList();
 
    void loadBaudRateList();
 
    void togglePort();
 
    void selectPort(QString portName);
 
    void onPortToggled(bool open);
 
@@ -85,12 +87,14 @@ private slots:
 
    void selectStopBits(int stopBits); // stopBits must be one of QSerialPort::StopBits
 
    void selectFlowControl(int flowControl); // flowControl must be one of QSerialPort::FlowControl
 

	
 
    void onDataReady();
 
    void onPortError(QSerialPort::SerialPortError error);
 

	
 
    void skipByte();
 

	
 
    void onNumOfSamplesChanged(int value);
 
    void onAutoScaleChecked(bool checked);
 
    void onYScaleChanged();
 

	
 
    void onNumberFormatButtonToggled(int numberFormatId, bool checked);
 
    void selectNumberFormat(NumberFormat numberFormatId);
0 comments (0 inline, 0 general)