Results 1 to 6 of 6

Thread: transfer binary file from pc(ubuntu) to raspberry(rasbian) without lrzsz or kermit, e

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2019
    Posts
    11
    Thanks
    4
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default 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.
    Qt Code:
    1. m_serial = new QSerialPort(this)
    2. m_serial->setPortName("/dev/ttyUSB0)
    3. m_serial->setBaudRate(QSerialPort::Baud115200);
    4. m_serial->setDataBits(QSerialPort::Data8);
    5. m_serial->setParity(QSerialPort::NoParity);
    6. m_serial->setStopBits(QSerialPort::OneStop);
    7. m_serial->setFlowControl(QSerialPort::NoFlowControl);
    8. m_serial->open(QIODevice::ReadWrite);
    To copy to clipboard, switch view to plain text mode 

    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"
    Qt Code:
    1. void MainWindow::on_btnRecv_clicked()
    2. {
    3. m_command = "dd bs=1 count=138333 | base64 -d > test_32_test \r";
    4. m_serial->write(m_command.toLocal8Bit());
    5. }
    To copy to clipboard, switch view to plain text mode 

    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"
    Qt Code:
    1. system("cat file_to_send > /dev/ttyUSB0");
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  3. #3
    Join Date
    Jan 2019
    Posts
    11
    Thanks
    4
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default 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.
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9.  
    10. m_stdOut_Proc = "";
    11. m_stdOut_Serial = "";
    12. m_command = "";
    13.  
    14. m_serial = new QSerialPort(this);
    15. openSerialPort();
    16.  
    17. }
    18.  
    19. MainWindow::~MainWindow()
    20. {
    21. if(m_serial->isOpen())
    22. m_serial->close();
    23. delete ui;
    24. }
    25.  
    26. void MainWindow::openSerialPort()
    27. {
    28. m_serial->setPortName("/dev/ttyUSB0");
    29. m_serial->setBaudRate(QSerialPort::Baud115200);
    30. m_serial->setDataBits(QSerialPort::Data8);
    31. m_serial->setParity(QSerialPort::NoParity);
    32. m_serial->setStopBits(QSerialPort::OneStop);
    33. m_serial->setFlowControl(QSerialPort::NoFlowControl);
    34.  
    35. connect(m_serial, &QSerialPort::readyRead, this, &MainWindow::readyreadStdOut_QSerial);
    36. if(m_serial->open(QIODevice::ReadWrite))
    37. qDebug()<<"Device opened successful";
    38. else
    39. {
    40. qDebug()<<"Device opened fail";
    41. return;
    42. }
    43. }
    44.  
    45. void MainWindow::readyreadStdOut_QSerial()
    46. {
    47. m_stdOut_Serial = m_serial->readAll();
    48. qDebug()<< m_stdOut_Serial;
    49. ui->labelQSerial->setText(m_stdOut_Serial);
    50. }
    51.  
    52. void MainWindow::on_btnWrite_clicked()
    53. {
    54. m_command = ui->lineEditCommand->text() +"\r";
    55. m_serial->write(m_command.toLocal8Bit());
    56. ui->lineEditCommand->setText("");
    57. }
    58.  
    59. void MainWindow::on_btnQuitApp_clicked()
    60. {
    61. qApp->quit();
    62. }
    63.  
    64. void MainWindow::on_btnRecv_clicked() //after connection and login to raspberry. i run this command in console raspi
    65. {
    66. m_command = "dd bs=1 count=138333 | base64 -d > file_to_receive\r";
    67. m_serial->write(m_command.toLocal8Bit());
    68. }
    69.  
    70.  
    71. 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"
    72. {
    73. system("dd if=file_to_send of=/dev/ttyUSB0");
    74. }
    To copy to clipboard, switch view to plain text mode 



    this is my h-file:
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QSerialPort>
    6. #include <QSerialPortInfo>
    7.  
    8. #include <QDebug>
    9. #include <QDataStream>
    10. #include <QByteArray>
    11.  
    12. namespace Ui {
    13. class MainWindow;
    14. }
    15.  
    16. class MainWindow : public QMainWindow
    17. {
    18. Q_OBJECT
    19.  
    20. public:
    21. explicit MainWindow(QWidget *parent = nullptr);
    22. ~MainWindow();
    23.  
    24. private slots:
    25. void readyreadStdOut_QSerial();
    26.  
    27. void on_btnWrite_clicked();
    28. void on_btnQuitApp_clicked();
    29. void on_btnFirmware_clicked();
    30. void on_btnRecv_clicked();
    31.  
    32. private:
    33. void writeDate_test(const QByteArray &data);
    34. void openSerialPort();
    35.  
    36. private:
    37. Ui::MainWindow *ui;
    38.  
    39. QSerialPort *m_serial;
    40. QString m_stdOut_Serial;
    41. QString m_command;
    42.  
    43.  
    44. };
    45.  
    46. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2019
    Posts
    11
    Thanks
    4
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: transfer binary file from pc(ubuntu) to raspberry(rasbian) without lrzsz or kermi

    nobody can help me?

  5. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  6. The following user says thank you to Lesiok for this useful post:

    malone (28th May 2019)

  7. #6
    Join Date
    Jan 2019
    Posts
    11
    Thanks
    4
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default 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.
    Last edited by malone; 28th May 2019 at 16:15.

Similar Threads

  1. transfer file via wi fi
    By montanaro in forum Newbie
    Replies: 2
    Last Post: 17th February 2019, 17:15
  2. How to install Qt 4.7 from binary on Ubuntu 11.04
    By ibn-tashfin in forum Installation and Deployment
    Replies: 12
    Last Post: 31st March 2011, 14:55
  3. File Transfer in Qt
    By Rajeshsan in forum Qt Programming
    Replies: 6
    Last Post: 11th February 2011, 05:13
  4. Replies: 2
    Last Post: 2nd April 2008, 18:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.