Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, December 2006
QFile::waitForReadyRead doesn't block?


Message 1 in thread

Hi,

I am developeing an application that must connect to a device through a
serial port. The protocol requires an escape sequence like a modem - a
1 second timeout, the string "+++" and a 1 second timeout - before
sending any command.
I made a working thread that communicate with the gui through a
queue/semaphore/mutex system.
This is the sendEscape function in the thread:

bool CFeeder::sendEscape()
{
    QThread::sleep(1);

    m_dev->write ("+++");
    qDebug ("=> +++");

    QThread::sleep(1);
    bool b = m_dev->waitForReadyRead (1000);   // Wait 1000ms for resp.
    qDebug ("returned %d", b);
    QString response = m_dev->readLine();  // ignore
    qDebug ("<= %s", response.toLatin1().constData());
    return true;
}

The problem is that the waitForReadyRead() always  returns 0 - without
waiting the timeout .
What I am missing? m_dev is a QFile, which has been opened passing the
file descriptor to the /dev/ttyS0 device - because I must setup the
serial port with the termios.h tc{set,get}attr() functions.
What am I missing?

TIA

ing. Federico Fuga

--
 [ signature omitted ] 

Message 2 in thread

I can confirm this problem. Same problem here!

ing. Federico Fuga wrote:

> Hi,
> 
> I am developeing an application that must connect to a device through a
> serial port. The protocol requires an escape sequence like a modem - a
> 1 second timeout, the string "+++" and a 1 second timeout - before
> sending any command.
> I made a working thread that communicate with the gui through a
> queue/semaphore/mutex system.
> This is the sendEscape function in the thread:
> 
> bool CFeeder::sendEscape()
> {
>     QThread::sleep(1);
> 
>     m_dev->write ("+++");
>     qDebug ("=> +++");
> 
>     QThread::sleep(1);
>     bool b = m_dev->waitForReadyRead (1000);   // Wait 1000ms for resp.
>     qDebug ("returned %d", b);
>     QString response = m_dev->readLine();  // ignore
>     qDebug ("<= %s", response.toLatin1().constData());
>     return true;
> }
> 
> The problem is that the waitForReadyRead() always  returns 0 - without
> waiting the timeout .
> What I am missing? m_dev is a QFile, which has been opened passing the
> file descriptor to the /dev/ttyS0 device - because I must setup the
> serial port with the termios.h tc{set,get}attr() functions.
> What am I missing?
> 
> TIA
> 
> ing. Federico Fuga

-- 
 [ signature omitted ]