Dear all,
I'm currently using MPU-9150 devices to perform angle measurements (bluetooth communication between a laptop and the external device) and I want to get and display them in my C++ application (using Qt library).
I correctly manage to extract the euler components from the packets sent to the virtual COM port. But previously, I have to "push" the data by typing "inve" through the cube example or through a classical terminal emulator. I would like to do this initialization step in my own application, but it does not work. It is really troublesome since I can read the data from the device but I cannot write to it.
Here is some pieces of my code :
clear(QSerialPort::Output);
int nb_send =0;
int t_pause = 500;
int bufferSize = 0;
int i_tds = 0;
this->setDataTerminalReady(true);
this->setRequestToSend(true);
QString cmd = "inv1";
int length = cmd.length();
QByteArray ba_cmd = cmd.toLocal8Bit();
char* c_cmd = ba_cmd.data();
for (int i = 0; i < length; i++)
{
nb_send += this->write(c_cmd+i,1);
qDebug() << i << " : " << *(c_cmd+i);
QTime time;
time.start();
while (time.elapsed() < t_pause)
{}
}
bufferSize = this->bytesToWrite();
b_flush = this->flush();
My problem is that the command is never received by the sensor, because I cannot see any frequency change (the command "inv1" is reducing the rate to 10Hz).
In this example, the buffer is correctly filled (bufferSize equals to 6), but the flush() function returns 'false'. It seems that the buffer content is never sent to the device. Do you have any idea about this issue ? Do I forget any special character before sending data ? (I tried to send XON, but no result) Do I have to open the port in a specific way? (however, reading data works perfectly by calling "this->read(...)" !). Here is how I initialize the port :
this->setPortName("Com7");
open(QIODevice::ReadWrite)
setFlowControl(QSerialPort::NoFlowControl);
setBaudRate(Baud115200,QSerialPort::AllDirections);
All suggestions will be helpful !
Kind Regards,