Polling serial ports

This is a discussion on Polling serial ports within the Windows Programming forums, part of the Platform Specific Boards category; Well, what i want to do is a simple routine that polls a serial port every 10ms for [timeout] seconds. ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    3

    Polling serial ports

    Well, what i want to do is a simple routine that polls a serial port every 10ms for [timeout] seconds.
    This is under CE btw. but it shouldn't make a difference.

    Looked around and found a function-call, called GetCommMask(), and thought to myself that i could just call that and check for the EV_RXCHAR bit of the mask.
    Well, thing is, this function seems to just set mask to zero, or to whatever you have set using SetCommMask().

    Looked around some more, and found a function called WaitForCommEvent, nice, well, this function does never timeout?!?!

    So this was no good, read the stuff at MSDN, found out some way that you could make WaitCommEvent() return directly and just set the mask if it's ?OverLapped?, but that parameter doesn't seem to be valid for CE.

    Now is there anyway way to accomplish this?

  2. #2
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Did you try to give the window a timer? If not, use SetTimer() with the last argument NULL and then do everthing when the window receives a WM_TIMER message.

  4. #4
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    > Well, thing is, this function seems to just set mask to zero, or to whatever you have set using SetCommMask().

    Which is precisely what it's documented as doing.

    > Looked around some more, and found a function called WaitForCommEvent, nice, well, this function does never timeout?!?!

    Have you tried using SetCommTimeouts?

    If these timeouts don't work for WaitCommEvent (and the documentation doesn't specify), then the obvious thing to do is to use ReadFile, which does time out. Read the documentation for COMMTIMEOUTS.
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 06-24-2008, 02:59 AM
  2. Polling serial ports
    By Nevyn in forum Windows Programming
    Replies: 0
    Last Post: 06-06-2002, 09:11 AM
  3. Need a hand accessing the serial ports
    By Danwood13 in forum C++ Programming
    Replies: 3
    Last Post: 04-24-2002, 11:03 AM
  4. Serial Ports
    By SavesTheDay in forum C Programming
    Replies: 4
    Last Post: 02-04-2002, 03:52 PM
  5. Serial Ports
    By camposv in forum C Programming
    Replies: 2
    Last Post: 01-30-2002, 12:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21