Results 1 to 3 of 3

Thread: sending 8bit values to QSerialPort, some of which are 0x00

  1. #1
    Join Date
    Apr 2018
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default sending 8bit values to QSerialPort, some of which are 0x00

    I'm trying to interface a bluetooth dongle. It works with the software tools they provide. the "Hello" command is supposed to loop-back. The command is 4 bytes as follows: 00 00 00 01 One concern is that three of those values are NULL, and some Qt data types and functions will terminate at NULL. The code below compiles and the value returned to written is 4; however, no response is read. Suggestion please.

    Qt Code:
    1. const char cmdHello[] = {0x00, 0x00, 0x00, 0x01};
    2. written = btSerial.write(cmdHello, 4);
    3.  
    4. bytesRead = btSerial.read(inData, 2);
    To copy to clipboard, switch view to plain text mode 
    Last edited by Kingfisher; 19th April 2018 at 04:22.

  2. #2
    Join Date
    Apr 2018
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: sending 8bit values to QSerialPort, some of which are 0x00

    It works after adding waitForReadyRead() on line 3

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: sending 8bit values to QSerialPort, some of which are 0x00

    The write() method queues the data to be sent and returns immediately. The data is not actually sent, or read, until the program reaches the event loop, which is what you are forcing with waitForReadyRead(). This asynchronous data transmission and reception is a common pattern in Qt: reading results in usually done in response to a readyRead() signal.

Similar Threads

  1. Sending data over QSerialPort
    By jvalerio in forum Qt Programming
    Replies: 1
    Last Post: 12th February 2016, 16:40
  2. Replies: 6
    Last Post: 23rd October 2015, 10:47
  3. qDebug donsn't display 0x00
    By SwanseaLover in forum Qt Programming
    Replies: 4
    Last Post: 22nd April 2013, 06:32
  4. (char) 0x00
    By saman_artorious in forum Qt Programming
    Replies: 8
    Last Post: 25th June 2012, 12:25
  5. RGB values greater than 8bit & QColor?
    By smacchia in forum Newbie
    Replies: 11
    Last Post: 21st March 2007, 15:40

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.