Results 1 to 20 of 31

Thread: send binary file over serial port with QSerialDevice

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: send binary file over serial port with QSerialDevice

    Hi,

    if r is equal to the file size the program prints "Writed binary file."
    The error is: the program sends all the bytes but if there is a XOFF the device doesn't read all the bytes.
    Just to make sure I understand you right : you do get the message "Writed binary file.", right ? This may be significant because QSerialDevice doesn't send all data at once, but in chuncks of 512 or so bytes. It might be that the serial port driver returns false on a write() when an XOff has been received. Unlikely though.

    I thought the QSerialDevice manage this XON/XOFF but I don't know if it works.
    The operating system should take care of this. QSerialDevice doesn't need to do this.

    It is very easy to implement the Xon/Xoff handshaking yourself :
    Qt Code:
    1. // until all data sent :
    2. // send a chunck of data
    3. // if something is received from the printer :
    4. // if Xoff was received :
    5. // wait until Xon received
    To copy to clipboard, switch view to plain text mode 

    Best regards,
    Marc

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: send binary file over serial port with QSerialDevice

    What is likely is that if you are sending data that is larger than the serial port buffers. What does QSerialDevice typically set the serial buffers to?

    Also, try sending in smaller chunks, say 128 bytes or even 64 or 32 bytes (you can always increase the number if it starts to work) and possibly put in a small delay between each chunk, say 100ms or so.

  3. #3
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: send binary file over serial port with QSerialDevice

    Also, try sending in smaller chunks, say 128 bytes or even 64 or 32 bytes (you can always increase the number if it starts to work) and possibly put in a small delay between each chunk, say 100ms or so.
    Yes, you can try to reduce the size of the pieces, as The default library sends data chunks of 512 bytes:
    Qt Code:
    1. #define WRITE_CHUNKSIZE Q_INT64_C(512)
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to kuzulis for this useful post:

    ilpaso (9th December 2010)

  5. #4
    Join Date
    Sep 2010
    Location
    IT
    Posts
    20
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: send binary file over serial port with QSerialDevice

    Quote Originally Posted by kuzulis View Post
    Yes, you can try to reduce the size of the pieces, as The default library sends data chunks of 512 bytes:
    Qt Code:
    1. #define WRITE_CHUNKSIZE Q_INT64_C(512)
    To copy to clipboard, switch view to plain text mode 
    Tomorrow I'll try to implement the Xon/Xoff handshaking myself and find the right buffer.
    Thank you

    ilpaso

  6. #5
    Join Date
    Sep 2010
    Location
    IT
    Posts
    20
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: send binary file over serial port with QSerialDevice

    Hi all,
    I implemented myself the flow control and the transfer works with a buffer size of 256bytes and 512bytes.
    I tried to change the "WRITE_CHUNKSIZE" variable to 256bytes and send datas without my flow control. The transfer doesn't work.

  7. #6
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: send binary file over serial port with QSerialDevice

    Great.

    Maybe kuzulis could integrate it in QSerialDevice. Xon/Xoff handshaking in software instead of in the driver of the OS.

    Regards,
    Marc

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.