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.
  • H Offline
    H Offline
    huythy
    wrote on 2 Dec 2016, 08:59 last edited by A Former User 12 Feb 2016, 17:24
    #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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 2 Dec 2016, 09:04 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
      • H Offline
        H Offline
        huythy
        wrote on 2 Dec 2016, 10:42 last edited by huythy 12 Feb 2016, 10:42
        #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
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 2 Dec 2016, 11:12 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
          • H Offline
            H Offline
            huythy
            wrote on 2 Dec 2016, 11:42 last edited by huythy 12 Feb 2016, 11:44
            #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
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 2 Dec 2016, 11:55 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
              • H Offline
                H Offline
                huythy
                wrote on 2 Dec 2016, 12:30 last edited by
                #7

                thanks for your help , my problem is solved

                M 1 Reply Last reply 2 Dec 2016, 12:53
                1
                • H huythy
                  2 Dec 2016, 12:30

                  thanks for your help , my problem is solved

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 2 Dec 2016, 12:53 last edited by
                  #8

                  @huythy
                  Super :) Please mark as Solved.

                  1 Reply Last reply
                  0

                  4/8

                  2 Dec 2016, 11:12

                  • Login

                  • Login or register to search.
                  4 out of 8
                  • First post
                    4/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved