Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QSerialPort problem for sending data
Forum Updated to NodeBB v4.3 + New Features

QSerialPort problem for sending data

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 2 Posters 710 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.
  • JonathanCJ Offline
    JonathanCJ Offline
    JonathanC
    wrote on last edited by
    #1

    Hello,

    I have a problem for sending data through serial port, my code is working well except if I add a sleep() after sending the data. bytesWritten() return 1 but the byte is not sent (I check with my scope).
    Here is my code :

        connect(m_port, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64)));
        while(1)
        {
            char startByte = 0x7f;
            m_port->putChar(startByte);
            m_port->waitForBytesWritten(-1);        
            sleep(1);         /* code is working if I comment this line */
        }
    

    What I am doing wrong ?
    Thanks for your help.

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

      Hi,

      You have a infinite loop that is blocking Qt's event loop thus Qt can't process anything.

      If you want to use your serial port in an infinite loop, you have to move that code in it's own thread.

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

        Hi,
        Thank you for your answer.
        That code is already in a thread.
        Maybe it's hardware problem with my board because I just realized that this code is working with 9600baud and not with 115200 ...

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

          Are you configuring the serial port correctly ?
          Does your device have any limitation ?

          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