Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. UART terminal
Forum Updated to NodeBB v4.3 + New Features

UART terminal

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 4 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Christian EhrlicherC Christian Ehrlicher

    @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.

    A Offline
    A Offline
    another_one
    wrote on last edited by
    #4

    @Christian-Ehrlicher

    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!

    Christian EhrlicherC 1 Reply Last reply
    0
    • A another_one

      @Christian-Ehrlicher

      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!

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #5

      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!

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      A 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        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!

        A Offline
        A Offline
        another_one
        wrote on last edited by
        #6

        @Christian-Ehrlicher
        Thank you!

        A 1 Reply Last reply
        0
        • A another_one

          @Christian-Ehrlicher
          Thank you!

          A Offline
          A Offline
          another_one
          wrote on last edited by
          #7

          @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

          JonBJ 1 Reply Last reply
          0
          • A another_one

            @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

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #8

            @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.

            A 1 Reply Last reply
            1
            • JonBJ JonB

              @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.

              A Offline
              A Offline
              another_one
              wrote on last edited by
              #9

              @JonB

              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

              JonBJ M 2 Replies Last reply
              0
              • A another_one

                @JonB

                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

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #10

                @another_one said in UART terminal:

                Pin # 3
                LED ON

                Take this as an example. We have explained that it can happen that device sends Pin #3 LED ON in a single write(). 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 to readAll(): first time it gets Pin # 3, second time it gets remaining LED 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 call append() 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 call append() when you have (one or more) full lines.

                A 1 Reply Last reply
                1
                • JonBJ JonB

                  @another_one said in UART terminal:

                  Pin # 3
                  LED ON

                  Take this as an example. We have explained that it can happen that device sends Pin #3 LED ON in a single write(). 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 to readAll(): first time it gets Pin # 3, second time it gets remaining LED 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 call append() 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 call append() when you have (one or more) full lines.

                  A Offline
                  A Offline
                  another_one
                  wrote on last edited by
                  #11

                  @JonB

                  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!

                  JonBJ 1 Reply Last reply
                  0
                  • A another_one

                    @JonB

                    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!

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #12

                    @another_one
                    Build up a line (however they are terminated, carriage return or whatever) before calling QTextEdit:: append(). I would keep a class member variable for a buffer and each time realAll() 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.

                    A 1 Reply Last reply
                    1
                    • JonBJ JonB

                      @another_one
                      Build up a line (however they are terminated, carriage return or whatever) before calling QTextEdit:: append(). I would keep a class member variable for a buffer and each time realAll() 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.

                      A Offline
                      A Offline
                      another_one
                      wrote on last edited by
                      #13

                      @JonB

                      Thank 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?

                      1 Reply Last reply
                      0
                      • A another_one

                        @JonB

                        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

                        M Offline
                        M Offline
                        mpergand
                        wrote on last edited by
                        #14

                        @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 ...

                        A 1 Reply Last reply
                        2
                        • M mpergand

                          @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 ...

                          A Offline
                          A Offline
                          another_one
                          wrote on last edited by
                          #15

                          @mpergand

                          Thanks to all
                          Now I have found temporary descision based on insertPlainText of QTextEdit Class

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved