transfer binary file from pc(ubuntu) to raspberry(rasbian) without lrzsz or kermit, e
Hello Community,
i'm trying to transfer a binary file or file from my PC(ubuntu OS) to an embedded system raspberry(raspbian OS) over serial port. Physically, my PC is connected to my raspberry through FTDI Chip TTL-232R-Rpi Kabel(USB-to-UART).
I use an own application on my pc developed over qtcreator with QSerialPort library to configure and open the device /dev/ttyUSB0(COM3 for Windows OS) of my pc.
Code:
m_serial = new QSerialPort(this)
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);
m_serial->open(QIODevice::ReadWrite);
All work fine. I can connect the pc to the raspberry with login. The serial connection currently is working but this is controlled by the Raspberry console like a remote connection to Raspberry and goes directly to console and login(raspberry).
On my PC, being connected on the raspberry console i run the following code "dd bs=1 count=138333 | base64 -d > myfile_to_receive \r"
Code:
void MainWindow::on_btnRecv_clicked()
{
m_command = "dd bs=1 count=138333 | base64 -d > test_32_test \r";
m_serial->write(m_command.toLocal8Bit());
}
to wait and receive via serial port all binary data from pc, it works fine.
Unfortunately, when i send data from my pc using the same application but via QProcess or system with the following code "cat file_to_send > /dev/ttyUSB0"
Code:
system("cat file_to_send > /dev/ttyUSB0");
i cannot send my file and i get the message "cannot create /dev/ttyUSB0: Device or resource busy". I'm trying to remove the file LCK..ttyUSB0 created by QSerialport but nothing works well(Sending).
Can somebody help me, please?
Thank you in advance
N.B: transfer binary file over serial port without protocol like kermit, or zmodem or putty, etc.... as also no ethernet or ssh connection
Re: transfer binary file from pc(ubuntu) to raspberry(rasbian) without lrzsz or kermi
I don't think either QProcess nor system() understand shell syntax like ">", they simply execute a single program.
Have you tried using "dd" with "if=file_to_send of=/dev/ttyUSB0"?
Cheers,
_
Re: transfer binary file from pc(ubuntu) to raspberry(rasbian) without lrzsz or kermi
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.
Code:
#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");
}
this is my h-file:
Code:
#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
Re: transfer binary file from pc(ubuntu) to raspberry(rasbian) without lrzsz or kermi
Re: transfer binary file from pc(ubuntu) to raspberry(rasbian) without lrzsz or kermi
It is normal if You have COM port opened by application and trying to open this port from another process.
Re: transfer binary file from pc(ubuntu) to raspberry(rasbian) without lrzsz or kermi
thank you for your reply. i have found out a solution.
Added after 4 minutes:
thank you very much anda_skoa,
you given me a solution but i misused it.