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 random read timeout
Forum Updated to NodeBB v4.3 + New Features

QSerialPort random read timeout

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.2k Views 1 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.
  • T Offline
    T Offline
    theknight47
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • B Offline
      B Offline
      BowCatShot
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        theknight47
        wrote on last edited by
        #3

        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

        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