QSerialport SIGNAL



  • Hello,

    when exactly OSerialPort emits the 'readyread' Signal ?
    I assume 'readyread' signal is emitted when the UARTS readbuffer received
    a specified number of bytes. If so, how can i increase the number of bytes to be received before the signal is emitted. I'm not sure but i think, termios allowed the chnage of buffersize, but I 'm not sure here.

    thx wally



  • I assume 'readyread' signal is emitted when the UARTS readbuffer received
    a specified number of bytes.

    Any number of bytes (at least an one).

    I'm not sure but i think, termios allowed the chnage of buffersize, but I 'm not sure here.

    You can try to use the QSerialPort::handle() to re-configure the termios structure (look on VMIN/VTIME options). But I'm not sure.

    What reason for your issue? Why just do not use:

    Foo::onReadyRead()
    {
    if (port->bytesAvailable() < expected)
    return;
    }



  • Thanks for reply!

    reason is i get sequences of bytemessages from a device on serialport which are between 14 and 110 bytes long. I would prefer to get the ready read signal, when more than 8 bytes are in buffer. I would like to setup the
    signal to be emitted lets say if 5 ms no other incoming byte is received.

    I have in this special serial protocol an advantage:
    Every message starts with 0xAA followed by a 2 bytes short (revers endianess) containing number of bytes in this particular message:
    So i can use something like this:

        quint64 tmpLen = 0;
        if (port->bytesAvailable() > 2) {
            QByteArray tmpDat(port->peek(3));
            int pos = tmpDat.indexOf(0xAA, 0);
            if (pos > -1) {
                tmpLen = tmpDat.at(pos+2) * 0xFF + tmpDat.at(pos+1);
            }
        }
    
        if (port->bytesAvailable() > (qint64) tmpLen+1) {
    
            QByteArray tmpMsg = port->read(tmpLen +1);
            currKNmsg = reinterpret_cast<KNMsg*>(tmpMsg.data());
    

    first 3 bytes are read by peek, so they remain and when i know how long the message is i do a read.
    I'm sure there are smarter solution but the communication is rather quick, and
    a nonstop keepalive message is exchanged every 300ms

    Somthing like QSerialPort->readyReadTimeOut() and QSerialPort->setRreadyReadTimeOut( t ) , t as cycles or us or other



  • I would prefer to get the ready read signal, when more than 8 bytes are in buffer

    You can wrap the QSerialPort with your custom class, and to emit the readyRead() when the bytesAvailable() more than 8 bytes.

    PS: But, the main idea is in that QSerialPort provides a continuous byte stream, similar to QAbstractSocket and so on. And you can't relies on the timeouts, number of bytes and so on. So, you need just to parse an incoming stream by own algorithm, depends on your protocol, and nothing more.



  • This is a clear answer i can follow and agree with, thx


Log in to reply
 

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