Read Continuously from Serial Port in QT

#include <QCoreApplication>
#include <QtSerialPort/QSerialPort>
#include <Qdebug>

QSerialPort serial;

int main()
{
    //COM Port Configuration
    serial.setPortName("COM6");
    serial.setBaudRate(QSerialPort::Baud9600);
    serial.setDataBits(QSerialPort::Data8);
    serial.setParity(QSerialPort::NoParity);
    serial.setStopBits(QSerialPort::OneStop);
    serial.setFlowControl(QSerialPort::NoFlowControl);
    serial.open(QIODevice::ReadWrite);

    char buffer[50];

    while(1)
    {
        serial.waitForReadyRead(); // blocks calls until new data is available for reading.
        serial.readLine(buffer, 50);
        qDebug()<<buffer;
    }

    serial.close();
}


Comments

Popular posts from this blog

HackRF with srsLTE and openlte

Blinking a LED in STM32F103C8T6 (Blue Pill) Board