QML SerialPort: using readAll or readLine but receive multi lines
-
I want to received data only 1 line/1time.Thank in advance
open serial:void SerialPort:: openSerialPort (QString comName, int baudRate) { ... connect (serial, SIGNAL (readyRead()), this, SLOT (readFromSerialPort())); }
read from serial funtion
void SerialPort::readFromSerialPort() { \\ if (serial->canReadLine()) \\ { QByteArray data = QByteArray (serial->readAll()); emit getData (data.toHex()); \\ } }
...
qml file:Connections { target: MySerial onGetData: { textArea.append(data) } }
this is result (3 lines):
-
readAll reads all the data. Did you try with read(..) or readLine(..) with maxsize ?
-
@taind said in QML SerialPort: using readAll or readLine but receive multi lines:
XCTU software
I don't know what it is and what data it is sending. If it sends binary data I would not expect to be able to read it correctly line by line. You really should first clarify what type of data you actually get (binary? text?).
-
@taind said in QML SerialPort: using readAll or readLine but receive multi lines:
@jsulm i received from XCTU software and I don't know why "serial->canReadLine()" this case is always "false"
probably because your frame doesn't end on
0x0A
? the last one seems to be 0xFD -
@taind said in QML SerialPort: using readAll or readLine but receive multi lines:
data return text type when readLine from serial
That doesn't mean that the other side is sending text...
-
@taind
Since you do not seem to have any idea what bytes are being sent to you, before trying to "read lines" you should really just usereadAll()
and (convert the bytes to hex if you wish) look at what is being actually being sent before proceeding to code.