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. Receiving garbage data from serial port

Receiving garbage data from serial port

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 3.1k 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.
  • S Offline
    S Offline
    samsam
    wrote on last edited by
    #1

    I'm using serial port class for transferring data from machine to machine. Before I open the port I define the following settings:

    @Port = new QSerialPort(this);
    Port ->setPortName("COM16");
    Port ->setBaudRate(QSerialPort::Baud115200);
    Port ->setDataBits(QSerialPort::Data8);
    Port ->setParity(QSerialPort::NoParity);
    Port ->setFlowControl(QSerialPort::NoFlowControl);
    Port ->setStopBits(QSerialPort::OneStop);
    Port ->clear();@
    My problem is, that sometimes when I run my app I get from the Serial port garbage data, the issue gets fixed when I open ExtraPutty tool (http://www.extraputty.com/download.php) on the same port- I get their the correct data and afterwards when I open my application everything is OK and I receive normal data. Probably the ExtraPutty defines some setting that I missed and the settings stays when I open the port from my application. can some one help me figure out what is the issue?

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

      Hi,

      You didn't open the serial port before doing the rest

      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
      • S Offline
        S Offline
        samsam
        wrote on last edited by
        #3

        well, I didn't write here the line that I'm opening the port, I open the port after setting these above details.
        for the case it makes sense I'm adding here the code that opens the port:

        @Port->open(QIODevice:: ReadWrite);
        if ((Port->isOpen()))
        {
        Port->clear();

            connect(Port, SIGNAL(readyRead()), this,SLOT(DataReceived()));
           
        }
        else
        {
            QMessageBox::critical(this, tr("Error"), Port->errorString());
        }@
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You have to open it before setting anything

          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
          • K Offline
            K Offline
            kuzulis
            Qt Champions 2020
            wrote on last edited by
            #5

            Also, you should to check the return from the all setXX() methods.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              samsam
              wrote on last edited by
              #6

              I checked the return. the return is false and the last error message is: "the handle is invalid"

              what does it mean, and what should I do in order to fix it?

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kuzulis
                Qt Champions 2020
                wrote on last edited by
                #7

                bq. what does it mean,

                It means that the device isn't opened.

                bq. and what should I do in order to fix it?

                For the old Qt versions (is lower than 5.3.1) it is necessary: at first - try to open device, and second - try to do setXX() methods (but not vice versa!!!).

                Now (for the Qt 5.3.1 and above) in it there is no need: it is possible to do setXX() before device opening.

                But anyway it is necessary always to do check of return codes.

                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