Results 1 to 10 of 10

Thread: Suppressing CR on LF in C++ in Windows

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Suppressing CR on LF in C++ in Windows

    I'm afraid that doesn't work, using \x0A instead of \n operates the same. And I can't just strip out \r's following \n's as I'm transmitting binary data and that messes things up.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Suppressing CR on LF in C++ in Windows

    So prepare the other end of transmission to receive \r\n instead of \n.

  3. #3
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Suppressing CR on LF in C++ in Windows

    That's the only way I can deal with it at the moment, it means that I cannot have a "command" number 13 as the first character in a message so I can strip it out if it is following a NL. It works, it's just less elegant and makes my command number enumeration more fragile.

    Thanks.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Suppressing CR on LF in C++ in Windows

    You have an alternative - don't use newlines at all. If you transmit binary data, what do you need the newlines for?

  5. #5
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Suppressing CR on LF in C++ in Windows

    It's a convienience to work in a line oriented mode as the embedded cpu has a monitor program that can be accessed via a terminal in line input mode - so the serial receiving program can be the same for both - it buffers characters until a \n then sends a message to either the command processor or monitor program depending upon the mode it's in.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Suppressing CR on LF in C++ in Windows

    Quote Originally Posted by Doug Broadwell View Post
    it means that I cannot have a "command" number 13 as the first character in a message
    This suggests you are sending bare command numbers. In such a situation you'll be having unprintable characters in your transmission, so you'll end up with trash in your monitor anyway. Maybe it's better to implement the monitor in a way that it "translates" binary data to human readable format and get rid of all textual transmission?

  7. #7
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Suppressing CR on LF in C++ in Windows

    Thanks. Actually, I realized in the wee hours of the morning what a ninny I am, there is no way that there could be a "line oriented" binary protocol !!

    What I must do is move the logic of the parsing of messages down into the routine that is reading in the characters to switch between the binary message format and the line oriented format (and then, the CR stripping will be trivial for the line oriented case but still a big problem if some driver I have no control over is insisting on inserting a #13 character every time it sees a #10 character).

    Sorry for being so dense.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Suppressing CR on LF in C++ in Windows

    You can use XML (using QDomDocument of course) to have a nice textual representation of your protocol, which is very easy to parse and interpret - this way you can make a nice monitoring application and at the same time have both human readable representation and easy syntax checking on both ends.

Similar Threads

  1. Deploying with MySQL support under Windows
    By KShots in forum Installation and Deployment
    Replies: 1
    Last Post: 12th October 2006, 09:19
  2. converting unix exe to windows binary
    By deekayt in forum General Programming
    Replies: 2
    Last Post: 17th September 2006, 01:00
  3. Experience using KDevelop with Cygwin under windows
    By high_flyer in forum General Discussion
    Replies: 4
    Last Post: 11th September 2006, 16:50
  4. qt and mingw can not run on windows 98?
    By evewei in forum Installation and Deployment
    Replies: 4
    Last Post: 26th June 2006, 09:22
  5. MDI windows without QWorkspace
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 16th June 2006, 17:15

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.