Reputation: 43
I am trying to stream data in real time from an arduino. Below is how I set up the serial port :
QSerialPort serial;
QByteArray value0;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
serial.setPortName("COM3");
serial.setBaudRate(QSerialPort::Baud9600);
serial.setDataBits(QSerialPort::Data8);
serial.setParity(QSerialPort::NoParity);
serial.setStopBits(QSerialPort::OneStop);
serial.setFlowControl(QSerialPort::NoFlowControl);
serial.open(QIODevice::ReadWrite);
}
....
This is how I have tried to change the serial data into a double :
serial.readData();
Upvotes: 1
Views: 763
Reputation: 32645
You should convert the raw byte array to double according to your device logic. But in case you have sent the data on the other side by streaming it, you can read it by :
QByteArray data = serial->readAll();
QDataStream stream(data);
double value;
stream>>value
Upvotes: 1