QIODevice::ReadWrite | QIODevice::Unbuffered - Unsupported open mode

1.5k Views Asked by At

http://doc.qt.io/qt-5/qserialport.html#open

Warning: The mode has to be QIODevice::ReadOnly, QIODevice::WriteOnly, or QIODevice::ReadWrite. Other modes are unsupported.

Following code does not open the serial port.

if(serialPort.open (QIODevice::ReadWrite | QIODevice::Unbuffered))
    {
        qDebug() << "asdasdas";
        serialPort.setDataBits(QSerialPort::Data8);
        serialPort.setParity(QSerialPort::NoParity);
        serialPort.setStopBits(QSerialPort::OneStop);
    }
    else
    {
        qDebug() << "QSerialPort::SerialPortError: " << serialPort.errorString();
    }

what is the way to use the unbuffered flag?

2

There are 2 best solutions below

2
On BEST ANSWER

what is the way to use the unbuffered flag?

There is none. QSerialPort doesn't support it.

Alas, your assumption about the buffering slowing you down is unfounded unless you have measurements that demonstrate the issue. My bet is that you don't and won't have such measurements. You have other problems. Serial ports are usually of comparatively slow bandwidth, single megabits/second aren't an issue when it comes to buffering unless you're doing something that causes the buffering to have quadratic cost, and not the linear cost with very low proportionality constant it normally has.

1
On

My gui slows down while data transmission

It is impossible, in principle. Because all I/O becomes asynchronously. Most likelly the problem is in your code.

Besides, you haven't provided information about Qt version and your OS.

PS: Unbuffered mode won't help you. Besides, QSerialPort does not support it, the error code says it for you directly! Do you understand it?