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. i need buffer for serial communication
Forum Updated to NodeBB v4.3 + New Features

i need buffer for serial communication

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 272 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.
  • K Offline
    K Offline
    KARMA
    wrote on last edited by
    #1

    I get a total of 10 bytes of data starting with 0xAA.
    data sometimes comes in 2 parts.
    for instance;
    xAA,x00,x10,x00 -> 4byte
    x40,x00,x10,x00,x10,x00 -> 6byte

    When the data comes in 2 parts like this, I could not find a solution with buffer how to combine it.
    I don't know how to think as I've never used a buffer before

    jsulmJ 1 Reply Last reply
    0
    • K KARMA

      I get a total of 10 bytes of data starting with 0xAA.
      data sometimes comes in 2 parts.
      for instance;
      xAA,x00,x10,x00 -> 4byte
      x40,x00,x10,x00,x10,x00 -> 6byte

      When the data comes in 2 parts like this, I could not find a solution with buffer how to combine it.
      I don't know how to think as I've never used a buffer before

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @KARMA said in i need buffer for serial communication:

      I could not find a solution with buffer how to combine it

      Simply use a QByteArray member variable in your class and append incoming data to it until you got everything.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      5
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        Hi

        • I don't know how to think as I've never used a buffer before

        In your Mainwindow / where serialport lives, add in the .h / class

        QByteArray data; // the buffer

        then in the read slot

        void MainWindow::readData()
        {     
             data.append(m_serial->readAll( ) );
             if (data.size() == 10 ) {
              // do processing   
              data.clear();   
             }
        }
        
        
        1 Reply Last reply
        4

        • Login

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