Not able to pass 0x00 over Qserial port
-
@KroMignon i am sending this command to AM335x and observing the data in microcom or other QT receiving application running on board..

@Ramarao said in Not able to pass 0x00 over Qserial port:
i am sending this command to AM335x and observing the data in microcom or other QT receiving application running on board..
You should be aware that '\0' (NULL character) are not printable, so you cannot see it with microcom.
You have to use an hexadecimal terminal, something likessterm(https://github.com/vsergeev/ssterm)ssterm -o hex /dev/ttyXXX -
@KroMignon iam running QT receiving app also at board side to observe data.
code_text QByteArray data = serial->readAll(); QString str = QString(data); qDebug() << str;My doubt is serial->write() will not send 0's by treating it as null character if we send in any format.
-
@KroMignon iam running QT receiving app also at board side to observe data.
code_text QByteArray data = serial->readAll(); QString str = QString(data); qDebug() << str;My doubt is serial->write() will not send 0's by treating it as null character if we send in any format.
@Ramarao
I know you have ignored every post I have made, but I did tell you:QString str = QString(data); qDebug() << str;Using
qDebug()like this is not the way to be able to see the data. Particularly0x00s....And additionally did you read QString::QString(const QByteArray &ba):
Constructs a string initialized with the byte array ba. The given byte array is converted to Unicode using fromUtf8(). Stops copying at the first 0 character, otherwise copies the entire byte array.
[My bold.]
-
@KroMignon iam running QT receiving app also at board side to observe data.
code_text QByteArray data = serial->readAll(); QString str = QString(data); qDebug() << str;My doubt is serial->write() will not send 0's by treating it as null character if we send in any format.
@Ramarao said in Not able to pass 0x00 over Qserial port:
iam running QT receiving app also at board side to observe data.
code_text
QByteArray data = serial->readAll();
QString str = QString(data);
qDebug() << str;And this wrong, you want to see hexadecimal data:
QByteArray data = serial->readAll(); qDebug() << "Raw data:" << data; qDebug() << "Hex data:"<< data.toHex(':');My doubt is serial->write() will not send 0's by treating it as null character if we send in any format.
QSerialPort::write(const char * buffer, int size)do not check null byte, what matter is size. You can send as many null bytes you want, there is no interpretation about buffer content. -
@Ramarao
I know you have ignored every post I have made, but I did tell you:QString str = QString(data); qDebug() << str;Using
qDebug()like this is not the way to be able to see the data. Particularly0x00s....And additionally did you read QString::QString(const QByteArray &ba):
Constructs a string initialized with the byte array ba. The given byte array is converted to Unicode using fromUtf8(). Stops copying at the first 0 character, otherwise copies the entire byte array.
[My bold.]
@JonB sorry that as i am new guy, forum is not allowing me immediately(making me to wait 10 mins). I am new to QT and i am trying to send 16 bytes command to AM335x board from QT application(running in PC) with button press for time being.
My goal is to send and receive data over serial communication between AM335x and STM32 where AM335x acting as GUI interface with QT application. -
@JonB sorry that as i am new guy, forum is not allowing me immediately(making me to wait 10 mins). I am new to QT and i am trying to send 16 bytes command to AM335x board from QT application(running in PC) with button press for time being.
My goal is to send and receive data over serial communication between AM335x and STM32 where AM335x acting as GUI interface with QT application.@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
0bytes across serial. Your problems will be (a) if you ever convert aQByteArrayto 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 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
-
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? -
@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
-
@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
-
@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.
-
@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.