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. QtSerialPort does not detect parity error under linux

QtSerialPort does not detect parity error under linux

Scheduled Pinned Locked Moved General and Desktop
serial portparityspacemarkerror detection
11 Posts 3 Posters 6.0k 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.
  • I Offline
    I Offline
    ivanperino
    wrote on 10 Aug 2015, 00:15 last edited by
    #1

    I have developed an application that uses Space and Mark parity configuration. It is an implementation of an old but still in force protocol. When a new frame starts, the first byte is with mark and others with space. So I change parity settings in runtime and I must be able to detect if the byte incoming through serial port has a mark or a space.

    It works fine in windows, but I need it on linux so when I switched to Debian, it didnt work anymore. After debugging I was able to see that mySerialPort->error() never return anything related to parity error.

    Anybody has experienced a similar behavior? Is there any bug? in QtSerialPort class?

    Thank you to everybody.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on 10 Aug 2015, 05:43 last edited by
      #2

      To be honest, nobody checked it on Linux. :)
      Probably that your device driver just do not suport this feature to detect a framing errors, or, maybe the qserialport has bugs.
      Also, your serial port side should be opened without NoParity flag (e.g. with EvenParity, OddParity, or, maybe with MarkParity or SpaceParity), to able to detect any incoming frame errors.

      Anyway, this "framing error detection" feature" is doubtful (and can be deprecated in future), because it depends on many reasons.. Besides, it reduces the stream performance, because it reads a byte by byte to able to trying to detect the framing errors.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ChrisW67
        wrote on 10 Aug 2015, 05:49 last edited by
        #3

        If I understand correctly, you configure the serial port to expect Space (0) as the parity bit. When the remote sender puts its first byte on the wire it deliberately sends Mark (1) as the parity bit. You expect to see a parity error flagged (different to a framing error), indicating the "first byte", but also expect the "corrupt" byte to be passed on to your program.

        It's possible (without looking) that the Linux serial port driver never announces the broken parity or passes on the "corrupt" byte, or that QSerialPort does the same. Does your program actually see the "corrupt" byte or is it completely absent?

        I see that any form of buffering could play havoc with this scheme: you have a parity error and three buffered bytes to choose from for example.

        1 Reply Last reply
        0
        • I Offline
          I Offline
          ivanperino
          wrote on 10 Aug 2015, 17:33 last edited by
          #4

          Dear all. Just to clarify, I never said "framing error".
          My app is always looking into serial port so there is no chance to have more than 1 byte in buffer. The first byte must be with a mark, if not, it is not the first byte of the message.
          Under windows, it works fine and fast enough to comply with such a protocol (SAS).

          • open serial port
          • set Space Parity
          • wait for a byte and read inmediatly after it arrives
          • call sp->error() and look for QSerialPort::ParityError
          • if there is a parityError, then I received a "Marked" byte because it was received with mark parity
          • read the rest of bytes (with space Parity) that correspond to the rest of message.

          I know when "marked" byte arrives because I can read it and also I see it on my osciloscope. The thing is I do not see QSerialPort::ParityError. Do you suggest that the fact of reading the byte first and THEN looking for a parity error could could be making the difference?

          Thank you for your support. I hope it is not a Bug on QSerialPort but if it is, I will be proud of collaborating for the first time.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kuzulis
            Qt Champions 2020
            wrote on 10 Aug 2015, 19:09 last edited by kuzulis 8 Oct 2015, 19:12
            #5

            POSIX API uses the byte stuffing to detecting of a frame errors. You can debug QSerialPort guts, look on readPerChar() method.
            I mean, you should himself do it, because nobody did not check it.

            PS: I tried to do it earlier, but unsuccessfully, because I have not appropriate device with the "framing detection feature". Maybe that the chip do not support it, or can be that the driver do not suport it (e.g. on Windows it will be works, but on Linux - not... by the driver reasons).. So, need to check it manually on your side with your device.. :). Also you can look on the driver's source code.. :)

            PSPS: What is chip vendor you are use (PL2303, FTDI)?

            1 Reply Last reply
            0
            • I Offline
              I Offline
              ivanperino
              wrote on 10 Aug 2015, 21:04 last edited by
              #6

              kuzulis:
              I have tried on the native Serial Port (COM1/ttyS0) on the same desktop machine I have installed Debian / Windows.
              Also tryed through a couple of Serial Ports implemented with a PCI card (COM9/ttyS2 and COM 10/ttyS3). And also over a FTDI USB adapter (COMx / ttyUSB0).

              Parity Error detection works fine on all situation using windows, but it doesnt work on any if using linux.

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kuzulis
                Qt Champions 2020
                wrote on 11 Aug 2015, 05:42 last edited by kuzulis 8 Nov 2015, 05:44
                #7

                Ok.. then only you can help himself in this case... I have no yet the HW serial ports to check it on my side. sorry. :)

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  ivanperino
                  wrote on 13 Aug 2015, 01:50 last edited by
                  #8

                  After working around.
                  I realize it is happening only in the Debian linux I have installed. I tryed with Ubuntu (Live CD) using minicom, putty and also cutecom and parity seems to work fine for native Serial Port as well as USB serial adapter.
                  I couldn't test QSerialPort yet, but I am pretty sure there is something wrong in my linux instance.

                  Thankyou very much to all of you. this forum has helped many times.

                  PD: If anybody has an idea of what is going on with my debian instalation, I will really appreciate that.

                  Thank you very much again.

                  Ivan

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kuzulis
                    Qt Champions 2020
                    wrote on 13 Aug 2015, 05:51 last edited by
                    #9

                    putty

                    I don't understand a bit, how do you detect a frame error using Putty?

                    I 1 Reply Last reply 19 Aug 2015, 14:41
                    0
                    • I Offline
                      I Offline
                      ivanperino
                      wrote on 19 Aug 2015, 00:56 last edited by
                      #10

                      After working a bit (few days indeed), it has been revealed.
                      QSerialPort is implemented under linux using termios.
                      The code for method QSerialPort::setParity(QSerialPort::Parity parity) in qserialport_unix.cpp doesn't allow parity error detection. Please take a look in the first two lines of code:
                      currentTermios.c_iflag &= ~(PARMRK | INPCK); <- here INPCK is deliberately disabled
                      currentTermios.c_iflag |= IGNPAR; <- Ignore Parity errors.

                      Library should be modified in order to process input parity errors.
                      If I use in my application:
                      QSerialPort::setParity(QSerialPort::OddParity);and inmediatly after
                      QSerialPort::setParity(QSerialPort::UnknownParity); so switch/case/default of the method is executed and incoming parity errors are now detected! Then, error signal should be emited, and etc.

                      I would like to collaborate with this given I need it and maybe to help in improvements of Qt libraries. I dont know how to do that.
                      I hope it is clear, it wasn't easy to realize my self where were the problem.

                      1 Reply Last reply
                      0
                      • K kuzulis
                        13 Aug 2015, 05:51

                        putty

                        I don't understand a bit, how do you detect a frame error using Putty?

                        I Offline
                        I Offline
                        ivanperino
                        wrote on 19 Aug 2015, 14:41 last edited by
                        #11

                        @kuzulis I used putty just to send data to my app. As you suggest, putty doesn´t detect parity errors.

                        1 Reply Last reply
                        0

                        1/11

                        10 Aug 2015, 00:15

                        • Login

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