Solved How to Receive the data as a String in pc From Arduino
-
Here , I have receive the data in QByte array ,
the input data isif (Serial.available() > 0) { // read the incoming byte: incomingByte = Serial.read(); // say what you got: Serial.print("I received: "); // This is the what i want to receive from the Arduino Serial.println(incomingByte, DEC);
But in PC , Its came as a byte array Even i have changed as a QString .
I got a output like this
I
rec
eive
d: 1
08
I re
cei
ved:
105
I
rece
ive
d: 1
10
I re
ceiv
ed:
101Its split into Pieces ..
I want to get a output as what i gave in Arduino , I mean
Serial.print("I received: ");I want a output as "I received:"
This is my Qt code
connect(serial, &QSerialPort::readyRead, this, &MainWindow::serialReceived); void MainWindow::serialReceived() // { QString glen = serial->readAll().trimmed(); if (glen.length() > 0) { ui->receive->append(glen); } checkAndSendData(); }
Thanks in Advance
-
@sankarapandiyan said in How to Receive the data as a String in pc From Arduino:
Its split into Pieces ..
of course, there's no guarantee that all send data arrives at the same time.
Each time you new data is available, readyRead is emitted it's your job as programmer to store the bytes and decide when the frame is complete.That said, increasing the baud rate would probably help, at least for such small data packages
-
The QTextEdit just does what you told it to do - see QTextEdit::append():
Appends a new paragraph with text to the end of the text edit.
So you should use maybe QTextEdit::setPlaintText() instead.
-
This post is deleted! -
@sankarapandiyan said in How to Receive the data as a String in pc From Arduino:
Its split into Pieces ..
of course, there's no guarantee that all send data arrives at the same time.
Each time you new data is available, readyRead is emitted it's your job as programmer to store the bytes and decide when the frame is complete.That said, increasing the baud rate would probably help, at least for such small data packages
-
@Yunus said in How to Receive the data as a String in pc From Arduino:
QString command = "something"; arduino->write(command.toStdString().c_str());
No! Never ever! toStdCString() ist the worst choice ever as you don't specify an encoding. Most often you have to use
toUtf8()
.QString command = "something"; // expecting arduino->write(const char *); function signature arduino->write(command.toUtf8().constData()); // or toLatin1() or toLocal8Bit()
Regards
-
@Yunus said in How to Receive the data as a String in pc From Arduino:
Maybe this conversion could work while reading too.
First - why to you convert a QString into a std::string into a char* array just to create a QByteArray out of it? QString has functions to directly create a QByteArray.
Second - it's not the way you send the data, it's the function you use to insert the incoming data into a QTextEdit - the documentation clearly states that a new paragraph is started, so a newline will be added... -
@J-Hilk Wow impressed, Thanks for your reply
.. now i have increased the Baud rate , Now my output is
I received: 108
I received: 10
5
I received: 110
I received: 101
I received:
32
I received: 49
I received: 13
I received: -
@Yunus Ok fine thanks