How to send and receive in the sametime



  • 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!



  • 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)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.