Serial flow with multiples data (Arduino) [SOLVED]



  • Hi all,

    I just finished a Qt program which read a serial flow from an Arduino.
    This program works well when I print just only one data from Arduino.
    But how Qt can read multiple data sent within the serial flow of the same Arduino ?

    I give you my Qt code just in case, which print only one data:

    @
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QSerialPort>

    using namespace std;

    QSerialPort *serial;

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    serial=new QSerialPort(this);
    serial->setPortName("/dev/ttyACM0");
    serial->setBaudRate(QSerialPort::Baud9600);
    serial->setDataBits(QSerialPort::Data8);
    serial->setParity(QSerialPort::NoParity);
    serial->setStopBits(QSerialPort::OneStop);
    serial->setFlowControl(QSerialPort::NoFlowControl);
    serial->open(QIODevice::ReadOnly);//mettre un bouton d'activation du port

    connect(serial, SIGNAL(readyRead()),this,SLOT(serialReceived()));
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    serial->close();
    }

    void MainWindow::serialReceived()
    {
    QByteArray valeur;
    valeur = serial->readAll();
    float nb = valeur.toFloat();
    ui->lcdNumber->display(nb);
    }
    @

    Thanks for your help, time and support.

    Regards,



  • I do not understand, what do you want?

    Please, read similar issue (as I understand): http://qt-project.org/forums/viewthread/52407/



  • Hi,

    Thanks for the link but I have not this kind of problem.

    My problem is:

    1- Arduino is coded to send three data over serial port. (Works)
    2- Qt received the flow of the serial port (Works)
    3- Qt show me just only one value over three (Doesn't work)

    So my question is:

    Does it exist a way to show these 3 values on Qt in C++ (Linux) ?
    The three values are plot on the serial terminal of the arduino like this:

    data1 data2 data3

    Actually, Qt show only data1.

    Thanks for your help



  • bq. Does it exist a way to show these 3 values on Qt in C++ (Linux) ?

    yes. just check your input stream, llike:

    @
    void MainWindow::serialReceived()
    {
    qDebug() << serial->bytesAvailable();
    }
    @

    for data1 .. data3 size. and then to parse your input stream correctly.



  • Thanks so much fore your help Kuzulis.

    Regards,


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.