Results 1 to 3 of 3

Thread: how sending and recieving file via serial port

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default how sending and recieving file via serial port

    Hi,
    I want to send a file via serial port (rs232) on a device to another device. Any idea for doing this by Qt?

  2. #2
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how sending and recieving file via serial port

    I think after setting some thing like baud rate, bit data, stop bits, parity and etc then i can use this code for sending file:
    Qt Code:
    1. {
    2. QFile file(fileName);
    3. if (!file.open(QIODevice::ReadOnly)){
    4. qDebug() << "Open file fault";
    5. start(false);
    6. port->close();
    7. return;
    8. }
    9. QByteArray data = file.readAll();
    10. quint64 r = port->write(data);
    11. port->waitForBytesWritten(responseTimeout);
    12. port->waitForReadyRead(responseTimeout);
    13. cout<<r<<endl;
    14. if (r == quint64(data.size())) qDebug() << "Writed text file.";
    15. else qDebug() << "Bytes writed small: " << r;
    16. }
    To copy to clipboard, switch view to plain text mode 

    how much mega bytes cab sent by serial port? and could i consider a checksum for sending and recieving all right?

  3. #3
    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: how sending and recieving file via serial port

    Serial port can transfer any number of bytes - it is only a pipe. That you have to define a protocol and transmit the data in an orderly manner so that the recipient can interpret them correctly.

    PS
    An example protocol for file transfer is xmodem or zmodem.
    Last edited by Lesiok; 22nd November 2016 at 11:58.

Similar Threads

  1. Problem sending data over to serial port
    By hovuquocan1997 in forum Qt Programming
    Replies: 6
    Last Post: 28th July 2015, 17:49
  2. How to interrupt serial port sending?
    By redkit_redkit in forum Qt Programming
    Replies: 3
    Last Post: 9th April 2014, 12:58
  3. Replies: 2
    Last Post: 24th June 2011, 05:31
  4. serial port printer sending commands, how?
    By triperzonak in forum Qt Programming
    Replies: 3
    Last Post: 6th April 2009, 14:51
  5. sending QImage over serial port
    By yagabey in forum Qt Programming
    Replies: 5
    Last Post: 16th January 2008, 21:38

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.