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. Receive Data on Serial Port C++ Windows.
Forum Updated to NodeBB v4.3 + New Features

Receive Data on Serial Port C++ Windows.

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 315 Views
  • 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.
  • M Offline
    M Offline
    mbatra
    wrote on last edited by
    #1

    Hi,

    I have to develop an application where I have to read data from serial (COM) port. Data is coming in the form of a structure where there is StartByte and EndByte. I have to implement the following:
    Read data continuously from serial port and search for StartByte (5A), then store the next 10 bytes in an array and the 12th byte is the EndByte. This should be done continuously. Again repeat the same process. if the endbyte is not received on 12th byte, then discard the data and again search for the start byte and endbyte. Data is coming continuously on the serial port.

    Any help would be appreciated.

    Thanks.

    jsulmJ C 2 Replies Last reply
    0
    • M mbatra

      Hi,

      I have to develop an application where I have to read data from serial (COM) port. Data is coming in the form of a structure where there is StartByte and EndByte. I have to implement the following:
      Read data continuously from serial port and search for StartByte (5A), then store the next 10 bytes in an array and the 12th byte is the EndByte. This should be done continuously. Again repeat the same process. if the endbyte is not received on 12th byte, then discard the data and again search for the start byte and endbyte. Data is coming continuously on the serial port.

      Any help would be appreciated.

      Thanks.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @mbatra Start here: https://doc.qt.io/qt-6/qserialport.html
      Examples: https://doc.qt.io/qt-6/qtserialport-examples.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      5
      • Christian EhrlicherC Christian Ehrlicher moved this topic from C++ Gurus on
      • M mbatra

        Hi,

        I have to develop an application where I have to read data from serial (COM) port. Data is coming in the form of a structure where there is StartByte and EndByte. I have to implement the following:
        Read data continuously from serial port and search for StartByte (5A), then store the next 10 bytes in an array and the 12th byte is the EndByte. This should be done continuously. Again repeat the same process. if the endbyte is not received on 12th byte, then discard the data and again search for the start byte and endbyte. Data is coming continuously on the serial port.

        Any help would be appreciated.

        Thanks.

        C Offline
        C Offline
        ChrisW67
        wrote on last edited by ChrisW67
        #3

        To go with the data in the QSerialPort documentation and examples, here is a sample program outline:

        • Start with an empty byte array buffer. This buffer has to persist for the entire life of the serial connection.
        • Each time you are told bytes have arrived:
          • Read all available bytes and append them to the buffer
          • If the buffer contains 12 or more bytes then it can possibly† contain a whole protocol data unit. Process all complete PDUs present and remove them from the buffer. There may be left-over bytes.
          • Exit the receive handler

        † It may contain the end of one and the start of another (both incomplete) or, less likely, contain random rubbish.

        1 Reply Last reply
        3

        • Login

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