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. [SOLVED]Serial port not sending bytes in my application
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Serial port not sending bytes in my application

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 12.6k Views 1 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.
  • J Offline
    J Offline
    JustGreg
    wrote on last edited by
    #3

    [quote author="toptan" date="1363098990"]You probably need to read docs for your LCD more thoroughly. I doubt that sending single letter via serial will cause the display to display that letter.[/quote]

    The external device is working correctly. Trust me, I'm not sending single letters to an OLED display :-)

    1 Reply Last reply
    0
    • T Offline
      T Offline
      toptan
      wrote on last edited by
      #4

      Have you checked whether putChar returns true. After all it is QIODevice of some king. Also you could try write and waitForBytesWritten combo. Something like this:
      @
      QByteArray data("W");
      serial.write(data);
      if (!serial.waitForBytesWritten(waitTimeout)) {
      /* timeout handling */
      }
      @

      I am using array of six 7 segment led displays in my project and QSerialPort works no problem on linux.

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

        2 JustGreg

        Remove serial->close() in end of MainWindow constructor.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JustGreg
          wrote on last edited by
          #6

          [quote author="kuzulis" date="1363101362"]2 JustGreg

          Remove serial->close() in end of MainWindow constructor.[/quote]

          Thank you kuzulis. That was the problem, however my app is still not sending the bytes when I'm stepping over the code in debug mode. Only in 'Run' mode. Do you know what can cause this behaviour? It'd be nice to know.

          @toptan: the putChar method returned true, even in debug mode where there were no bytes sent to my device...strange. Thank you for your help, anyway.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            toptan
            wrote on last edited by
            #7

            No problem. I also have the problem in debug mode. I overcame that with a lot of qDebug(), if you find solution for step-by-step debugging please share.

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

              bq. That was the problem, however my app is still not sending the bytes when I’m stepping over the code in debug mode. Only in ‘Run’ mode. Do you know what can cause this behaviour? It’d be nice to know.

              Because all I/O operations processing asynchronously in Qt event-loop, so in debug step-by-step event-loop is stopped by step-by-step. :)

              So, nothing strange in this...

              UPD:
              Also, port->write() always returns true, because it write data to internal ring buffer.
              So, for catch errors you can connect to SerialPortError signal.

              1 Reply Last reply
              0
              • J Offline
                J Offline
                JustGreg
                wrote on last edited by
                #9

                [quote author="toptan" date="1363102507"]No problem. I also have the problem in debug mode. I overcame that with a lot of qDebug(), if you find solution for step-by-step debugging please share.[/quote]

                Right, I'll check qDebug then. I'm new to Qt & Linux so do not expect too much brainpower from me :-)

                [quote author="kuzulis" date="1363102625"]
                Because all I/O operations processing asynchronously in Qt event-loop, so in debug step-by-step event-loop is stopped by step-by-step. :)

                So, nothing strange in this...[/quote]

                Good to know. Thank you and I'll be back soon with my receive event signal-slot questions :-)

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  JustGreg
                  wrote on last edited by
                  #10

                  [quote author="kuzulis" date="1363101362"]2 JustGreg

                  Remove serial->close() in end of MainWindow constructor.[/quote]

                  One more question: what could cause the putChar process to fail? The close method was too fast and it had already closed the port before the internal buffer was emptied?

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

                    Yes. At the moment to the call close() does not force flush data.

                    So, you can do port->flush() before port->close()

                    UPD: On future maybe behavior can change... and flush() will called automatically on close().

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      JustGreg
                      wrote on last edited by
                      #12

                      Ok and thanks!

                      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