Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. The best place for ReadFile()

The best place for ReadFile()

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    awwase
    wrote on last edited by
    #1

    Hi all, I'm writing a program using VC++ 6.0. The program is send and receives messages - string - via serial port. I used Overlapped mode for the communication. The program does not know when the data will come. i.e. if there is a data coming from the serial port at any time, read it. I used MFC in this project, so where is the best place for ReadFile() so that it checks if there is any data coming from serial port?? Thanks in advance What I learned is still a dot in the programming world

    R R 2 Replies Last reply
    0
    • A awwase

      Hi all, I'm writing a program using VC++ 6.0. The program is send and receives messages - string - via serial port. I used Overlapped mode for the communication. The program does not know when the data will come. i.e. if there is a data coming from the serial port at any time, read it. I used MFC in this project, so where is the best place for ReadFile() so that it checks if there is any data coming from serial port?? Thanks in advance What I learned is still a dot in the programming world

      R Offline
      R Offline
      Ram Murali
      wrote on last edited by
      #2

      I also have the same problem to read the file from the serial port.

      Regards, Ram

      1 Reply Last reply
      0
      • A awwase

        Hi all, I'm writing a program using VC++ 6.0. The program is send and receives messages - string - via serial port. I used Overlapped mode for the communication. The program does not know when the data will come. i.e. if there is a data coming from the serial port at any time, read it. I used MFC in this project, so where is the best place for ReadFile() so that it checks if there is any data coming from serial port?? Thanks in advance What I learned is still a dot in the programming world

        R Offline
        R Offline
        Roger Stoltz
        wrote on last edited by
        #3

        Have a look at Joe Newcomer's article about a threaded solution to serial programming: clickety[^]. In the article Joe uses UI threads. I've developed my own with worker threads. In addition to Joe's article you have to use ::SetCommState() in order to set baudrate and such. You should also set the timeouts for the read and write operations with ::SetCommTimeouts(). I usually set ReadIntervalTimeout and ReadTotalTimeoutMultiplier to MAXDWORD to get a special behaviour where a read operation expires after ReadTotalTimeoutConstant ms even if nothing has been received. In my opinion a reasonable value for ReadTotalTimeoutConstant would be 50 ms. Read more here: ::SetCommState()[^] ::SetCommTimeouts()[^]


        "It's supposed to be hard, otherwise anybody could do it!" - selfquote

        A 1 Reply Last reply
        0
        • R Roger Stoltz

          Have a look at Joe Newcomer's article about a threaded solution to serial programming: clickety[^]. In the article Joe uses UI threads. I've developed my own with worker threads. In addition to Joe's article you have to use ::SetCommState() in order to set baudrate and such. You should also set the timeouts for the read and write operations with ::SetCommTimeouts(). I usually set ReadIntervalTimeout and ReadTotalTimeoutMultiplier to MAXDWORD to get a special behaviour where a read operation expires after ReadTotalTimeoutConstant ms even if nothing has been received. In my opinion a reasonable value for ReadTotalTimeoutConstant would be 50 ms. Read more here: ::SetCommState()[^] ::SetCommTimeouts()[^]


          "It's supposed to be hard, otherwise anybody could do it!" - selfquote

          A Offline
          A Offline
          awwase
          wrote on last edited by
          #4

          Thanks Roger Stoltz for help I found a function that called all the time. I put the ReadFile() there. The function is DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam). Right click on the dialog>Classwizard from Messages Maps tab choose DefWindowProc under Messages. Add function then edit code :cool: .

          R 1 Reply Last reply
          0
          • A awwase

            Thanks Roger Stoltz for help I found a function that called all the time. I put the ReadFile() there. The function is DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam). Right click on the dialog>Classwizard from Messages Maps tab choose DefWindowProc under Messages. Add function then edit code :cool: .

            R Offline
            R Offline
            Roger Stoltz
            wrote on last edited by
            #5

            :wtf::omg::confused: X| Have you read the articles I provided links for in my previous post? If you have, you did not understand any of it. DefWindowProc() is probably the absolute worst place you can put a call to ::ReadFile() in since it processes unhandled messages and may get called frequently or not at all. Have a look here: http://msdn2.microsoft.com/en-us/library/ms633569.aspx[^] for further information about window procedures. You should also have a look at http://www.codeproject.com/system/#Hardware+programming[^] since you'll find some different approaches to writing serial communication.


            "It's supposed to be hard, otherwise anybody could do it!" - selfquote

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups