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. Data stream throught QSerialPort

Data stream throught QSerialPort

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.4k 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
    michelson
    wrote on last edited by
    #1

    Hello,
    i have a measuring device connected to PC via QSerialPort (bluetooth). It supports 2 communication modes:

    1. sending some settings in a manner of command-optional answer pair which I already implemented
    2. online measurment in which it streams continuous data until being stopped (by sending proper command)

    I am wondering which approach would be the best (mayby easiest to code) for getting streamed data if I want to plot it in real-time. I am considering QSerialPort::readData() combined with QSerialPort::availableBytes() to read only full data samples (2 to 4 bytes depending on settings). I also read something about QDataStream(QIODevice) but since I havent worked with QDataStrem yet I assume it might be more problematic. However class name promises wanted behaviour so I find it tempting :D
    Long story short - I would appreciate any kind of help/suggestions!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      QDataStream is indeed not what you are looking for. Using readyRead should do what you want. Does the data you receive follow a pattern ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        michelson
        wrote on last edited by
        #3

        Yep it does, however this pattern depends on previously programmed pattern eg.: if i program N-channel measurment I'll be getting data like [L byte ch1] [H byte ch1] ... [L byte ch_N] [H byte ch_N] [END OF SAMPLE L] [END OF SAMPLE H]. So basicly after every portion of data I'll have an end-of-sample info (2 bytes) and the next byte will be already from another sample.
        @SGaist Do you have some particular solution in mind regarding your question? :)

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Yes, use a buffer where you append the data you receive from the serial port then check if it contains one or more complete packet. If so extract it/them from the buffer and do your processing the way you want it.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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