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.
Code:
const char cmdHello[] = {0x00, 0x00, 0x00, 0x01};
written = btSerial.write(cmdHello, 4);
bytesRead = btSerial.read(inData, 2);
Re: sending 8bit values to QSerialPort, some of which are 0x00
It works after adding waitForReadyRead() on line 3
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.