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. Changing end-of-line character for QSerialPort?

Changing end-of-line character for QSerialPort?

Scheduled Pinned Locked Moved General and Desktop
10 Posts 6 Posters 4.8k 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.
  • R Offline
    R Offline
    RogueWarrior
    wrote on last edited by
    #1

    Is there any way to change the end-of-line character for QSerialPort from /n to /r so that canReadLine will return true if there is only /r between lines?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vezprog
      wrote on last edited by
      #2

      I don't believe there is any way to change the '\n' end of line character to '\r' since it is the standard for for QSerialPort which inherits "QIODevice":http://qt-project.org/doc/qt-4.8/qiodevice.html#getChar

      It may not be the most efficient way of doing it, but you could call getChar() and read until you get your '\r' character. This probably isn't the most GUI friendly way unless you toss it in a thread.

      Depending on how your using the QSerialPort class, a common way to read the port if your expecting data after a '\r' (say its streaming data constantly on the port) is to use a circular buffer. You can call readAll() and just post the remaining bytes for the next readyRead() you encounter.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RogueWarrior
        wrote on last edited by
        #3

        Well, I had to write my own canReadLine and readLine equivalents that use the peek function to inspect the data stream for the existence and location of \r characters. It works but it's not elegant. This is all because the device I'm talking to does a non-standard end-of-line. Other devices I've used all use \n.

        IMHO, full support of termios that would allow me to set ICRNL and other configuration flags would be better. Of course that assumes that these are available on all platforms e.g. Windows.

        So, feature request.

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          Hi,

          If you want to submit a feature request, you can do so https://bugreports.qt-project.org/ (Create a new issue and set the Issue Type to "Suggestion").

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

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

            RogueWarrior,

            you can derive you own class from the QSerialPort and implement any your feature as you want. Just override an desired virtual methods:

            [code]
            MyCoolSerialPort : public QSerialPort
            {
            public:
            ...
            bool canReadLine() const Q_DECL_OVERRIDE;
            ...

            protected:
            ...
            qint64 readLineData(char *data, qint64 maxSize) Q_DECL_OVERRIDE;
            ...

            }
            [/code]

            and so on.

            Besides, you can use QSerialPort::handle() to setup your specific options to termios.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              djszapi
              wrote on last edited by
              #6

              For the record, here is the report: https://bugreports.qt-project.org/browse/QTBUG-38812

              1 Reply Last reply
              0
              • R Offline
                R Offline
                RogueWarrior
                wrote on last edited by
                #7

                Are the details of handle documented anywhere?

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  MuldeR
                  wrote on last edited by
                  #8

                  [quote author="RogueWarrior" date="1399471127"]Are the details of handle documented anywhere?[/quote]

                  The "handle" is almost certainly going to be platform-specific, so you'll have to refer to the Win32 API documentation or the POSIX standard, respectively.

                  My OpenSource software at: http://muldersoft.com/

                  Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                  Go visit the coop: http://youtu.be/Jay...

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    djszapi
                    wrote on last edited by
                    #9

                    @#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
                    typedef void* Handle;
                    #else
                    typedef int Handle;
                    #endif
                    @

                    https://qt.gitorious.org/qt/qtserialport/source/c0fc9aecd67323630011eaa9a1c213eed5bc5387:src/serialport/qserialport.h#L78

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      MuldeR
                      wrote on last edited by
                      #10

                      I think the really interesting part is in "qserialport_win_p.h" and "qserialport_unix_p.h", respectively:
                      @class QSerialPortPrivate : public QSerialPortPrivateData
                      {
                      public:
                      HANDLE handle; /WINDOWS version/
                      int descriptor; /UNIX version/
                      }@

                      So, not much surprising, it's a "native" file "HANDLE":http://goo.gl/Hrjk1W on the Windows platform and it's a standard file descriptor on POSIX systems.

                      My OpenSource software at: http://muldersoft.com/

                      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                      Go visit the coop: http://youtu.be/Jay...

                      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