Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QSerialPort unable to detect framing error and parity error.
Forum Updated to NodeBB v4.3 + New Features

QSerialPort unable to detect framing error and parity error.

Scheduled Pinned Locked Moved Solved Mobile and Embedded
8 Posts 4 Posters 2.1k Views 2 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.
  • S Offline
    S Offline
    sasanka
    wrote on last edited by VRonin
    #1

    Hello all,
    I have built an application that receives and transmits data through a USB serial port running on Windows 10. I am able to send and recieve data across using QSerialPort. But i want to detect the errors caused due to parity and framing error. I am doing this by simply shorting the Tx and Rx with Gnd pins. These errors are being detected by applications created using Labwindows but are not being emitted by the error signal as provided in Qt documentation. Below is the sample code for this.

    constructor{
    setSerialConfig(serialport,"com5");
    connect(&serialport,SIGNAL(error(QSerialPort::SerialPortError)),this,SLOT(handleError(QSerialPort::SerialPortError)));
    }
    
    void TwoWayComm::setSerialConfig(QSerialPort &port,QString name)
        {
        port.setPortName(name);
        port.open(QIODevice::ReadWrite);
        port.setBaudRate(QSerialPort::Baud9600);
        port.setDataBits(QSerialPort::Data8);
        port.setParity(QSerialPort::OddParity);
        port.setStopBits(QSerialPort::OneStop);
        port.setFlowControl(QSerialPort::NoFlowControl);
        }
    
       void TwoWayComm::handleError(QSerialPort::SerialPortError error)
        {
        qWarning("Error\n");
        qDebug()<<"Error triggered\n";
        }
    

    The slot is never triggered even when I remove the cables while the communication is taking place or shorting the pins while communication is taking place. Any suggestions regarding this will be really helpful.

    Thanks in advance.

    Pablo J. RoginaP 1 Reply Last reply
    0
    • S sasanka

      Hello all,
      I have built an application that receives and transmits data through a USB serial port running on Windows 10. I am able to send and recieve data across using QSerialPort. But i want to detect the errors caused due to parity and framing error. I am doing this by simply shorting the Tx and Rx with Gnd pins. These errors are being detected by applications created using Labwindows but are not being emitted by the error signal as provided in Qt documentation. Below is the sample code for this.

      constructor{
      setSerialConfig(serialport,"com5");
      connect(&serialport,SIGNAL(error(QSerialPort::SerialPortError)),this,SLOT(handleError(QSerialPort::SerialPortError)));
      }
      
      void TwoWayComm::setSerialConfig(QSerialPort &port,QString name)
          {
          port.setPortName(name);
          port.open(QIODevice::ReadWrite);
          port.setBaudRate(QSerialPort::Baud9600);
          port.setDataBits(QSerialPort::Data8);
          port.setParity(QSerialPort::OddParity);
          port.setStopBits(QSerialPort::OneStop);
          port.setFlowControl(QSerialPort::NoFlowControl);
          }
      
         void TwoWayComm::handleError(QSerialPort::SerialPortError error)
          {
          qWarning("Error\n");
          qDebug()<<"Error triggered\n";
          }
      

      The slot is never triggered even when I remove the cables while the communication is taking place or shorting the pins while communication is taking place. Any suggestions regarding this will be really helpful.

      Thanks in advance.

      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by Pablo J. Rogina
      #2

      @sasanka said in QSerialPort unable to detect framing error and parity error.:

      connect(&serialport,SIGNAL(error(QSerialPort::SerialPortError)),

      It looks like you're using a non existing signal... From QSerialPort documentation (Qt 5.11), the signal is errorOccurred(QSerialPort::SerialPortError error)

      You should have a runtime message in the application output.

      As a side note, this situation could have been avoided by using the new signal/slot syntax since the connection is checked at compile time.

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

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

        But i want to detect the errors caused due to parity and framing error.

        QSP does not support this features, and the FramingError/ParityError are obsolete. Reason is that impossible to implement this features in common case, and it complicates a code.

        The slot is never triggered even when I remove the cables while the communication is taking place

        The QSP does not know about any cables, it works with a device handle. So, if an I/O operations does not return an errors when the USB cable unplugged it is a driver/hardware/system issue.

        S 1 Reply Last reply
        2
        • S Offline
          S Offline
          sasanka
          wrote on last edited by
          #4

          Hi Thanks for the reply. Still nothing is working, I was using Qt 5.9 so both the signals error and errorOccured were available.
          But I switched to Qt 5.11 now and I have changed the source code as follows.

          connect(&serialport,&QSerialPort::errorOccurred,this,&TwoWayComm::handleError);

          still the slot handleError does not receive any errors when I try to unplug the cables in middle of communication or try to short the Tx and Rx pins of the USB serial port cable.

          1 Reply Last reply
          0
          • K kuzulis

            But i want to detect the errors caused due to parity and framing error.

            QSP does not support this features, and the FramingError/ParityError are obsolete. Reason is that impossible to implement this features in common case, and it complicates a code.

            The slot is never triggered even when I remove the cables while the communication is taking place

            The QSP does not know about any cables, it works with a device handle. So, if an I/O operations does not return an errors when the USB cable unplugged it is a driver/hardware/system issue.

            S Offline
            S Offline
            sasanka
            wrote on last edited by sasanka
            #5

            @kuzulis
            Thanks for the reply. I just wanted to reset the QSP when such errors take place. Is there any alternative how i could detect these errors and reset . thanks in advance

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

              If you want to detect for the plug/unplug events (e.g. for a USB/serial dongle), then you need to write own custom class which uses the WM_DEVICECHANGE on Windows (or udev monitoring on Linux).

              If you want to detect a framing/parity errors, then I think, it is impossible with QSP...

              But if you use only Windows, then you can write an own I/O serial port class which handles an extended event masks (like EV_BREAK, EV_ERR (for CE_FRAME, CE_OVERRUN, and CE_RXPARITY)). But, I'm not sure that it will work as you want for all serial ports (it depends on HW, driver and etc). It will not work in 90% cases, from our experience. For this reason we mark the Frame/Parity errors as deprecated (besides, this errors has not sense anyway, as need to use the protocols with a CRC fields instead).

              S 1 Reply Last reply
              0
              • K kuzulis

                If you want to detect for the plug/unplug events (e.g. for a USB/serial dongle), then you need to write own custom class which uses the WM_DEVICECHANGE on Windows (or udev monitoring on Linux).

                If you want to detect a framing/parity errors, then I think, it is impossible with QSP...

                But if you use only Windows, then you can write an own I/O serial port class which handles an extended event masks (like EV_BREAK, EV_ERR (for CE_FRAME, CE_OVERRUN, and CE_RXPARITY)). But, I'm not sure that it will work as you want for all serial ports (it depends on HW, driver and etc). It will not work in 90% cases, from our experience. For this reason we mark the Frame/Parity errors as deprecated (besides, this errors has not sense anyway, as need to use the protocols with a CRC fields instead).

                S Offline
                S Offline
                sasanka
                wrote on last edited by
                #7

                @kuzulis
                Thanks for the comments. Yeah probably using CRC fields will be an option for now.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Marria
                  Banned
                  wrote on last edited by
                  #8
                  This post is deleted!
                  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