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. Sending 2 string through serial port
Forum Updated to NodeBB v4.3 + New Features

Sending 2 string through serial port

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 2.0k Views 2 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.
  • huythyH Offline
    huythyH Offline
    huythy
    wrote on last edited by A Former User
    #1

    Hi, pros
    I'm new with Qt. My problem is i don't know how to send multiple strings to serial port like :
    QString data = "x" + "50" + " 60" ;
    Does anyone who knows the answer, please ?

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

      Hi
      I would take
      http://doc.qt.io/qt-5/qtserialport-terminal-example.html

      It can both send and read.

      To send the data its simply
      serial->write(data);

      1 Reply Last reply
      4
      • huythyH Offline
        huythyH Offline
        huythy
        wrote on last edited by huythy
        #3

        Yes, i read it but it can't get a right result, because i send a long string to arduino through serial. A string and convert to ascii
        Here's my code :
        int value_a=0, value_b=0;
        QString a = ui->lineEdit_1->text();
        QString b=ui->lineEdit_2->text();
        for (int i = 0; i< a.length(); i++)
        {
        value_a = a.at(i).toLatin1();
        }
        for (int j = 0; j < b.length(); j++)
        {
        value_b = b.at(j).toLatin1();
        }
        QString data = "x" + value_a + value_b;
        QByteArray buffer = data.toLatin1();
        serial->write(buffer);

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

          Hi
          I assume you check that data contains what you expect.
          You must explain what the issue is?

          • get a right result

          What is right result?
          Is it on the arduino side?
          Are you using ReadAll() ?

          1 Reply Last reply
          2
          • huythyH Offline
            huythyH Offline
            huythy
            wrote on last edited by huythy
            #5

            well, i will send "x" + "50" to serial , and in arduino will convert it , "x" is a character for starting and "50" is for data.
            example : result = (data[0] - 48)*100 + (data[1]-48)*10 + data[2]-48 - this is on arduino side.
            The right result is 50 will be displayed oon LCD, i've checked on visual studio , everything on arduino is ok.
            I'm not using ReadAll()

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

              well U can test with the Terminal sample.
              Try send from one to other and see what you get.

              1 Reply Last reply
              3
              • huythyH Offline
                huythyH Offline
                huythy
                wrote on last edited by
                #7

                thanks for your help , my problem is solved

                mrjjM 1 Reply Last reply
                1
                • huythyH huythy

                  thanks for your help , my problem is solved

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

                  @huythy
                  Super :) Please mark as Solved.

                  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