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

QSerialport SIGNAL

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.5k 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.
  • D Offline
    D Offline
    deleted28
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on last edited by
      #2

      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;
      }

      1 Reply Last reply
      0
      • D Offline
        D Offline
        deleted28
        wrote on last edited by deleted28
        #3

        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

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kuzulis
          Qt Champions 2020
          wrote on last edited by kuzulis
          #4

          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.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            deleted28
            wrote on last edited by
            #5

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

            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