Article View: comp.os.os2.programmer
Article #2124Re: COM ports under OS/2 2.0
From: David Bolen
Date: Fri, 16 Oct 1992 15:36
Date: Fri, 16 Oct 1992 15:36
40 lines
2754 bytes
2754 bytes
In article <1992Oct15.210722.26773@isrc.sandia.gov> ceschel@isrc.sandia.gov (Chad E. Schell) writes: >Do anyone know of a way to flush the receive buffers >of the OS/2 2.0 com drivers? I need to do this >in order to make sure that I am receiving recent >data from a constant stream that I sample only at >intermittent periods. If you are truly only issuing I/O calls to the COM port periodically, then you could make an initial IOCtl call (68H) to query the number of characters in the receive queue, and then issue a read request for just that many characters, so you don't block, but you get them all. Personally though, I think that whenever you are dealing with the COM port, you really should dedicate a thread to *always* be blocked ready to read data from the port, and stick it into your own internal buffer. The queue of the COM driver isn't all that large (a K or two maybe), and if you don't check soon enough you can lose data. Now the one "problem" is that by default, if you issue a read for n characters, it will block until you get all n characters, which is presumably not what you want. The best thing to do is to use a different read timeout mode - "Wait-For-Something". Use the Set DCB IOCtl (53H) to enable wait-for-something read timeout processing. In this mode, a read to the COM device will block if nothing is available, but will return as soon as something shows up, returning as much data as showed up. You can then buffer that data locally, and return to request more. If no data shows up for the full read timeout period (default=1min), then the read will return anyway with 0 bytes, and you can just loop back and issue the read again. You can also adjust the actual read timeout if you'd like. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ Internet: db3l@ans.net / | Advanced Network & Services, Inc. \ Phone: (914) 789-5327 | / 100 Clearbrook Road, Elmsford, NY 10523 \ Fax: (914) 789-5310 \ \-----------------------------------------------------------------------/
Technical Details
Message-ID:
<1992Oct16.193132.3601@ans.net>Path:
arc1-ca.pugleaf.net!sparky!uunet!know!cass.ma02.bull.com!think.com!ames!elroy.jpl.nasa.gov!swrinde!zaphod.mps.ohio-state.edu!malgudi.oar.net!news.ans.net!ans.net!db3lReferences:
<1992Oct15.210722.26773@isrc.sandia.gov>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!know!cass.ma02.bull.com!think.com!ames!elroy.jpl.nasa.gov!swrinde!zaphod.mps.ohio-state.edu!malgudi.oar.net!news.ans.net!ans.net!db3l From: db3l@ans.net (David Bolen) Newsgroups: comp.os.os2.programmer Subject: Re: COM ports under OS/2 2.0 Message-ID: <1992Oct16.193132.3601@ans.net> Date: 16 Oct 92 15:36:33 GMT References: <1992Oct15.210722.26773@isrc.sandia.gov> Sender: news@ans.net (News Administrator) Organization: Advanced Network & Services, Inc. - Elmsford, NY Lines: 40 In-Reply-To: ceschel@isrc.sandia.gov's message of Thu, 15 Oct 1992 21: 07:22 GMT