Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. [SOLVED] QtSerialPort even parity problem on low baudrate
QtWS25 Last Chance

[SOLVED] QtSerialPort even parity problem on low baudrate

Scheduled Pinned Locked Moved 3rd Party Software
9 Posts 2 Posters 3.3k 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.
  • L Offline
    L Offline
    lfxciii
    wrote on last edited by
    #1

    Hi Team

    I've been using QtSerialPort, works fine on baudrates 9600 up. I'm trying to use it on 2400 baudrate with evenparity, one stop bit and 7 data bits. but when i use it like this, the parity is out.

    is this a common problem which has been fixed? I'm using qt4.8.

    thank you for any help

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

      Please provide your code, OS version, QtSerialPort version.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lfxciii
        wrote on last edited by
        #3

        I'm not sure about the QtSerialPort version, but I built it for Qt4, can you tell me how to find the version?

        dont have the code with me now, but i'm using this to open the port:
        @
        if (currentPortNameChanged) {
        serial.close();
        serial.setPortName(currentPortName);

        if (!serial.open(QIODevice::ReadWrite)) {
            emit error(tr("Can't open %1, error code %2")
                       .arg(portName).arg(serial.error()));
            return;
        }
        
        if (!serial.setBaudRate(QSerialPort::Baud2400)) {
            emit error(tr("Can't set baud rate 2400 baud to port %1, error code %2")
                       .arg(portName).arg(serial.error()));
            return;
        }
        
        if (!serial.setDataBits(QSerialPort::Data7)) {
            emit error(tr("Can't set 7 data bits to port %1, error code %2")
                       .arg(portName).arg(serial.error()));
            return;
        }
        
        if (!serial.setParity(QSerialPort::EvenParity)) {
            emit error(tr("Can't set even parity to port %1, error code %2")
                       .arg(portName).arg(serial.error()));
            return;
        }
        
        if (!serial.setStopBits(QSerialPort::OneStop)) {
            emit error(tr("Can't set 1 stop bit to port %1, error code %2")
                       .arg(portName).arg(serial.error()));
            return;
        }
        
        if (!serial.setFlowControl(QSerialPort::NoFlowControl)) {
            emit error(tr("Can't set no flow control to port %1, error code %2")
                       .arg(portName).arg(serial.error()));
            return;
        }
        

        } @

        then connect to readyRead
        @
        connect(&serial, SIGNAL(readyRead(), this, SLOT(readData()), Qt:DirectConnection);

        void ClassWhatWhat::readData(){
        QByteArray buffer = serial.read(1);
        }
        @

        Then when I view buffer.at(0) equals = 0x82, where in fact, it should be: 0x02

        OS version - ubuntu 12.04

        thank you for your help

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

          Are you sure that your transmitter send this byte correctly? I mean, are you sure that transmitter also has same 2400,7,E,1,noflow ?

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lfxciii
            wrote on last edited by
            #5

            yes i'm sure, i tested it by connecting another laptop to my ubuntu machine. I sent instructions from it to my ubuntu machine and i get the same. it only looks like it happens when reading from the port though.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lfxciii
              wrote on last edited by
              #6

              i also connected the tramitter to the other laptop (not the ubuntu machine),using the same terminal program and the byte comes through correctly

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

                Strange.. But you can create a bug on bug-tracker in any case, or try to understand a problem yourself.

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lfxciii
                  wrote on last edited by
                  #8

                  when my transmitter is set to even parity, i get this problem

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    lfxciii
                    wrote on last edited by
                    #9

                    faulty usb to serial cable.

                    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