PDA

View Full Version : XON/XOFF connection with QtSerialPort



oldFox64
6th February 2014, 07:54
Hi,

Wanted to know how I should approach a serial port connection with XON/XOFF flow control.

Before I read/write from/to serial port, what should I do?

The process is something like this:

I send data to my serial port, the receiver sends me XOFF after he receives it, now I should wait until he sends me XON, then I can send again. How I translate that to code? The waiting part (which should be passive, no?) is the difficult one for me.

The purpose is to send a hex file by lines.

kuzulis
6th February 2014, 10:03
Hi.

We didn't check the modes "Software/Hardware" flow control for QtSerialPort. I.e. it isn't known as this set of modes will behave with the Qt event-loop and so forth.
In the theory, for you (as transmitter role) is not necessary cares of existence of XON/XOFF bytes that received from the receiver. Because it does by hardware, at the level of the driver of the serial port.
So, your task consists in that simply to send all data to the receiver, like Transmitter::write(/all data/). And just watch for the bytesWritten() signal to know how many data are transferred in reality, IMHO.

oldFox64
6th February 2014, 10:31
Thank you, kuzulis.

I tell my results later.

EDIT: Success :) Was easier than I thought.

while(!in.atEnd()){
QString line = in.getLine();
serial->write(line.toLocalBits8());
serial->waitForBytesWritten(250);
}

That is enough.

oldFox64
11th February 2014, 08:31
Hmm, if I don't use waitForBytesWritten after write and waitForReadyRead before read, the communication doesn't work properly. That means that these functions are checking the control chars XON/XOFF (as I said, my firmware, the receiver, sends me XON's and XOFF's chars) ? If so, I think it would be a good idea to specify it in the documentation, don't you?

kuzulis
13th February 2014, 07:20
Please show your complete code to reproduce a problem.