Results 1 to 20 of 31

Thread: send binary file over serial port with QSerialDevice

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #18
    Join Date
    Sep 2010
    Location
    IT
    Posts
    20
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Unhappy Re: send binary file over serial port with QSerialDevice

    thank you marcvanriet,
    you have understood all my problems!
    I do not understand why a class for serial communication is not ready to manage the xon/xoff flow control (or other flow control) in a easy way and so I think I'm not able to use it.
    I'll try to send the file in smaller partitions. This is a good idea!

    This is my code:
    I set the Xon/Xoff:
    Qt Code:
    1. if (!port->setFlowControl(AbstractSerial::FlowControlXonXoff)) {
    2. qDebug() << "Set flow " << AbstractSerial::FlowControlXonXoff << " error.";
    3. return;
    4. }
    To copy to clipboard, switch view to plain text mode 
    .....
    inside the function "writeBinaryFile(QString fileName)" I send the datas
    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 

    when I send a small text file all is ok. When I send a bigger binary file (32KByte) printer returns only 7Kbyte read.

    regards
    ilpaso
    Last edited by ilpaso; 7th December 2010 at 22:49.

Similar Threads

  1. Serial Port communication
    By mgurbuz in forum Qt Programming
    Replies: 12
    Last Post: 22nd January 2011, 02:38
  2. How Do I get the “friendly” name of serial port
    By sudheer168 in forum Qt Programming
    Replies: 14
    Last Post: 25th January 2010, 01:27
  3. data from serial port
    By bhe in forum Newbie
    Replies: 4
    Last Post: 3rd May 2009, 10:19
  4. serial port programming
    By sujatashooter in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2008, 15:51
  5. Serial Port
    By b1 in forum Qt Programming
    Replies: 2
    Last Post: 18th January 2007, 02:05

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
  •  
Qt is a trademark of The Qt Company.