PDA

View Full Version : QSerialPort device not open display



zodd
1st July 2019, 17:35
Hello,

I use QSerialPort and I don't manage to display the information "QIODevice::write (QSerialPort): device not open" when I try to send some data if the serial port is not yet open. I can see the message in the output application of Qt Creator, but the SIGNAL(errorOccurred(QSerialPort::SerialPortError) is not emit; I guess it's because the serial port is not yet open?

I've got this source code (everything else is working well when I open the serial port):




connect(uart, SIGNAL(errorOccurred(QSerialPort::SerialPortError) ), this, SLOT(handleError(QSerialPort::SerialPortError)));

...

void UART::handleError(QSerialPort::SerialPortError error)
{
if (error == QSerialPort::ResourceError)
{
emit errorDetected(uart->errorString()); //emit error string to the GUI
if(uart->isOpen())
{
uart->close();
}

}
}



Do you have a clue?
Thanks

anda_skoa
1st July 2019, 17:53
Writing to an unopened device is likely not considered an internal error that needs to be notified but an error of usage.

But just to be sure check the result of the connect() call.

Cheers,
_

zodd
2nd July 2019, 09:03
Yes I wanted to display this error of usage as a "reminder" for me..

I checked the result of the connect() call and it's ok