Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Not able to pass 0x00 over Qserial port
Qt 6.12 LTS is out! See what's new in the release blog

Not able to pass 0x00 over Qserial port

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
26 Posts 4 Posters 6.5k 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.
  • R Ramarao

    @KroMignon after trying below code, i got "U" as first character and rest are like above.
    code_text

    QByteArray ba = QByteArray::fromRawData((char *)&omsg,sizeof(omsg));
    serial->write(ba.data(),ba.size());

    KroMignonK Offline
    KroMignonK Offline
    KroMignon
    wrote on last edited by
    #10

    @Ramarao said in Not able to pass 0x00 over Qserial port:

    after trying below code, i got "U" as first character and rest are like above.

    Which seems to be normal to me 0x55 is U is ASCII table.
    But where to you see this?
    You are only sending data with this code extract.

    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

    R 1 Reply Last reply
    0
    • KroMignonK KroMignon

      @Ramarao said in Not able to pass 0x00 over Qserial port:

      after trying below code, i got "U" as first character and rest are like above.

      Which seems to be normal to me 0x55 is U is ASCII table.
      But where to you see this?
      You are only sending data with this code extract.

      R Offline
      R Offline
      Ramarao
      wrote on last edited by
      #11

      @KroMignon i am sending this command to AM335x and observing the data in microcom or other QT receiving application running on board..Am335x_terminal.png

      KroMignonK 1 Reply Last reply
      0
      • R Ramarao

        @KroMignon i am sending this command to AM335x and observing the data in microcom or other QT receiving application running on board..Am335x_terminal.png

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by
        #12

        @Ramarao said in Not able to pass 0x00 over Qserial port:

        i am sending this command to AM335x and observing the data in microcom or other QT receiving application running on board..

        You should be aware that '\0' (NULL character) are not printable, so you cannot see it with microcom.
        You have to use an hexadecimal terminal, something like ssterm (https://github.com/vsergeev/ssterm)

        ssterm -o hex /dev/ttyXXX
        

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        1 Reply Last reply
        1
        • R Offline
          R Offline
          Ramarao
          wrote on last edited by Ramarao
          #13

          @KroMignon iam running QT receiving app also at board side to observe data.

          code_text
          QByteArray data = serial->readAll();
             QString str = QString(data);
             qDebug() << str;
          

          My doubt is serial->write() will not send 0's by treating it as null character if we send in any format.

          JonBJ KroMignonK 2 Replies Last reply
          0
          • R Ramarao

            @KroMignon iam running QT receiving app also at board side to observe data.

            code_text
            QByteArray data = serial->readAll();
               QString str = QString(data);
               qDebug() << str;
            

            My doubt is serial->write() will not send 0's by treating it as null character if we send in any format.

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

            @Ramarao
            I know you have ignored every post I have made, but I did tell you:

               QString str = QString(data);
               qDebug() << str;
            

            Using qDebug() like this is not the way to be able to see the data. Particularly 0x00s....

            And additionally did you read QString::QString(const QByteArray &ba):

            Constructs a string initialized with the byte array ba. The given byte array is converted to Unicode using fromUtf8(). Stops copying at the first 0 character, otherwise copies the entire byte array.

            [My bold.]

            R 1 Reply Last reply
            2
            • R Ramarao

              @KroMignon iam running QT receiving app also at board side to observe data.

              code_text
              QByteArray data = serial->readAll();
                 QString str = QString(data);
                 qDebug() << str;
              

              My doubt is serial->write() will not send 0's by treating it as null character if we send in any format.

              KroMignonK Offline
              KroMignonK Offline
              KroMignon
              wrote on last edited by KroMignon
              #15

              @Ramarao said in Not able to pass 0x00 over Qserial port:

              iam running QT receiving app also at board side to observe data.
              code_text
              QByteArray data = serial->readAll();
              QString str = QString(data);
              qDebug() << str;

              And this wrong, you want to see hexadecimal data:

              QByteArray data = serial->readAll();
              
              qDebug() << "Raw data:" << data;
              qDebug() << "Hex data:"<< data.toHex(':');
              
              

              My doubt is serial->write() will not send 0's by treating it as null character if we send in any format.

              QSerialPort::write(const char * buffer, int size) do not check null byte, what matter is size. You can send as many null bytes you want, there is no interpretation about buffer content.

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              1 Reply Last reply
              3
              • JonBJ JonB

                @Ramarao
                I know you have ignored every post I have made, but I did tell you:

                   QString str = QString(data);
                   qDebug() << str;
                

                Using qDebug() like this is not the way to be able to see the data. Particularly 0x00s....

                And additionally did you read QString::QString(const QByteArray &ba):

                Constructs a string initialized with the byte array ba. The given byte array is converted to Unicode using fromUtf8(). Stops copying at the first 0 character, otherwise copies the entire byte array.

                [My bold.]

                R Offline
                R Offline
                Ramarao
                wrote on last edited by
                #16

                @JonB sorry that as i am new guy, forum is not allowing me immediately(making me to wait 10 mins). I am new to QT and i am trying to send 16 bytes command to AM335x board from QT application(running in PC) with button press for time being.
                My goal is to send and receive data over serial communication between AM335x and STM32 where AM335x acting as GUI interface with QT application.

                JonBJ 1 Reply Last reply
                0
                • R Ramarao

                  @JonB sorry that as i am new guy, forum is not allowing me immediately(making me to wait 10 mins). I am new to QT and i am trying to send 16 bytes command to AM335x board from QT application(running in PC) with button press for time being.
                  My goal is to send and receive data over serial communication between AM335x and STM32 where AM335x acting as GUI interface with QT application.

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

                  @Ramarao
                  That's OK, welcome :)

                  If you read what @KroMignon & I have said between us you ought be good to go!

                  Truly there is no problem sending 0 bytes across serial. Your problems will be (a) if you ever convert a QByteArray to a QString, because it's liable to terminate at the 0, as I wrote earlier, and (b) if you're not careful about interpreting what you see from qDebug(), because it shows "odd" bytes in ways you might misinterpret. Using @KroMignon's QByteArray::toHex() at least is one way to visualise the bytes without having them "terminated early" or being shown "oddly".

                  1 Reply Last reply
                  1
                  • R Offline
                    R Offline
                    Ramarao
                    wrote on last edited by
                    #18

                    This issue is resolved.

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      manel.sam
                      wrote on last edited by
                      #19

                      This my open for opening IMU
                      Imu::Imu() :
                      moving(false)
                      {

                      serialPort = new QSerialPort("COM7",this);
                      if (!serialPort->open( QIODevice::ReadOnly))
                      {
                          log_warning("imu","failed to open device file \"%s\", IMU measures will be unavailable",qPrintable(serialPort->portName()));
                          return;
                      }
                      
                      if (!serialPort->setBaudRate(115200))
                          log_error("imu","failed to set baudrate, error no %d",serialPort->error());
                      serialPort->setDataBits(QSerialPort::Data8);
                      serialPort->setParity(QSerialPort::NoParity);
                      serialPort->setStopBits(QSerialPort::OneStop); // One Stop bit
                      serialPort->setFlowControl(QSerialPort::NoFlowControl);
                      //serialPort->open(QIODevice::ReadOnly);
                      
                      pollingTimer = new QTimer(this);
                      QObject::connect(pollingTimer, SIGNAL(timeout()), this, SLOT(pollSerialPort()));
                      pollingTimer->start(10);
                      
                      }
                      

                      Imu::~Imu()
                      {
                      serialPort->close();
                      }

                      void Imu::pollSerialPort()
                      {
                      static const unsigned char START_BYTES[2] = {0x55,0xAA};
                      static const QByteArray START_WORD((char*)START_BYTES,2);

                      static QTime startTime = QTime::currentTime();
                      
                      static QByteArray data;
                      data.append(serialPort->readAll());
                      qDebug() <<"Raw data"<<data.append(serialPort->readAll());
                      QByteArray hex = data.append(serialPort->readAll()).toHex('0');   // returns "123456abcdef"
                      qDebug() <<"Hex data"<<hex;
                      

                      I would like to get the data in hexadecimal, however I could not get anything

                      Neither in binary data, nor in hexadecimal

                      JonBJ 1 Reply Last reply
                      0
                      • M manel.sam

                        This my open for opening IMU
                        Imu::Imu() :
                        moving(false)
                        {

                        serialPort = new QSerialPort("COM7",this);
                        if (!serialPort->open( QIODevice::ReadOnly))
                        {
                            log_warning("imu","failed to open device file \"%s\", IMU measures will be unavailable",qPrintable(serialPort->portName()));
                            return;
                        }
                        
                        if (!serialPort->setBaudRate(115200))
                            log_error("imu","failed to set baudrate, error no %d",serialPort->error());
                        serialPort->setDataBits(QSerialPort::Data8);
                        serialPort->setParity(QSerialPort::NoParity);
                        serialPort->setStopBits(QSerialPort::OneStop); // One Stop bit
                        serialPort->setFlowControl(QSerialPort::NoFlowControl);
                        //serialPort->open(QIODevice::ReadOnly);
                        
                        pollingTimer = new QTimer(this);
                        QObject::connect(pollingTimer, SIGNAL(timeout()), this, SLOT(pollSerialPort()));
                        pollingTimer->start(10);
                        
                        }
                        

                        Imu::~Imu()
                        {
                        serialPort->close();
                        }

                        void Imu::pollSerialPort()
                        {
                        static const unsigned char START_BYTES[2] = {0x55,0xAA};
                        static const QByteArray START_WORD((char*)START_BYTES,2);

                        static QTime startTime = QTime::currentTime();
                        
                        static QByteArray data;
                        data.append(serialPort->readAll());
                        qDebug() <<"Raw data"<<data.append(serialPort->readAll());
                        QByteArray hex = data.append(serialPort->readAll()).toHex('0');   // returns "123456abcdef"
                        qDebug() <<"Hex data"<<hex;
                        

                        I would like to get the data in hexadecimal, however I could not get anything

                        Neither in binary data, nor in hexadecimal

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

                        @manel-sam
                        Hi. It might have been better to open your own topic for this than putting it in this existing thread. You could still do that.

                        You are calling serialPort->readAll() 3 times, including in a qDebug() statement. Each time you call it all the data is read, it will not be there for next read.

                        Wouldn't using readyRead() signal be better than your timed polling?

                        M 1 Reply Last reply
                        1
                        • JonBJ JonB

                          @manel-sam
                          Hi. It might have been better to open your own topic for this than putting it in this existing thread. You could still do that.

                          You are calling serialPort->readAll() 3 times, including in a qDebug() statement. Each time you call it all the data is read, it will not be there for next read.

                          Wouldn't using readyRead() signal be better than your timed polling?

                          M Offline
                          M Offline
                          manel.sam
                          wrote on last edited by
                          #21

                          @JonB Thank you for your feedback, I am new to this forum and QT too, I will do so indeed

                          Thanks

                          Can you tell me then how I can read the data without using the qDebug(), to be able to visualize if I receive the data well

                          and how to get the data in Hexadecimal

                          JonBJ 1 Reply Last reply
                          0
                          • M manel.sam

                            @JonB Thank you for your feedback, I am new to this forum and QT too, I will do so indeed

                            Thanks

                            Can you tell me then how I can read the data without using the qDebug(), to be able to visualize if I receive the data well

                            and how to get the data in Hexadecimal

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

                            @manel-sam

                            QByteArray ba = serialPort->readAll();
                            qDebug() << ba.count() << ba.toHex()
                            
                            M 1 Reply Last reply
                            1
                            • JonBJ JonB

                              @manel-sam

                              QByteArray ba = serialPort->readAll();
                              qDebug() << ba.count() << ba.toHex()
                              
                              M Offline
                              M Offline
                              manel.sam
                              wrote on last edited by
                              #23

                              @JonB
                              Thanks a lot,

                              I receive only the value 0, whereas the Imu I use receives the values in Hexadecimal.
                              Is it necessary to write other commands?

                              JonBJ 1 Reply Last reply
                              0
                              • M manel.sam

                                @JonB
                                Thanks a lot,

                                I receive only the value 0, whereas the Imu I use receives the values in Hexadecimal.
                                Is it necessary to write other commands?

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

                                @manel-sam said in Not able to pass 0x00 over Qserial port:

                                whereas the Imu I use receives the values in Hexadecimal.

                                No, it does not. Forget about hexadecimal. You are receiving 0 bytes.

                                M 1 Reply Last reply
                                0
                                • JonBJ JonB

                                  @manel-sam said in Not able to pass 0x00 over Qserial port:

                                  whereas the Imu I use receives the values in Hexadecimal.

                                  No, it does not. Forget about hexadecimal. You are receiving 0 bytes.

                                  M Offline
                                  M Offline
                                  manel.sam
                                  wrote on last edited by
                                  #25

                                  @JonB Can you please devellope more, because I did not understand well

                                  sorry

                                  JonBJ 1 Reply Last reply
                                  0
                                  • M manel.sam

                                    @JonB Can you please devellope more, because I did not understand well

                                    sorry

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

                                    @manel-sam
                                    What can I say? You are not receiving any bytes from the serial port!!! You printed out ba.count() and it was 0. You really should be able to understand this.....

                                    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
                                    • Unsolved