Unsolved Not able to pass 0x00 over Qserial port
-
@Ramarao
That's OK, welcome :)If you read what @KroMignon & I have said between us you ought be good to go!
Truly there is no problem sending
0
bytes across serial. Your problems will be (a) if you ever convert aQByteArray
to aQString
, because it's liable to terminate at the0
, as I wrote earlier, and (b) if you're not careful about interpreting what you see fromqDebug()
, because it shows "odd" bytes in ways you might misinterpret. Using @KroMignon'sQByteArray::toHex()
at least is one way to visualise the bytes without having them "terminated early" or being shown "oddly". -
This issue is resolved.
-
This my open for opening IMU
Imu::Imu() :
moving(false)
{serialPort = new QSerialPort("COM7",this); if (!serialPort->open( QIODevice::ReadOnly)) { log_warning("imu","failed to open device file \"%s\", IMU measures will be unavailable",qPrintable(serialPort->portName())); return; } if (!serialPort->setBaudRate(115200)) log_error("imu","failed to set baudrate, error no %d",serialPort->error()); serialPort->setDataBits(QSerialPort::Data8); serialPort->setParity(QSerialPort::NoParity); serialPort->setStopBits(QSerialPort::OneStop); // One Stop bit serialPort->setFlowControl(QSerialPort::NoFlowControl); //serialPort->open(QIODevice::ReadOnly); pollingTimer = new QTimer(this); QObject::connect(pollingTimer, SIGNAL(timeout()), this, SLOT(pollSerialPort())); pollingTimer->start(10); }
Imu::~Imu()
{
serialPort->close();
}void Imu::pollSerialPort()
{
static const unsigned char START_BYTES[2] = {0x55,0xAA};
static const QByteArray START_WORD((char*)START_BYTES,2);static QTime startTime = QTime::currentTime(); static QByteArray data; data.append(serialPort->readAll()); qDebug() <<"Raw data"<<data.append(serialPort->readAll()); QByteArray hex = data.append(serialPort->readAll()).toHex('0'); // returns "123456abcdef" qDebug() <<"Hex data"<<hex;
I would like to get the data in hexadecimal, however I could not get anything
Neither in binary data, nor in hexadecimal
-
@manel-sam
Hi. It might have been better to open your own topic for this than putting it in this existing thread. You could still do that.You are calling
serialPort->readAll()
3 times, including in aqDebug()
statement. Each time you call it all the data is read, it will not be there for next read.Wouldn't using
readyRead()
signal be better than your timed polling? -
@JonB Thank you for your feedback, I am new to this forum and QT too, I will do so indeed
Thanks
Can you tell me then how I can read the data without using the qDebug(), to be able to visualize if I receive the data well
and how to get the data in Hexadecimal
-
QByteArray ba = serialPort->readAll(); qDebug() << ba.count() << ba.toHex()
-
@JonB
Thanks a lot,I receive only the value 0, whereas the Imu I use receives the values in Hexadecimal.
Is it necessary to write other commands? -
@manel-sam said in Not able to pass 0x00 over Qserial port:
whereas the Imu I use receives the values in Hexadecimal.
No, it does not. Forget about hexadecimal. You are receiving 0 bytes.
-
@JonB Can you please devellope more, because I did not understand well
sorry
-
@manel-sam
What can I say? You are not receiving any bytes from the serial port!!! You printed outba.count()
and it was0
. You really should be able to understand this.....