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 and receiving data from/to PC/Arduino through serial port using QT
Forum Updated to NodeBB v4.3 + New Features

Sending and receiving data from/to PC/Arduino through serial port using QT

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 5 Posters 1.8k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #4
    serialPort->write("0");
    

    Did you already read about signals and slots in Qt ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    D 1 Reply Last reply
    0
    • SGaistS SGaist
      serialPort->write("0");
      

      Did you already read about signals and slots in Qt ?

      D Offline
      D Offline
      DanAm
      wrote on last edited by
      #5

      @SGaist This line is what i am doing now for turning on an LED on Arduino. but I want to send an array contains 8 bytes ( command of 5 bytes, int (2 bytes), status(2 bytes) ) which is 8 bytes data array. I have the corresponding Arduino code that receives the same data frame in PC as was sent to Arduino. Many thanks in advance for any help.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DanAm
        wrote on last edited by
        #6

        Nobody helps? I need to write 8 bytes data in Arduino and receive the same data sent in PC, I need to read the serial and convert it to the float and print it. I would be grateful if anybody can help me.

        jsulmJ SGaistS 2 Replies Last reply
        0
        • D DanAm

          Nobody helps? I need to write 8 bytes data in Arduino and receive the same data sent in PC, I need to read the serial and convert it to the float and print it. I would be grateful if anybody can help me.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #7

          @DanAm Did you take a look at example applications: https://doc.qt.io/qt-5/qtserialport-examples.html ?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • D DanAm

            Nobody helps? I need to write 8 bytes data in Arduino and receive the same data sent in PC, I need to read the serial and convert it to the float and print it. I would be grateful if anybody can help me.

            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #8

            @DanAm said in Sending and receiving data from/to PC/Arduino through serial port using QT:

            Nobody helps? I need to write 8 bytes data in Arduino and receive the same data sent in PC, I need to read the serial and convert it to the float and print it. I would be grateful if anybody can help me.

            Please have some patience and let at least 24 hours before bumping your own thread. This is a voluntary driven forum and people might not even live in the same timezone as you.

            As @jsulm suggested there are several examples in Qt's documentation to get you started with bi-directionnal serial communication.

            As for the array you want to send:

            @DanAm said in Sending and receiving data from/to PC/Arduino through serial port using QT:

            I want to send an array contains 8 bytes ( command of 5 bytes, int (2 bytes), status(2 bytes) ) which is 8 bytes data array.

            That makes it 9 bytes. Also, an int is not 2 bytes, that's rather a short. So what exactly do you want to send ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            D 1 Reply Last reply
            1
            • SGaistS SGaist

              @DanAm said in Sending and receiving data from/to PC/Arduino through serial port using QT:

              Nobody helps? I need to write 8 bytes data in Arduino and receive the same data sent in PC, I need to read the serial and convert it to the float and print it. I would be grateful if anybody can help me.

              Please have some patience and let at least 24 hours before bumping your own thread. This is a voluntary driven forum and people might not even live in the same timezone as you.

              As @jsulm suggested there are several examples in Qt's documentation to get you started with bi-directionnal serial communication.

              As for the array you want to send:

              @DanAm said in Sending and receiving data from/to PC/Arduino through serial port using QT:

              I want to send an array contains 8 bytes ( command of 5 bytes, int (2 bytes), status(2 bytes) ) which is 8 bytes data array.

              That makes it 9 bytes. Also, an int is not 2 bytes, that's rather a short. So what exactly do you want to send ?

              D Offline
              D Offline
              DanAm
              wrote on last edited by
              #9

              @SGaist Yes you are right.

              My mistake, I want to send a command of 4 bytes and status of 2 bytes and a counter that has 2 bytes. It makes 8 bytes that I want to send and receive. And also I want to convert the received command to float in QT and display it. Can I use this way :

              QByteArray command ;
              command.resize(4);
              command[0]=0x41;
              command[1]=0xf8;
              command[2]=0xf6;
              command[3]=0x00;

              float value;
              QDataStream stream(command);
              stream >> value;

              qDebug() << value;

              Thanks

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #10

                Why not use QByteArray::toFloat ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                D 1 Reply Last reply
                1
                • SGaistS SGaist

                  Why not use QByteArray::toFloat ?

                  D Offline
                  D Offline
                  DanAm
                  wrote on last edited by
                  #11

                  @SGaist thanks, i think the problem solved.

                  One general question : to send through serial port, do we need to stream the byte array (QByteArray type) using QDataStream or we can write the array in the port directly ?

                  Pablo J. RoginaP JonBJ 2 Replies Last reply
                  0
                  • D DanAm

                    @SGaist thanks, i think the problem solved.

                    One general question : to send through serial port, do we need to stream the byte array (QByteArray type) using QDataStream or we can write the array in the port directly ?

                    Pablo J. RoginaP Offline
                    Pablo J. RoginaP Offline
                    Pablo J. Rogina
                    wrote on last edited by
                    #12

                    @DanAm said in Sending and receiving data from/to PC/Arduino through serial port using QT:

                    the problem solved

                    so please don't forget to mark this post as such!

                    Upvote the answer(s) that helped you solve the issue
                    Use "Topic Tools" button to mark your post as Solved
                    Add screenshots via postimage.org
                    Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • D DanAm

                      @SGaist thanks, i think the problem solved.

                      One general question : to send through serial port, do we need to stream the byte array (QByteArray type) using QDataStream or we can write the array in the port directly ?

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

                      @DanAm said in Sending and receiving data from/to PC/Arduino through serial port using QT:

                      One general question : to send through serial port, do we need to stream the byte array (QByteArray type) using QDataStream or we can write the array in the port directly ?

                      Either, you do not have to use QDataStream.

                      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