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. How to send and receive in the sametime
Forum Updated to NodeBB v4.3 + New Features

How to send and receive in the sametime

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 438 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.
  • V Offline
    V Offline
    victor wang
    wrote on last edited by
    #1

    Hi, I'm using QT5.5 on my computer.
    I wanna write a program that will do send and receive in the same place and time.
    This is my code.

    QSerialPort comport;
        QString comportstring="/dev/ttyXRUSB0";
        comport.setPortName(comportstring);
        comport.setBaudRate(115200);
    
        if (!comport.open(QIODevice::WriteOnly)) {
            qDebug()<<comport.errorString();
        }
        QByteArray writeData="HELLO WORLD!";
        qDebug("here am i ")
        if (writeData.isEmpty()) {
     qDebug()<<"Either no data was currently available on the standard input ff
    or reading, or an error occurred for port";
        }
    
        qint64 bytesWritten = comport.write(writeData);
    
        if (bytesWritten == -1)
        {
            qDebug()<<"Failed to write the data to port";
        }
        else if (bytesWritten != writeData.size())
        {
            qDebug()<<"Failed to write all the data to port";
        }
        else if (!comport.waitForBytesWritten(5000))
        {
            qDebug()<<"Operation timed out or an error occurred for port";
        }
    
        qDebug()<<"Data successfully sent to port";
        QByteArray readData=comport.readAll();
        while(comport.waitForReadyRead(5000))
            readData.append(comport.readAll());
     if(comport.error()==QSerialPort::ReadError)
        {
            qDebug("Failed to read");
        }
        else if(comport.error()==QSerialPort::TimeoutError)
        {
            qDebug("Time is out");
        }
        else if(readData.isEmpty())
        {
            qDebug("no data is currently available");
        }
        qDebug()<<"read successfully :"<<readData.constData();
    

    I wanna receive the words that i just write in.
    But It cannot do what i want it to do.
    It will show read timeout.
    What can i do?
    Did i miss something here?
    Please help!

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

      Did i miss something here?
      I wanna write a program that will do send and receive in the same place and time.
      comport.open(QIODevice::WriteOnly)

      1 Reply Last reply
      4

      • Login

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