Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is QSerialPort sending data too fast?

Is QSerialPort sending data too fast?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 548 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wost
    wrote on last edited by wost
    #1

    I have this code:

    _port.write( _commandMap.value(command) );
    _port.flush();
    
    _rwTimeoutTimer->start(100);
    
    if(_hasTimeout) {
    	_port.write(QByteArrayLiteral("\x15"));
    	_port.flush();
    } else {
    	_port.write(QByteArrayLiteral("\x06"));
    	_port.flush();
    }
    

    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.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      1
      • W Offline
        W Offline
        wost
        wrote on last edited by
        #3

        Sorry! I have this connect at the top:

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

        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! :)

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved