Qt World Summit: Register Today!

Is QSerialPort sending data too fast?

  • I have this code:

    _port.write( _commandMap.value(command) );
    if(_hasTimeout) {
    } else {

    So I write a command, use a timer that waits for 100ms and when it times out, I start ignoring the data being sent to me and _hasTimeout is set to True. It works, but unfortunately the byte 0x06 (ACK) is sometimes appended to the command I'm sending for some reason. I know that _port.flush() is non-blocking, and I'm thinking that might be the problem -- that everything is happening too fast.
    Any ideas as to what I can try to do?

    EDIT: I tried adding a QThread::msleep() on like 3ms, and that made the 0x06 suffixing happen less frequently.

  • Moderators

    So the code you pasted gets called repeatedly, right? Is it in some kind of loop, triggered by some even or something?

    Why do you wait for 100 ms? From your description it looks like you rather want to send a command and stop listening immediately.

    BTW> start(100); is not blocking, either.

  • Sorry! I have this connect at the top:

    connect(_rwReadyTimer, QTimer::timeout, [this]() {
    	if(_state == 2) {
    		_hasTimeout = false;

    After 100ms, it stops reading and goes back to a "readyRead" state. The application I'm working with specifies that each frame sent by the application should just try to read for 100ms before discarding it. Anyway, I found a solution in creating a new signal and emitting it when I was done reading the data I wanted! :)

Log in to reply