Created
September 17, 2025 15:04
-
-
Save esmarr58/4c062aec0734145b2a8a2292baaff675 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void MainWindow::on_pushButton_clicked() | |
| { | |
| if (!serialActual || !serialActual->isOpen()) { | |
| QMessageBox::warning(this, "Error", "No hay ningún puerto abierto."); | |
| return; | |
| } | |
| // Tomar el texto escrito por el usuario (ej: {"sensor":"dht22","pin":4}) | |
| QString jsonStr = ui->lineEdit->text().trimmed(); | |
| if (jsonStr.isEmpty()) { | |
| QMessageBox::information(this, "Aviso", "Por favor escribe un mensaje JSON."); | |
| return; | |
| } | |
| // Convertir a bytes y agregar un salto de línea | |
| QByteArray datos = jsonStr.toUtf8() + "\n"; | |
| // Enviar al puerto serial | |
| qint64 enviados = serialActual->write(datos); | |
| if (enviados == -1) | |
| QMessageBox::warning(this, "Error", "No se pudo enviar el mensaje."); | |
| else | |
| qDebug() << "JSON enviado:" << jsonStr; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment