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. [solved] error in reading values from uart
Forum Updated to NodeBB v4.3 + New Features

[solved] error in reading values from uart

Scheduled Pinned Locked Moved Mobile and Embedded
9 Posts 3 Posters 4.9k 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.
  • S Offline
    S Offline
    shajeen
    wrote on last edited by
    #1

    I got a hardware which send data about 300 single data per second. I developed GUI application on Qt , use Qextserialport. problem is when i read data from serial port it display in AScii value. i tried to conver to Hex, but the value are wrong. I need Value in Binary , for further process....
    @
    this->rs232_ = new QextSerialPort();
    this->rs232_->setPortName("/dev/ttyS0");
    this->rs232_->setBaudRate(BAUD4800);
    this->rs232_->setFlowControl(FLOW_OFF);
    this->rs232_->setParity(PAR_ODD);
    this->rs232_->setDataBits(DATA_8);
    this->rs232_->setStopBits(STOP_1);
    this->rs232_->open(QIODevice::ReadWrite);

    if (!this->rs232_->isOpen()) {
        qDebug()<<"....Port ttyS0 CanNot Open...."<<endl;
          this->rs232_->flush();
          this->rs232_->close();
               }
    connect(rs232_, SIGNAL(readyRead()), this, SLOT(onDataAvailable()));
    

    void MainWindow::onDataAvailable()
    {
    QByteArray data = rs232_->readAll();
    qDebug()<<data<<data.toHex();
    QByteArray process = data.toHex();
    }@

    output I Got:
    @
    "�""�"" "06"
    ""�" "dc"
    "�" "ec"
    "�" "ff"
    "�" "80"
    "�"" "06"
    ""�" "dc"
    "t���"�" "f9"
    "�" "80"
    "�"" "06"
    ""�" "dc"
    "l" "6c"
    "�" "f3"
    "�" "80"
    "�"" "06"
    ""�" "dc"
    "$" "24"
    "�" "f1"
    @

    Shajeen Ahamed

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

      Hi shajeen.
      Welcome to DevNet.
      Do you want display incoming data as binary, like:
      06 - > "00000110"
      or you mean some thing else?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shajeen
        wrote on last edited by
        #3

        yes i need in binary --- "00000110"

        Thank you qxoz for replay

        Shajeen Ahamed

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #4

          Ok if you want string display of binary data use
          @QString::number(value, 2);@
          look at "doc":https://qt-project.org/doc/qt-4.8/qstring.html#number

          1 Reply Last reply
          0
          • S Offline
            S Offline
            shajeen
            wrote on last edited by
            #5

            i Tried to display ,but values become zero

            @QString data = rs232_->read(rs232_->bytesAvailable());

            QString str = data;
            bool ok;
            int binary = str.toInt(&ok, 2);
            int dec = str.toInt(&ok, 10);
            qDebug()<<binary<<dec;@

            Output:
            0 3
            0 0
            0 0
            0 0
            0 0
            0 0
            0 0
            0 9
            0 0
            0 0
            0 0
            0 0
            0 0

            Shajeen Ahamed

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qxoz
              wrote on last edited by
              #6

              i don't know what are you trying to do, but if i understand you, here the solution:
              @void MainWindow::onDataAvailable()
              {
              QByteArray data = rs232_->readAll();
              foreach (char tch, data) {
              qDebug()<<QString::number((quint8)tch, 10)<< QString::number((quint8)tch, 2);
              }
              }@

              1 Reply Last reply
              0
              • S Offline
                S Offline
                shajeen
                wrote on last edited by
                #7

                Thx qxoz it convert's......

                Shajeen Ahamed

                1 Reply Last reply
                0
                • Q Offline
                  Q Offline
                  qxoz
                  wrote on last edited by
                  #8

                  You 're welcome.
                  By the way if you want display all 8 bits
                  @QString tempZero;
                  QString tStr;
                  foreach (char tch, tArray) {
                  tempZero = "00000000";
                  tStr = QString::number((quint8)tch, 2);
                  tempZero.replace(8-tStr.length(), tStr.length(), tStr);
                  qDebug()<< tempZero;
                  }@

                  1 Reply Last reply
                  0
                  • Y Offline
                    Y Offline
                    yravi
                    wrote on last edited by
                    #9

                    Hi qxoz

                    I need your help..currently working on a embedded board(friendlyarm mini2440), with Xbee pro module.. using qext i am able to transmit the correct data to hyperterminal..

                    But from when i send from hyperterminal the data received at the board end is different..for example if press "9" then on receiving side its is showing as "y" ..same for all..may i know the solution for it..

                    my aim is to read entire data from xbee(zigbee module) and show on lcd..please help me..

                    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