Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

edited tags
Link
pmacfarlane
  • 4.5k
  • 3
  • 14
  • 35
deleted 570 characters in body; edited tags; edited title
Source Link
pmacfarlane
  • 4.5k
  • 3
  • 14
  • 35

send Send integer from stm32STM32 board to Qt app with serial communication using uartUART

ImI'm trying to click on the read button on my Qt app and read an integer from stm32an STM32 board I.

I can send tramea frame from the Qt app to stm32the STM32 board which is "5\r" and the board readreads it normally, but when the board sendsends the intgerinteger it dosen't reach to the QT app, any help this. This is the code offor sending the first trame and the code from stm32 that sendframe to the integerSTM32:


 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);'
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);

The code that sendsends the integer to the 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");
 }*/'
char data = '1'; // Define a character variable with the value '1'
HAL_UART_Transmit(&UartHandle, (uint8_t *)&data, 1, 500);

The code for receiving the integer that doesn't 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");
}

What is the solution for recivingreceiving the integer?

send integer from stm32 board to Qt app with serial communication using uart

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 "5\r" and the board read it normally but when the board send the intger it dosen't reach to the QT app, any help this is code of sending the first trame and the code from stm32 that send the integer


 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

Send integer from STM32 board to Qt app with serial communication using UART

I'm trying to click on the read button on my Qt app and read an integer from an STM32 board.

I can send a frame from the Qt app to the STM32 board which is "5\r" and the board reads it normally, but when the board sends the integer it dosen't reach the QT app. This is the code for sending the first frame to the 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);

The code that sends the integer to the Qt app:

char data = '1'; // Define a character variable with the value '1'
HAL_UART_Transmit(&UartHandle, (uint8_t *)&data, 1, 500);

The code for receiving the integer that doesn't 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");
}

What is the solution for receiving the integer?

edited body
Source Link
hcheung
  • 4.4k
  • 3
  • 16
  • 28

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 "5\r" and the bardboard read it normally but when the board send the intger it dosentdosen't reach to the QT app, any help this is code of sending the first trame and the code from stm32 that send the integer

send 5\r"5\r" to stm32


 'connectconnect(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);'

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 "5\r" 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 5\r 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);'

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 "5\r" and the board read it normally but when the board send the intger it dosen't reach to the QT app, any help this is code of sending the first trame and the code from stm32 that send the integer

send "5\r" 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);'
Source Link
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /