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 timeout between two telegrams
Qt 6.11 is out! See what's new in the release blog

QSerialPort timeout between two telegrams

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 3.0k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1

    Hello there,
    I am using Qt 5.4.1 for Windows to create a programm, that sniffes the communication between two modbus devices.
    The end of each modbus message is defined by a pause of 3.5 characters.
    How can I determine this "timeout" using QSerialPort? Or should I use a different API?
    I like QSerialPort, it is very simple.

    In conclusion, I want to know how can I read only one message a time, which starts or ends with a pause of a defined time, and not the hole buffer with readall().
    The message size can be different each time.

    I have a RS485-USB-converter with an FTDI to sniff the traffic.
    I have already test "libmodbus", but there is almost the first byte wrong, every second time, there is a "wrong" byte at the start of the message.

    Thank you all & and sorry for my english, greetings from germany
    George

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

      How can I determine this "timeout" using QSerialPort?

      It is impossible in commom case. But as workaround, you can try to use QSerialPort::handle() to change COMMTIMEOUTS on Windows, ot VMIN/VTIME on Linux/MacOSX, but this will cause freezes, since it is blocking.

      Or should I use a different API?

      There are no different API.

      In conclusion, I want to know how can I read only one message a time, which starts or ends with a pause of a defined time, and not the hole buffer with readall().

      You can use QSerialPort::bytesAvailable(), QSerialPort::read(), QSerialPort::peek().

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Thank you,

        I think ReadIntervalTimeout is what I am searching for.

        How can I use this with QSerialPort::handle()?
        I cannot find any example for QSerialPort::handle(), or what it is good for.

        Can you give me a small example how to change COMMTIMEOUTS with QSerialPort::handle()?

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

          Can you give me a small example how to change COMMTIMEOUTS with QSerialPort::handle()?

          See: https://msdn.microsoft.com/ru-ru/library/windows/desktop/aa363437(v=vs.85).aspx

          For example:

          QSerialPort port("COM10");
          port.setBaudRate(115200);
          // and other settings, if need

          if (port.open(QIODevice::ReadWrite) {
          COMMTIMEOUTS timeouts;
          GetCommTimeouts(port.handle(), &timeouts);
          timeouts.ReadIntervalTimeout = 100500;
          SetCommTimeouts(port.handle(), &timeouts)) ;
          }

          1 Reply Last reply
          1
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            It works well! Thank you! My problem is solved :)

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved