Thank you for your reply.
i am trying with "dd" but i always receive the same error message "cannot open /dev/ttyUSB0: Device or resource busy". May be i cannot utilize in the same time with 2 differents(QSerialPort and System/or QProcess) process the device /dev/ttyUSB0. do you have any idea?
Thank you!
this is my code cpp.
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_stdOut_Proc = "";
m_stdOut_Serial = "";
m_command = "";
m_serial = new QSerialPort(this);
openSerialPort();
}
MainWindow::~MainWindow()
{
if(m_serial->isOpen())
m_serial->close();
delete ui;
}
void MainWindow::openSerialPort()
{
m_serial->setPortName("/dev/ttyUSB0");
m_serial->setBaudRate(QSerialPort::Baud115200);
m_serial->setDataBits(QSerialPort::Data8);
m_serial->setParity(QSerialPort::NoParity);
m_serial->setStopBits(QSerialPort::OneStop);
m_serial->setFlowControl(QSerialPort::NoFlowControl);
connect(m_serial, &QSerialPort::readyRead, this, &MainWindow::readyreadStdOut_QSerial);
qDebug()<<"Device opened successful";
else
{
qDebug()<<"Device opened fail";
return;
}
}
void MainWindow::readyreadStdOut_QSerial()
{
m_stdOut_Serial = m_serial->readAll();
qDebug()<< m_stdOut_Serial;
ui->labelQSerial->setText(m_stdOut_Serial);
}
void MainWindow::on_btnWrite_clicked()
{
m_command = ui->lineEditCommand->text() +"\r";
m_serial->write(m_command.toLocal8Bit());
ui->lineEditCommand->setText("");
}
void MainWindow::on_btnQuitApp_clicked()
{
qApp->quit();
}
void MainWindow::on_btnRecv_clicked() //after connection and login to raspberry. i run this command in console raspi
{
m_command = "dd bs=1 count=138333 | base64 -d > file_to_receive\r";
m_serial->write(m_command.toLocal8Bit());
}
void MainWindow::on_btnFirmware_clicked() // i try to start this command in shell pc but it doesn't work. i receive a error message: "cannot open /dev/ttyUSB0: Device or resource busy"
{
system("dd if=file_to_send of=/dev/ttyUSB0");
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_stdOut_Proc = "";
m_stdOut_Serial = "";
m_command = "";
m_serial = new QSerialPort(this);
openSerialPort();
}
MainWindow::~MainWindow()
{
if(m_serial->isOpen())
m_serial->close();
delete ui;
}
void MainWindow::openSerialPort()
{
m_serial->setPortName("/dev/ttyUSB0");
m_serial->setBaudRate(QSerialPort::Baud115200);
m_serial->setDataBits(QSerialPort::Data8);
m_serial->setParity(QSerialPort::NoParity);
m_serial->setStopBits(QSerialPort::OneStop);
m_serial->setFlowControl(QSerialPort::NoFlowControl);
connect(m_serial, &QSerialPort::readyRead, this, &MainWindow::readyreadStdOut_QSerial);
if(m_serial->open(QIODevice::ReadWrite))
qDebug()<<"Device opened successful";
else
{
qDebug()<<"Device opened fail";
return;
}
}
void MainWindow::readyreadStdOut_QSerial()
{
m_stdOut_Serial = m_serial->readAll();
qDebug()<< m_stdOut_Serial;
ui->labelQSerial->setText(m_stdOut_Serial);
}
void MainWindow::on_btnWrite_clicked()
{
m_command = ui->lineEditCommand->text() +"\r";
m_serial->write(m_command.toLocal8Bit());
ui->lineEditCommand->setText("");
}
void MainWindow::on_btnQuitApp_clicked()
{
qApp->quit();
}
void MainWindow::on_btnRecv_clicked() //after connection and login to raspberry. i run this command in console raspi
{
m_command = "dd bs=1 count=138333 | base64 -d > file_to_receive\r";
m_serial->write(m_command.toLocal8Bit());
}
void MainWindow::on_btnFirmware_clicked() // i try to start this command in shell pc but it doesn't work. i receive a error message: "cannot open /dev/ttyUSB0: Device or resource busy"
{
system("dd if=file_to_send of=/dev/ttyUSB0");
}
To copy to clipboard, switch view to plain text mode
this is my h-file:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QDebug>
#include <QDataStream>
#include <QByteArray>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= nullptr
);
~MainWindow();
private slots:
void readyreadStdOut_QSerial();
void on_btnWrite_clicked();
void on_btnQuitApp_clicked();
void on_btnFirmware_clicked();
void on_btnRecv_clicked();
private:
void openSerialPort();
private:
Ui::MainWindow *ui;
QSerialPort *m_serial;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QDebug>
#include <QDataStream>
#include <QByteArray>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void readyreadStdOut_QSerial();
void on_btnWrite_clicked();
void on_btnQuitApp_clicked();
void on_btnFirmware_clicked();
void on_btnRecv_clicked();
private:
void writeDate_test(const QByteArray &data);
void openSerialPort();
private:
Ui::MainWindow *ui;
QSerialPort *m_serial;
QString m_stdOut_Serial;
QString m_command;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
Bookmarks