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. serial communication
Qt 6.11 is out! See what's new in the release blog

serial communication

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 6 Posters 3.3k 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
    Rameshguru
    wrote on last edited by
    #1

    i want to send data in serial i write code like
    QString cmd=ui->lineEdit->text();
    QByteArray value=cmd.toUtf8();
    qDebug()<<"vlaue arrary"<<value;
    serial->write(value);

    receiver side:
    QByteArray str;
    str.append(serial->readAll());
    qDebug()<<"second string"<<str;

    In receiver side the value is splited like "WELCOME" splited to W ELCOME
    why the string is splited

    mrjjM 1 Reply Last reply
    0
    • R Rameshguru

      i want to send data in serial i write code like
      QString cmd=ui->lineEdit->text();
      QByteArray value=cmd.toUtf8();
      qDebug()<<"vlaue arrary"<<value;
      serial->write(value);

      receiver side:
      QByteArray str;
      str.append(serial->readAll());
      qDebug()<<"second string"<<str;

      In receiver side the value is splited like "WELCOME" splited to W ELCOME
      why the string is splited

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Rameshguru

      The string is split as data comes in groups.
      This is normal, and its your job to put it back together again while reading.

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

        i want to click button one time only

        mrjjM 1 Reply Last reply
        0
        • R Rameshguru

          i want to click button one time only

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Rameshguru

          It has nothing to with clicking a button

          When Data signal comes
          you do
          QByteArray str; // this should live in class
          str.append(serial->readAll()); // append to buffer for each read

          when str.size() is big enough that you know all data have been read, you can then look at the data.

          There is NO WAY to make sure that it only takes 1 serial->readAll()
          to get all data.

          1 Reply Last reply
          3
          • T Offline
            T Offline
            thni-macio
            wrote on last edited by thni-macio
            #5

            Most common way would be defining a very simple protocol used to deliver your data via serial port.
            In your case, you may just add a <newline> to the data you want to transmit. On the receiver side, you can then wait for that <newline> (using the mechanism already mentioned) to identify the end of the transmission and that your received data is now complete.

            However this only works if your data itself does not contain a <newline>. In that case you will need to use another "marker" or define a more complex protocol.

            1 Reply Last reply
            1
            • sankarapandiyanS Offline
              sankarapandiyanS Offline
              sankarapandiyan
              wrote on last edited by
              #6

              Increase the Baud rate range to 115200 to avoid these type of spliting

              J.HilkJ 1 Reply Last reply
              0
              • sankarapandiyanS sankarapandiyan

                Increase the Baud rate range to 115200 to avoid these type of spliting

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

                @sankarapandiyan
                that's horrible advice, depending on how busy the OS is and how massive/long your datagram the response can still be split up


                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.

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

                  @sankarapandiyan
                  that's horrible advice, depending on how busy the OS is and how massive/long your datagram the response can still be split up

                  aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8
                  This post is deleted!
                  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