Sending and receiving data from/to PC/Arduino through serial port using QT
-
serialPort->write("0");
Did you already read about signals and slots in Qt ?
-
serialPort->write("0");
Did you already read about signals and slots in Qt ?
@SGaist This line is what i am doing now for turning on an LED on Arduino. but I want to send an array contains 8 bytes ( command of 5 bytes, int (2 bytes), status(2 bytes) ) which is 8 bytes data array. I have the corresponding Arduino code that receives the same data frame in PC as was sent to Arduino. Many thanks in advance for any help.
-
Nobody helps? I need to write 8 bytes data in Arduino and receive the same data sent in PC, I need to read the serial and convert it to the float and print it. I would be grateful if anybody can help me.
@DanAm Did you take a look at example applications: https://doc.qt.io/qt-5/qtserialport-examples.html ?
-
Nobody helps? I need to write 8 bytes data in Arduino and receive the same data sent in PC, I need to read the serial and convert it to the float and print it. I would be grateful if anybody can help me.
@DanAm said in Sending and receiving data from/to PC/Arduino through serial port using QT:
Nobody helps? I need to write 8 bytes data in Arduino and receive the same data sent in PC, I need to read the serial and convert it to the float and print it. I would be grateful if anybody can help me.
Please have some patience and let at least 24 hours before bumping your own thread. This is a voluntary driven forum and people might not even live in the same timezone as you.
As @jsulm suggested there are several examples in Qt's documentation to get you started with bi-directionnal serial communication.
As for the array you want to send:
@DanAm said in Sending and receiving data from/to PC/Arduino through serial port using QT:
I want to send an array contains 8 bytes ( command of 5 bytes, int (2 bytes), status(2 bytes) ) which is 8 bytes data array.
That makes it 9 bytes. Also, an int is not 2 bytes, that's rather a short. So what exactly do you want to send ?
-
@DanAm said in Sending and receiving data from/to PC/Arduino through serial port using QT:
Nobody helps? I need to write 8 bytes data in Arduino and receive the same data sent in PC, I need to read the serial and convert it to the float and print it. I would be grateful if anybody can help me.
Please have some patience and let at least 24 hours before bumping your own thread. This is a voluntary driven forum and people might not even live in the same timezone as you.
As @jsulm suggested there are several examples in Qt's documentation to get you started with bi-directionnal serial communication.
As for the array you want to send:
@DanAm said in Sending and receiving data from/to PC/Arduino through serial port using QT:
I want to send an array contains 8 bytes ( command of 5 bytes, int (2 bytes), status(2 bytes) ) which is 8 bytes data array.
That makes it 9 bytes. Also, an int is not 2 bytes, that's rather a short. So what exactly do you want to send ?
@SGaist Yes you are right.
My mistake, I want to send a command of 4 bytes and status of 2 bytes and a counter that has 2 bytes. It makes 8 bytes that I want to send and receive. And also I want to convert the received command to float in QT and display it. Can I use this way :
QByteArray command ;
command.resize(4);
command[0]=0x41;
command[1]=0xf8;
command[2]=0xf6;
command[3]=0x00;float value;
QDataStream stream(command);
stream >> value;qDebug() << value;
Thanks
-
Why not use QByteArray::toFloat ?
-
Why not use QByteArray::toFloat ?
-
@SGaist thanks, i think the problem solved.
One general question : to send through serial port, do we need to stream the byte array (QByteArray type) using QDataStream or we can write the array in the port directly ?
@DanAm said in Sending and receiving data from/to PC/Arduino through serial port using QT:
the problem solved
so please don't forget to mark this post as such!
-
@SGaist thanks, i think the problem solved.
One general question : to send through serial port, do we need to stream the byte array (QByteArray type) using QDataStream or we can write the array in the port directly ?
@DanAm said in Sending and receiving data from/to PC/Arduino through serial port using QT:
One general question : to send through serial port, do we need to stream the byte array (QByteArray type) using QDataStream or we can write the array in the port directly ?
Either, you do not have to use
QDataStream
.