QSerialPort random read timeout



  • Hello everyone,

    I have a very strange problem with the QSerialPort::waitForReadyRead method, I use the following code ( running on a thread ):

    @String portCom::sendRequest( QString request )
    {
    serial->clear();
    serial->write( request.toLocal8Bit() );

    if (serial->waitForBytesWritten( 10000 )) {

     QByteArray responseData;
            if (serial->waitForReadyRead( 10000 )) {
    
                qint64 av = serial->bytesAvailable();
    std::cout << "Bytes to write " << av << std::endl;
    
    QByteArray oneResponse;
    
     while ( serial->waitForReadyRead( 100 ) )
     { 
      oneResponse = serial->readAll();
    
      for ( int i=0; i < oneResponse.size(); i++ )
      {
       if ( QString( oneResponse.at(i) ) == "!" ) break;
       else 
    
       { 
        responseData +=  oneResponse.at(i);
        qDebug ( QString( oneResponse.at(i) ).toLatin1() );
       }
       
      }
      
      
     }
    //}
    
                QString response2( responseData );
    
    response2.remove( "\n" );
    
    return response2;
    
            } else {
    
    std::cout << "error code AR003 : Wait read response timeout " << std::endl; 
    std::cout << serial->errorString().toStdString() << std::endl;
    
    serial->clear();
    //serial->clear();
    serial->close();
    
    if ( serial->open( QIODevice::ReadWrite ) ) 
    {
     std::cout << "Serial reopened" << std::endl;
    }
    
    else 
    {
     std::cout << "failed to open the device" << std::endl;
    }
    
    
    return QString("AR_ERROR");
            }
           
        } else {
    

    std::cout << "error code AR002 : Wait write request timeout " << std::endl;

    serial->clear();
    serial->close();

    if ( serial->open( QIODevice::ReadWrite ) ) 
    {
     std::cout << "Serial reopened" << std::endl;
    }
    
    else 
    {
     std::cout << "failed to open the device" << std::endl;
    }
    

    return QString("AR_ERROR");
    }

    }
    @

    Actually, the communication with the COM port (Arduino Uno) is working fine but in some times I have a read timeout and after that no response ( only read/write timeouts )

    My question is : can this problem be relative to the Qt functions (waitForReadyRead / waitForBytesWritten ) or is a hardware issue that can occur on the device.

    Thank you very much



  • If you're running on a Linux system, try doing a google search on EAGAIN. It's a known Linux bug and may pertain to what's going on here.



  • Thank you BowCatShot for the reply

    Actually, I am working on Windows 8.1 plate form with Qt 5.2.1

    Thank you very much


Log in to reply
 

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