-1

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?

Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
  • This question cannot be answered without you showing the code that is supposedly slow. Your question is a classical X-Y issue: you think you have problem Y, without any proof, while you really want to ask how to solve problem X: namely that your code is slow to start with. – Kuba hasn't forgotten Monica May 09 '16 at 14:00

2 Answers2

1

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.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • I did not say that buffering is slowing anything. When I send large packets my program slows down. I just wanted to confirm that buffering isn't causing it. – Aquarius_Girl May 09 '16 at 14:10
  • @TheIndependentAquarius There's no such thing as "large" packets with serial ports. Anything large enough to slow anything down would take minutes to transmit even over the fastest "serial" ports out there. `memcpy` is pretty damn fast these days. To confirm that buffering is causing it you don't want to disable buffering, you want to run it under a profiler and see that the time is spend in buffering-related functions such as `realloc` and `memcpy`. – Kuba hasn't forgotten Monica May 09 '16 at 14:29
-1

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?

Denis Shienkov
  • 517
  • 3
  • 12