Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Is this serial port receive method correct (TextEdit+SerialPort) ?
Qt 6.11 is out! See what's new in the release blog

Is this serial port receive method correct (TextEdit+SerialPort) ?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
3 Posts 2 Posters 996 Views
  • 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.
  • H Offline
    H Offline
    Hiloshi
    wrote on last edited by
    #1

    Dear Sirs,

    I add a TextEdit to receive data from serial port, the receive slot is as below:

    QByteArray data = serial->readAll();
    ui->textEdit->insertPlainText(data.toHex());
    ui->textEdit->insertPlainText("\n");
    

    I send out "55AA33887799" <--In hex 6 bytes
    I expect to receive the same data then cursor will move to next new line.

    However, in my TextEdit, the received data looks like:

    55AA33887799      //row 1
    55AA338877        //row 2
    99                //row 3
    55AA3388          //row 4
    7799              //row 5
    55AA33887799      //row 6
    

    I did not miss any data, but "new line" happen at wrong position.
    Take above row2 and row3 as an example, I receive row2 and row3 at the same time,
    but it should not separate to two row, all 6 bytes should at row2.

    Could it possible I miss some configuration on TextEdit ?
    Or something wrong on serial receive method ?

    Any suggestions would be appreciate.

    J.HilkJ 1 Reply Last reply
    0
    • H Hiloshi

      Dear Sirs,

      I add a TextEdit to receive data from serial port, the receive slot is as below:

      QByteArray data = serial->readAll();
      ui->textEdit->insertPlainText(data.toHex());
      ui->textEdit->insertPlainText("\n");
      

      I send out "55AA33887799" <--In hex 6 bytes
      I expect to receive the same data then cursor will move to next new line.

      However, in my TextEdit, the received data looks like:

      55AA33887799      //row 1
      55AA338877        //row 2
      99                //row 3
      55AA3388          //row 4
      7799              //row 5
      55AA33887799      //row 6
      

      I did not miss any data, but "new line" happen at wrong position.
      Take above row2 and row3 as an example, I receive row2 and row3 at the same time,
      but it should not separate to two row, all 6 bytes should at row2.

      Could it possible I miss some configuration on TextEdit ?
      Or something wrong on serial receive method ?

      Any suggestions would be appreciate.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Hiloshi
      that is normal behaviour. The ReadyRead signal is emited when new data is available at the serial port. But it checks this only 1 ever eventloop. So you might get a readyRead Signal but you do not yet have all the Data at your port.

      Depending on the protocol you use, one of your first bytes should be an identifier for the expected length of the telegram.

      if available data size < length identifier -> wait for next readyread Signal.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      H 1 Reply Last reply
      3
      • J.HilkJ J.Hilk

        @Hiloshi
        that is normal behaviour. The ReadyRead signal is emited when new data is available at the serial port. But it checks this only 1 ever eventloop. So you might get a readyRead Signal but you do not yet have all the Data at your port.

        Depending on the protocol you use, one of your first bytes should be an identifier for the expected length of the telegram.

        if available data size < length identifier -> wait for next readyread Signal.

        H Offline
        H Offline
        Hiloshi
        wrote on last edited by
        #3

        Dear @J.Hilk ,

        Understood. I will check number of bytes then determine if I should display it on the TextEdit or not.

        Thank you very much.

        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