Mark
Mark

Reputation: 5038

QtSerialPort: how to avoid any changes on serial handshaking lines

Here my functions to open and close a serial port:

QSerialPort _serial;

bool MySerial::open(QString port, quint32 baudrate)
{
    _serial.setPortName(port);
    _serial.setFlowControl(QSerialPort::NoFlowControl);
    if (_serial.open(QIODevice::ReadWrite))
    {
        _serial.setRequestToSend(false);
        _serial.setDataTerminalReady(false);
        _serial.setBaudRate(baudrate);
        _serial.flush();
        return true;
    }
    else return false;
}

void MySerial::close()
{
    _serial.close();
}

The serial port is an FT232RL USB-to-TTL converter. Under Linux (Qt 6.6.0) no problem, the code above just opens and closes the port without changing the handshaking lines (even without explicitly setting their state).

Instead, under Windows 7 (Qt 5.15 and Qt 6.6.0) when the port closes those signals toggle for a while. Since they are connected to an external device, I want to keep them steady. In other words: they are used but a specific tool, but in my application they are not useful and must keep their state.

How can I avoid this behavior?

I also tried to move this line:

_serial.setFlowControl(QSerialPort::NoFlowControl);

after opening the port, with no luck.

Upvotes: 0

Views: 23

Answers (0)

Related Questions