- Receiving all the data from modem
- Posted by SerGioGio on November 28th, 2004
Hello,
I am using the API CreateFile, WriteFile, ReadFile in non-overlapped mode to
query my modem using AT commands.
I have the following problem.
When I send a command, say "ATZ" using WriteFile, I check the modem status
with ClearCommStatus. If cbInQue member is positive, it means there is data
to read, so I read it with ReadFile.
But I am actually receiving only part of the data! I have to issue another
ReadFile to read the rest. What happens is that even in non-overlapped mode,
there is a delay between the time you WriteFile and the time you may
ReadFile to get all the response. Indeed, if I Sleep(1000) just after
WriteFile, ReadFile does return all the data.
I would like to know whether there is another way than Sleep. Is there any
API call that can tell me that all the data is ready to read?
Thanks in advance,
SerGioGio
- Posted by Scott McPhillips [MVP] on November 28th, 2004
SerGioGio wrote:
After you open the port you can call SetCommTimeouts to set a read
timeout of, let's say, 50 msec. When you call ReadFile pass a buffer
larger than the largest expected message. ReadFile will then wait at
least 50 msec before returning. This will tend to get all the incoming
characters (for short messages). But it obviously depends on the
external device timing, and may not be perfect in all cases. Your code
should still cope properly with receiving only part of a message.
--
Scott McPhillips [VC++ MVP]
- Posted by SerGioGio on November 29th, 2004
Thanks Scott,
That was exactly what I needed!
For those who wonder, if all you need is a simple query / response dialogue
with your modem in non-overlapped mode, SetCommTimeouts is the way to go,
ClearCommStatus and cbInQue member is not to use here.
SerGioGio
"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> a écrit dans le message
de news:lqydnSuoqeyybzTcRVn-hg@comcast.com...