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. QtSerialPort - device not open error [solved]

QtSerialPort - device not open error [solved]

Scheduled Pinned Locked Moved General and Desktop
14 Posts 2 Posters 17.9k Views
  • 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

    You can use a buffer and append the data using readAll(). Then parse the result, if it contains all that is needed, then update your label. That's the normal way of processing data from the serial port.

    As for why it suddenly work just adding the if… Good question...

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

    1 Reply Last reply
    0
    • U Offline
      U Offline
      uzz3
      wrote on last edited by
      #5

      Hello again, ok i tried your sugestion but i'm not able to implement it. If you wish, can you show me an example or just tell me where to look, because google is not helping me.
      Sorry for being a beginner, but i'm doing my best to learn as much as i can in my little free time, and asking for help instead of trying to discover everything by myself is more efficient.
      Thanks a lot for your help.

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

        You have a lot of QtSerialPort examples "
        here":http://qt-project.org/doc/qt-5/examples.html

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

        1 Reply Last reply
        0
        • U Offline
          U Offline
          uzz3
          wrote on last edited by
          #7

          Hi, i managed to get correct readings from serial port. Now i'm not sure how to go further with my project. What i need to do is read data from different senzors and display the data that i receive from serial port in different labels.

          For example i have a temperature senzor which sends data through serial from 10 to 10 seconds. And a humidity senzor which sends data from 20 to 20 seconds.

          And the question is how can i display the data that i receive from temperature senzor in a label, and the data that i receive from humidity senzor in another label.

          Thanks for your help and support.

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

            What do your sensors send ? Only value ? An identifier and the value ? A unit with it ?

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

            1 Reply Last reply
            0
            • U Offline
              U Offline
              uzz3
              wrote on last edited by
              #9

              Well the sensors are sending only the value. For example the temperature sensor will send an int value like: 24;
              And the humidity will send the same like: 60;

              But if it helps i can insert a string among with that value like: "Temperature in Celsius: 24";"Humidity sensor: 60 %"; (right now this is how i'm sending data through serial)

              Also if it helps i can assign an int id to a sensor so the output will be like:
              1 24; //where 1 is id of temp sens;
              2 60; // 2 - id of humidity sens;

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

                So to my understanding, you control what the sensors send ? Then it's up to you to define the protocol. You should have something like a starting value that you know will be the beginning of a message then the content of it and an end value that tells you the message is over. This way you will be able to parse your communication protocol more easily even if your sensors send their value at different rate.

                If you can have several sensors with similar outputs your should consider having an id, a type identifier and a unit.

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

                1 Reply Last reply
                0
                • U Offline
                  U Offline
                  uzz3
                  wrote on last edited by
                  #11

                  Lets say that i have this data sending through serial:

                  "Temperature: 24"
                  "Humidity: 60"
                  So i can make something like... after doing serial-readAll(), if in the string that stores the serial data, i have "Temperature: " then ui->labelA-setText();
                  else if i have "Humidity:" then ui->labelB->setText();

                  Hope this makes sense;

                  Thanks a lot for your support. You are really helping me.

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

                    Beware that you might not get all the text at once when readyRead is called. So you should have a buffer where you put the result of readAll() then parse the buffer to see if you have a complete sensor data then remove it from the buffer and send it to your label.

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

                    1 Reply Last reply
                    0
                    • U Offline
                      U Offline
                      uzz3
                      wrote on last edited by
                      #13

                      Hello,
                      I want to thank you for helping me and for guiding me in my project. I managed to finish what i had to do, and it works great.

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

                        You're welcome !

                        Good to know :)

                        Since all is working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

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

                        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