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. QSerialPort is(n't) sending data to ESP8266
Forum Updated to NodeBB v4.3 + New Features

QSerialPort is(n't) sending data to ESP8266

Scheduled Pinned Locked Moved Solved General and Desktop
qserialportesp8266
6 Posts 3 Posters 927 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.
  • G Offline
    G Offline
    Gh0stShell
    wrote on 15 Sept 2020, 09:00 last edited by Gh0stShell
    #1

    Hi,

    this is my first time I work with QSerialPort and I try to send data to an ESP8266. I tried the tool "Serial Port Monitor" to make a test message to the ESP and the connection is working so the problem shouldn't be on the ESP's side.

    QSerialPort serialo;
    
            Q_FOREACH(QSerialPortInfo port, QSerialPortInfo::availablePorts()) {
    
                if (port.description().compare("Silicon Labs CP210x USB to UART Bridge") == 0) {
                    serialo.setPort(port);
                    qDebug() << serialo.portName();
                    serialo.setBaudRate(QSerialPort::Baud9600);
                    serialo.setDataBits(QSerialPort::Data8);
                    serialo.setParity(QSerialPort::NoParity);
                    serialo.setStopBits(QSerialPort::OneStop);
                    serialo.setFlowControl(QSerialPort::NoFlowControl);
                    qDebug() << "PortOpen: " << serialo.open(QIODevice::ReadWrite);
                    qDebug() << "BytesSend: " << serialo.write("test");
    
                    serialo.close();
    
                }
            }
    

    I wrote this. Qt can open the port and it sends 4 Bytes, but the ESP isn't getting anything.

    Am I doing something completely wrong over there? Or is it something like a known issue or something?

    Edit: The ESP is connected via USB

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on 15 Sept 2020, 09:15 last edited by kuzulis
      #2

      You close the serial port before that the write starts. QSP::write() does not write the data immediatelly, it starts writing when the QSP becomes ready to write, internally.

      1 Reply Last reply
      4
      • G Offline
        G Offline
        Gh0stShell
        wrote on 15 Sept 2020, 09:18 last edited by
        #3

        Oh, ok. Is there a function to wait for writing is done?

        J 1 Reply Last reply 15 Sept 2020, 09:21
        0
        • G Gh0stShell
          15 Sept 2020, 09:18

          Oh, ok. Is there a function to wait for writing is done?

          J Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 15 Sept 2020, 09:21 last edited by
          #4

          @Gh0stShell said in QSerialPort is(n't) sending data to ESP8266:

          Oh, ok. Is there a function to wait for writing is done?

          yes, but rather use the BytesWritten signal.


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          3
          • K Offline
            K Offline
            kuzulis
            Qt Champions 2020
            wrote on 15 Sept 2020, 09:24 last edited by kuzulis
            #5

            @Gh0stShell said in QSerialPort is(n't) sending data to ESP8266:

            Oh, ok. Is there a function to wait for writing is done?

            Yes, you can use QSP::waitForBytesWritten(), but it is a very bad design. You should create your serial port instance on a heap and to use the signals/slots instead, as @J-Hilk suggested.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              Gh0stShell
              wrote on 15 Sept 2020, 10:34 last edited by
              #6

              Thank you, the problem was, that I didn't wait for the Bytes to be written.

              1 Reply Last reply
              0

              4/6

              15 Sept 2020, 09:21

              • Login

              • Login or register to search.
              4 out of 6
              • First post
                4/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved