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. Read byte by byte from serial
Forum Updated to NodeBB v4.3 + New Features

Read byte by byte from serial

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 10.1k 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.
  • R Offline
    R Offline
    regen
    wrote on last edited by
    #1

    hello everyone, i'm newbie in qt. i have 5 byte data from serial device and i wanna display the data byte by byte, anyone have sample code? i'm really really newbie in qt.. thanks before

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      Have a look at the "QSerialPort documentation":http://qt-project.org/doc/qt-5.1/qtserialport/qserialport.html

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • R Offline
        R Offline
        regen
        wrote on last edited by
        #3

        thank You JKSH for your reply.. but i use qextserialport in qt, my data in hex, 5 byte and i want to display data by byte, for example: lable1.setText(byte1), lable2.setText(byte2) and others. now i only can diplay all data in one lable and in string. my device send "0x55" but in qt i get "U". how to get 0x55 in qt?

        i'm sorry if my english is poor

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          U is the char corresponding to 0x55. If you want 0x55 literally you can use QByteArray::toHex()

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • R Offline
            R Offline
            regen
            wrote on last edited by
            #5

            i try to use QByteArray::toHex() bute still doesnt work, and other case ia want to display one byte data to one label, in visual C i can use label.text = serialport.ReadByte().. how to use it in qt?

            thank you

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              Hi,

              Usually you need to describe what you mean by "it doesn't work". Otherwise, people won't know what your problem is.

              @
              QByteArray ba = serialPort.readAll(); // Get the 0x55 byte

              label.setText(ba.toHex()); // Label shows "55"
              label.setText("0x" + ba.toHex()); // Label shows "0x55"
              @

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • R Offline
                R Offline
                regen
                wrote on last edited by
                #7

                thank You JKSH, i successfully to display data in 55.. but i have other problems, my data from arduino is 5 byte like this: Serial.write(0x55,0x50,0x17,0x16,0x150);
                how to display one byte in one label?

                1 Reply Last reply
                0
                • JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

                  You're welcome. :)

                  [quote]0×55,0×50,0×17,0×16,0×150[/quote]Is that a typo? 0x150 == 0b 0000 0001 0101 0000, which occupies 2 bytes. I'll assume your last byte is 0x15.

                  Anyway, when you convert your 5-byte array to hex, you will have a 10-character string, "5550171615". You'll then have to extract two characters at a time.

                  See "QByteArray::mid()":http://qt-project.org/doc/qt-5.1/qtcore/qbytearray.html#mid or "QString::mid()":http://qt-project.org/doc/qt-5.1/qtcore/qstring.html#mid

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    regen
                    wrote on last edited by
                    #9

                    thank you guys for your reply.. i sned the data repeatedly from arduino without delay so when i use this code
                    @void MainWindow::serialRecived(){
                    QByteArray ba(port->readAll());
                    QString s = ba.toHex();
                    ui->label->setText(s);
                    }@

                    the label display all byte repeatedly. i want to display each byte in one label so i can monitor any change in each byte.. can you give me an idea? thanks a lot before guys

                    1 Reply Last reply
                    0
                    • JKSHJ Offline
                      JKSHJ Offline
                      JKSH
                      Moderators
                      wrote on last edited by
                      #10

                      Like I said, see "QByteArray::mid()":http://qt-project.org/doc/qt-5.1/qtcore/qbytearray.html#mid or "QString::mid()":http://qt-project.org/doc/qt-5.1/qtcore/qstring.html#mid

                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                      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