[SOLVED] QtSerialPort even parity problem on low baudrate



  • 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



  • Please provide your code, OS version, QtSerialPort version.



  • 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



  • 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 ?



  • 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.



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



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



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



  • faulty usb to serial cable.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.