Results 1 to 6 of 6

Thread: Data corruption with read() / ReadFile()

  1. #1
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    64
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Data corruption with read() / ReadFile()

    I have a problem with Qt and reading bytes from the serial port.

    I have a QTimer at 100 mS. This timerhandler call's read() on Linux or
    ReadFile() on windows in order to read bytes from the serial port.

    Everything works well except when I put some load on the computer.
    For example, I get datacorruption on the serial port when I plug a USB-stick into the computer (on Linux).
    I get also data corruption when I open other applications (on windows).

    I tried with a real COM-port and with a RS-232 to USB converter. Same result.

    When I don't use Qt but instead use a console program that only uses the standard C-library,
    no datacorruption occurs, even under heavy load conditions.

    I lowered the amount of bytes sent to the pc from 9000 bytes/sec. to 1000 bytes/sec. Same result.

    Any ideas?

    Are there any known problems of mixing calls to read() or ReadFile() and Qt?

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Data corruption with read() / ReadFile()

    You are aware that the 100ms timer is not guaranteed to "fire" within 100ms?
    (Linux is not a real-time OS.)

  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: Data corruption with read() / ReadFile()

    And why use a timer to call the reading?
    It is easier to do - is to use ready-made libraries for use with serial port:
    QextSerialPort
    or
    QSerialDevice v 0.1.0 (but better from SVN) :
    release: http://fireforge.net/frs/download.ph...ice_v0.1.0.zip
    svn:http://fireforge.net/snapshots.php?group_id=199
    Last edited by kuzulis; 20th November 2009 at 15:42.

  4. #4
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    64
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Data corruption with read() / ReadFile()

    Quote Originally Posted by caduel View Post
    You are aware that the 100ms timer is not guaranteed to "fire" within 100ms?
    (Linux is not a real-time OS.)
    Yes, and I checked how many bytes are received during every call to read().
    The device sends 772 bytes per second to the pc. Baudrate of the serial port is 115K2.
    What I see is that one call receives 78 bytes, the next call 0 bytes, next call 78 bytes, next call 0 bytes, and so on.

    When I plug-in the USB-stick, the amount of bytes received per call does not change which gives me the impression that the timer does not delay too much.

    What happens is that in one block of data (772 bytes) 4 bytes are missing.

  5. #5
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    64
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Data corruption with read() / ReadFile()

    Quote Originally Posted by kuzulis View Post
    And why use a timer to call the reading?
    It is easier to do - is to use ready-made libraries for use with serial port:
    QextSerialPort
    or
    QSerialDevice v 0.1.0 (but better from SVN) :
    release: http://fireforge.net/frs/download.ph...ice_v0.1.0.zip
    svn:http://fireforge.net/snapshots.php?group_id=199
    I tried QextSerialPort one or two years ago but it wouldn't compile and it was not maintained anymore.

    I will have a look again at these libs but I want to know why Qt does not work well with direct call's to read()...

  6. #6
    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: Data corruption with read() / ReadFile()

    Teuniz ,

    used only QSerialDevice (from SVN).

    Your questions difficult to answer, because you did not show the code.

    If you have any questions QSerialDevice - you can write to me at mail (e-mail address in source code QSerialDevice)

Similar Threads

  1. Replies: 6
    Last Post: 6th August 2009, 17:18
  2. can`t read a binary data!
    By blm in forum Qt Programming
    Replies: 8
    Last Post: 18th September 2008, 16:56
  3. How can I read binary data to QString?
    By zolookas in forum Newbie
    Replies: 2
    Last Post: 29th July 2008, 20:03
  4. Read Data in formated manner
    By rajeshs in forum Qt Programming
    Replies: 1
    Last Post: 1st January 2008, 12:28
  5. Replies: 3
    Last Post: 23rd June 2006, 17:46

Tags for this Thread

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.