-1

I have some data coming over serial connection into my C++ Application. Now I wan't to make a simple GUI with a strip chart of those data plus some buttons. (Something like 10Hz refresh rate)

The Buttons are not really a problem. But I didn't find any Qt plugin for strip charts. Is there any or some other library I could call from c++. There should be plenty considering that it is rather simple and common task.

OS: Ubuntu

CC: g++

László Papp
  • 51,870
  • 39
  • 111
  • 135
magu_
  • 4,766
  • 3
  • 45
  • 79
  • Ehr, Why the downvote? Is it that horrible of a question? I don't think that I'm the only one having that problem... – magu_ Jan 04 '14 at 16:05

2 Answers2

1

Take a look at the following widgets:

Also charts might be a good choice (easy to implement with QML)

https://www.qt.io/blog/2013/11/07/qt-data-visualization-technology-preview-and-charts-1-3-1-release

or implement one by yourself with

https://doc.qt.io/qt-5/qtwidgets-graphicsview-diagramscene-example.html

ololuki
  • 377
  • 1
  • 7
  • 14
Marco A.
  • 43,032
  • 26
  • 132
  • 246
1

This does not necessarily need a separate library on its own, but it is common to combine such QtSerialPort and Qwt for such use cases.

The basic principle is to use asynchronous reading. You could run a timer internally with a fixed period, and then you could draw the next part of the "strip chart" in each interval that you specify.

You could do this until a certain condition is met, like there is no more data available and so forth. You have not mentioned whether you are using QtSerialPort, but this is almost tangential even though it would probably make sense to use it in a Qt Project.

You could write something like the code below in QtSerialPort for our async reader example. The idea is that you append periodically into your graphical widget.

SerialPortReader::SerialPortReader(QSerialPort *serialPort, QObject *parent)
    : QObject(parent)
    , m_serialPort(serialPort)
    , m_standardOutput(stdout)
{
    connect(m_serialPort, SIGNAL(readyRead()), SLOT(handleReadyRead()));
    connect(m_serialPort, SIGNAL(error(QSerialPort::SerialPortError)), SLOT(handleError(QSerialPort::SerialPortError)));
    connect(&m_timer, SIGNAL(timeout()), SLOT(handleTimeout()));

    m_timer.start(5000);
}

SerialPortReader::~SerialPortReader()
{
}

void SerialPortReader::handleReadyRead()
{
    m_readData.append(m_serialPort->readAll());
    // *** This will display the next part of the strip chart ***
    // *** Optionally make the use of a plotting library here as 'Qwt' ***
    myWidget.append('=');

    if (!m_timer.isActive())
        m_timer.start(5000);
}

void SerialPortReader::handleTimeout()
{
    if (m_readData.isEmpty()) {
        m_standardOutput << QObject::tr("No data was currently available for reading from port %1").arg(m_serialPort->portName()) << endl;
    } else {
        m_standardOutput << QObject::tr("Data successfully received from port %1").arg(m_serialPort->portName()) << endl;
        m_standardOutput << m_readData << endl;
    }

    QCoreApplication::quit();
}

void SerialPortReader::handleError(QSerialPort::SerialPortError serialPortError)
{
    if (serialPortError == QSerialPort::ReadError) {
        m_standardOutput << QObject::tr("An I/O error occurred while reading the data from port %1, error: %2").arg(m_serialPort->portName()).arg(m_serialPort->errorString()) << endl;
        QCoreApplication::exit(1);
    }
}
László Papp
  • 51,870
  • 39
  • 111
  • 135
  • Thank you for your answer, Since I already have done the rest I will stick to it for this time. But I should defently have a closer look into Qt in general – magu_ Jan 04 '14 at 16:03
  • @magu_: it is strange that you selected a link-only answer. ;-) – László Papp Dec 21 '14 at 10:52