Page 2 of 2 FirstFirst 12
Results 21 to 31 of 31

Thread: send binary file over serial port with QSerialDevice

  1. #21
    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

    So what is the output from your program, "Writed text file" ?

  2. #22
    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 squidge View Post
    So what is the output from your program, "Writed text file" ?
    Sorry there is an error:
    Qt Code:
    1. if (r == quint64(data.size())) qDebug() << "Writed binary file.";
    To copy to clipboard, switch view to plain text mode 

    this means:
    "r" is the number of sent bytes
    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.
    Now I've to find this XOFF answer, wait the XON signal and restart to write.
    I thought the QSerialDevice manage this XON/XOFF but I don't know if it works.

  3. #23
    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

    2 ilpaso,

    1.
    try in the file nativeserialengine_win.cpp in the method:
    "bool NativeSerialEnginePrivate:: nativeSetFlowControl (AbstractSerial:: Flow flow)" in the selection
    of "case AbstractSerial:: FlowControlXonXoff:" add the following code (example):
    Qt Code:
    1. ...
    2. this->dcb.XonChar = 0x11;
    3. this->dcb.XoffChar = 0x13;
    4. this->dcb.XonLim = 128;
    5. this->dcb.XoffLim = 128;
    6. ...
    To copy to clipboard, switch view to plain text mode 
    Try to change or XonLim XoffLim (see MSDN for these parameters).
    But I'm not sure that this will help. I have not tested mode Xon / Xoff.

    2.
    Try to open a port in Unbuffered! Maybe this will help.

    3. Install it on your computer program such as: port sniffer, such as Free Serial Port Monitor.
    This will help to analyze the traffic.
    And look what happens, because I do not have your printer and I can not help you. Define the problem, and I'll try to fix it.

    4. Another idea: in some way (I do not know how) the software simulated your printer. Ie so that this "virtual" printer with a buffer overflow, reported the suspension of transmission.

  4. #24
    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

    Thank you kuzulis for your help. You are the QSerialDevice developer and you know your class.

    I'm working on a linux distro and I think the file to read is nativenerialnngine_unix

    Quote Originally Posted by kuzulis View Post
    I have not tested mode Xon / Xoff.
    Ok. This is an important info to know! I'll try your code but an easy solution could be to implement the XON/XOFF manually.


    Quote Originally Posted by kuzulis View Post
    3. Install it on your computer program such as: port sniffer, such as Free Serial Port Monitor.
    This will help to analyze the traffic.
    And look what happens, because I do not have your printer and I can not help you. Define the problem, and I'll try to fix it.
    Thankyou very much. I'll install a port sniffer.
    Regards
    ilpaso

  5. #25
    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

    I'm working on a linux distro and I think the file to read is nativenerialnngine_unix
    Yes.
    Then look at the documentation: Serial Programming Guide for POSIX Operating Systems
    There is information on xon/xoff.
    Look also to parameters: termios.c_cc, maybe you want to add (define) in nativenerialnngine_unix.cpp options: VSTART, VSTOP (ie, check them out and maybe give them a value of 0x31, 011).

    Thankyou very much. I'll install a port sniffer.
    I do not know sniffers for Linux. Try using strace. But I'm not sure.

  6. #26
    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

  7. #27
    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.

  8. #28
    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 

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

    ilpaso (9th December 2010)

  10. #29
    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

  11. #30
    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.

  12. #31
    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.