Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Data stream throught QSerialPort

    General and Desktop
    2
    4
    1213
    Loading More Posts
    • 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
      michelson last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • M
          michelson last edited by

          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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 1
            • First post
              Last post