PDA

View Full Version : sending 8bit values to QSerialPort, some of which are 0x00



Kingfisher
19th April 2018, 00:09
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.



const char cmdHello[] = {0x00, 0x00, 0x00, 0x01};
written = btSerial.write(cmdHello, 4);

bytesRead = btSerial.read(inData, 2);

Kingfisher
19th April 2018, 03:23
It works after adding waitForReadyRead() on line 3

ChrisW67
19th April 2018, 09:56
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.