Im trying to click on read button on my Qt app and read an integer from stm32 board
I can send trame from Qt app to stm32 board which is “5r” and the bard read it normally but when the board send the intger it dosent reach the QT app, any help this is code of sending the first trame and the code from stm32 that send the integer
send 5r to stm32
'connect(button2, &QPushButton::clicked, [=]() {
textBrowser->clear();
Uart* uart = Uart::getInstance();
QSerialPort* serialPort = uart->getSerialPort();
char delimiter1[2] = "*";
QByteArray packet1;
packet1.append("5");
// packet1.append(delimiter1);
packet1.append("r");
qDebug() << "packet1 :"<< packet1 ;
if (serialPort->isOpen() && serialPort->isWritable()) {
qint64 bytesWritten = serialPort->write(packet1);
if (bytesWritten == -1) {
qDebug() << "Error: Failed to write data to serial port";
} else {
qDebug() << bytesWritten << "bytes written to serial port";
textBrowser->append("Request send ...");
}
} else {
qDebug() << "Error: Serial port is not open or not writable";
}
QString style = "color: #AA4A44;"; // Adresse de couleur pour le vert (green)
textBrowser->setStyleSheet(style);'
code that send the integer to Qt app
'char data = '1'; // Define a character variable with the value '1'
HAL_UART_Transmit(&UartHandle, (uint8_t *)&data, 1, 500); '
the code of reciving the integer that doesnt work
'/* QString lastResponse = ""; // Initialiser lastResponse à une chaîne vide
QByteArray responseData;
while (serialPort->waitForReadyRead(1000)) {
responseData.append(serialPort->readAll());
}
if (!responseData.isEmpty()) {
lastResponse = QString::fromUtf8(responseData);
textBrowser->clear();
textBrowser->append("recived data :");
qDebug() << "Received data:" << lastResponse;
qDebug() << "Received data:" << responseData;
textBrowser->append(lastResponse);
} else {
qDebug() << "No data received from serial port";
textBrowser->append("No data received from serial port");
}*/'
solution for reciving the integer
New contributor
Hamza Maxmouri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.