UART terminal
-
wrote on 3 May 2023, 21:05 last edited by another_one 5 Mar 2023, 21:05
Hello!
I wrote program which transfer "big data"(file) and receive ASCII simbol
Now I need to receive alse ASCII strinigs and control carriedge return and feedback
To receive ASCII symbol I used timer and call read fuction by timer count release
And the problem is I don't know how to call read function to be able to receive all ASCII strings without their size depends and how to call read permamently without taking all processing timeThanks in advance
-
Hello!
I wrote program which transfer "big data"(file) and receive ASCII simbol
Now I need to receive alse ASCII strinigs and control carriedge return and feedback
To receive ASCII symbol I used timer and call read fuction by timer count release
And the problem is I don't know how to call read function to be able to receive all ASCII strings without their size depends and how to call read permamently without taking all processing timeThanks in advance
wrote on 4 May 2023, 18:02 last edited by another_one 5 Apr 2023, 18:02@another_one
Sorry for what post, I was wrong in declaring the point of the question.
Now I can receive any size data strings from COM-port by using checking bytes available.
And this data I transfer to textEdit at all, but the result I see in some wrong format, - I see uncompleted, by new line, strings.
And I think it has two reason:- timer->start(10), - I use timer event to read data from qextserialport driver and that divides the string;
- ui->textEdit->append(tr("%1").arg(stReadHex)), - This function adds new line.
Thus, I need to control new line adding or exclude string dividing.
Please help! -
@another_one
Sorry for what post, I was wrong in declaring the point of the question.
Now I can receive any size data strings from COM-port by using checking bytes available.
And this data I transfer to textEdit at all, but the result I see in some wrong format, - I see uncompleted, by new line, strings.
And I think it has two reason:- timer->start(10), - I use timer event to read data from qextserialport driver and that divides the string;
- ui->textEdit->append(tr("%1").arg(stReadHex)), - This function adds new line.
Thus, I need to control new line adding or exclude string dividing.
Please help!@another_one said in UART terminal:
timer->start(10), - I use timer event to read data from qextserialport driver and that divides the string;
Don't use a timer but signals and slots.
And since it's a stream you will for sure get some data but not a complete line - it's up to you to bring the data to a desired format. -
@another_one said in UART terminal:
timer->start(10), - I use timer event to read data from qextserialport driver and that divides the string;
Don't use a timer but signals and slots.
And since it's a stream you will for sure get some data but not a complete line - it's up to you to bring the data to a desired format.wrote on 5 May 2023, 06:57 last edited byThank you for your replay !
Could you give me some example, please ?
I serached about what before, but didn't find any similar to my case.Thanks!
-
Thank you for your replay !
Could you give me some example, please ?
I serached about what before, but didn't find any similar to my case.Thanks!
The QSerialPort documentation has a lot of examples on how to use the serial port: https://doc.qt.io/qt-5/qtserialport-examples.html
Using signals and slots is a basic Qt feature you should learn - otherwise you will not have fun with Qt!
-
The QSerialPort documentation has a lot of examples on how to use the serial port: https://doc.qt.io/qt-5/qtserialport-examples.html
Using signals and slots is a basic Qt feature you should learn - otherwise you will not have fun with Qt!
wrote on 5 May 2023, 07:27 last edited by@Christian-Ehrlicher
Thank you! -
@Christian-Ehrlicher
Thank you!wrote on 5 May 2023, 10:19 last edited by@another_one
With your help I have done UART receive via signal and clots:connect(port, SIGNAL(readyRead()), this, SLOT(readData())); void MIPS_monitor::readData() { const QByteArray data = port->readAll(); ui->textEdit->append(data); }
But string dividing is still exist
-
@another_one
With your help I have done UART receive via signal and clots:connect(port, SIGNAL(readyRead()), this, SLOT(readData())); void MIPS_monitor::readData() { const QByteArray data = port->readAll(); ui->textEdit->append(data); }
But string dividing is still exist
wrote on 5 May 2023, 10:23 last edited by JonB 5 May 2023, 11:10@another_one
@Christian-Ehrlicher has already answered that "string dividing" (as you call it) is natural/possible/inevitable. The signals have no guarantee they will be emitted e.g. "one line at a time". That's how it works.As he has said
And since it's a stream you will for sure get some data but not a complete line - it's up to you to bring the data to a desired format.
It is your job to write code to "aggregate" received data in a buffer if you might want to "join" the data received at multiple signals.
-
@another_one
@Christian-Ehrlicher has already answered that "string dividing" (as you call it) is natural/possible/inevitable. The signals have no guarantee they will be emitted e.g. "one line at a time". That's how it works.As he has said
And since it's a stream you will for sure get some data but not a complete line - it's up to you to bring the data to a desired format.
It is your job to write code to "aggregate" received data in a buffer if you might want to "join" the data received at multiple signals.
wrote on 2 Jun 2023, 10:52 last edited bySorry I didnt understand
I checked data stream from external device and that is not devide transferring data
I thouught what qt driver will give receiced data as is but I has his job as results in the following format:Pin # 4 LED ON Pin # 3 LED ON Pin # 3 LED OFF Pin # 4 LED OFF Pin # 3 LED ON Pin # 3 LED OFF Pin # 4 LED ON Pin # 3 LED ON Pin # 3 LED OFF Pin # 4 LED OFF Pin # 3 LED ON Pin # 3 LED OFF Pin # 4 LED ON Pin # 3 LED ON Pin # 3 LED OFF Pin # 4 LED OFF Pin # 3 LED ON Pin # 3 LED OFF Pin # 4 LED ON Pin # 3 LED ON Pin # 3 LED OFF
Is it normal?, do you want to say what?
And as I udenerstand you right I must buffer (I think what it has already buffered by qt driver)that data to format it ?Thanks
-
Sorry I didnt understand
I checked data stream from external device and that is not devide transferring data
I thouught what qt driver will give receiced data as is but I has his job as results in the following format:Pin # 4 LED ON Pin # 3 LED ON Pin # 3 LED OFF Pin # 4 LED OFF Pin # 3 LED ON Pin # 3 LED OFF Pin # 4 LED ON Pin # 3 LED ON Pin # 3 LED OFF Pin # 4 LED OFF Pin # 3 LED ON Pin # 3 LED OFF Pin # 4 LED ON Pin # 3 LED ON Pin # 3 LED OFF Pin # 4 LED OFF Pin # 3 LED ON Pin # 3 LED OFF Pin # 4 LED ON Pin # 3 LED ON Pin # 3 LED OFF
Is it normal?, do you want to say what?
And as I udenerstand you right I must buffer (I think what it has already buffered by qt driver)that data to format it ?Thanks
wrote on 2 Jun 2023, 11:57 last edited by JonB 6 Feb 2023, 18:31@another_one said in UART terminal:
Pin # 3
LED ONTake this as an example. We have explained that it can happen that device sends
Pin #3 LED ON
in a singlewrite()
. So no "divide" as you call it.But it is possible that
readAll()
can receive this in multiple "chunks"/"divides". So It could arrive as 2 pieces toreadAll()
: first time it getsPin # 3
, second time it gets remainingLED ON
. And that seems to be happening here.Since
QTextEdit::append(text)
documents "Appends a new paragraph" you will end up with separate lines if you callappend()
twice, once for each "fragment" of the line. If you want it output on one line you will need to "join" partial lines like this, only callappend()
when you have (one or more) full lines. -
@another_one said in UART terminal:
Pin # 3
LED ONTake this as an example. We have explained that it can happen that device sends
Pin #3 LED ON
in a singlewrite()
. So no "divide" as you call it.But it is possible that
readAll()
can receive this in multiple "chunks"/"divides". So It could arrive as 2 pieces toreadAll()
: first time it getsPin # 3
, second time it gets remainingLED ON
. And that seems to be happening here.Since
QTextEdit::append(text)
documents "Appends a new paragraph" you will end up with separate lines if you callappend()
twice, once for each "fragment" of the line. If you want it output on one line you will need to "join" partial lines like this, only callappend()
when you have (one or more) full lines.wrote on 2 Jun 2023, 16:35 last edited byThank you for your detailed explanation the reason of the problem!
But sorry again, I didn't understand what should I do (how can I call "only append()") to solve this problem?.Thanks in advaunce!
-
Thank you for your detailed explanation the reason of the problem!
But sorry again, I didn't understand what should I do (how can I call "only append()") to solve this problem?.Thanks in advaunce!
wrote on 2 Jun 2023, 17:43 last edited by@another_one
Build up a line (however they are terminated, carriage return or whatever) before callingQTextEdit:: append()
. I would keep a class member variable for a buffer and each timerealAll()
returns anything append it into that buffer. When a line is complete add it to the text edit and remove from the buffer. That's what a buffer is. -
@another_one
Build up a line (however they are terminated, carriage return or whatever) before callingQTextEdit:: append()
. I would keep a class member variable for a buffer and each timerealAll()
returns anything append it into that buffer. When a line is complete add it to the text edit and remove from the buffer. That's what a buffer is.wrote on 5 Jun 2023, 14:27 last edited byThank you again! sorry, but can you give me some example please?
And why simplified() and trimmed() can not solve this problem(I tried)?
And I don't understand one more moment:
I receive data what can consits of \r\n and "Appends a new paragraph" gives another one \r\n.
How can I parse needest one in this case? -
Sorry I didnt understand
I checked data stream from external device and that is not devide transferring data
I thouught what qt driver will give receiced data as is but I has his job as results in the following format:Pin # 4 LED ON Pin # 3 LED ON Pin # 3 LED OFF Pin # 4 LED OFF Pin # 3 LED ON Pin # 3 LED OFF Pin # 4 LED ON Pin # 3 LED ON Pin # 3 LED OFF Pin # 4 LED OFF Pin # 3 LED ON Pin # 3 LED OFF Pin # 4 LED ON Pin # 3 LED ON Pin # 3 LED OFF Pin # 4 LED OFF Pin # 3 LED ON Pin # 3 LED OFF Pin # 4 LED ON Pin # 3 LED ON Pin # 3 LED OFF
Is it normal?, do you want to say what?
And as I udenerstand you right I must buffer (I think what it has already buffered by qt driver)that data to format it ?Thanks
wrote on 5 Jun 2023, 16:30 last edited by@another_one said in UART terminal:
I checked data stream from external device and that is not devide transferring data
In this case, have a try with canReadline() and then readLine()
Should be easier ... -
@another_one said in UART terminal:
I checked data stream from external device and that is not devide transferring data
In this case, have a try with canReadline() and then readLine()
Should be easier ...wrote on 6 Jun 2023, 17:47 last edited byThanks to all
Now I have found temporary descision based on insertPlainText of QTextEdit Class