Re: Readfile 0 byte from serial byte
- From: "Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam DOT com>
- Date: Fri, 27 May 2005 08:58:19 -0700
The way it's going to work is that ReadFile will, on each loop, return one
character or no characters (the count will be returned in readNum, in your
case). As previously mentioned, your code is *not* the way to write serial
I/O code because reading one character at a time is *very* slow. As for why
you aren't ever getting all of the characters, I can't answer that without
being the hardware vendor and seeing what is sent and what you receive.
Maybe you're overflowing the FIFO in the serial hardware. Maybe you're
missing serial port interrupts.
Paul T.
"charlie" <charlie@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3BB87673-1A4E-43B0-BB88-6531FC7139E9@xxxxxxxxxxxxxxxx
> Hello Paul G.T,
> Thanks for many answers before, I don't know why I can't create a new
> question in the news group site ( I click "New->Question" then it came
> back )
> so I have to use this thread to ask you a new question.
>
> here is the code sample:
>
> COMMTIMEOUTS t = {MAXDWORD,0,0,10,1000};
> char ch = 0;
> DWORD readNum = 0, readTotal = 0;
> while( ReadFile( hCOMHandle), &ch, 1, &readNum, NULL ) && readNum > 0 )
> {
> readTotal++;
> }
>
> I called SetCommMask etc.
> I can clearly see the other side sent 200 bytes, but the above loop gave
> me
> only 10, 20, ... bytes, why?
>
> Another question, not related to the above loop.
> If I configure the timeouts as {0,0,0, 10, 1000 } or { 10,0,0,10,1000 },
> some times the ReadFile hang even the data is available, for example: I
> use
> a loop:
> for( int i = 0; i< 4099; i++ )
> {
> ReadFile(...);
> }
> I saw the other side sent 4k+3 bytes, I can read full 4k+3 bytes some
> times,
> but very often, it can read only a few handreds bytes, then ReadFile
> hang,
> why? it didn't return.
> Why?
> Thanks,
> Charlie
>
>
.
- Follow-Ups:
- Re: Readfile 0 byte from serial byte
- From: Paul G. Tobey [eMVP]
- Re: Readfile 0 byte from serial byte
- References:
- Readfile, timeout and CRLF
- From: nop
- Re: Readfile, timeout and CRLF
- From: Paul G. Tobey [eMVP]
- Readfile 0 byte from serial byte
- From: charlie
- Re: Readfile 0 byte from serial byte
- From: Paul G. Tobey [eMVP]
- Re: Readfile 0 byte from serial byte
- From: charlie
- Re: Readfile 0 byte from serial byte
- From: Paul G. Tobey [eMVP]
- Re: Readfile 0 byte from serial byte
- From: charlie
- Re: Readfile 0 byte from serial byte
- From: Paul G. Tobey [eMVP]
- Re: Readfile 0 byte from serial byte
- From: charlie
- Re: Readfile 0 byte from serial byte
- From: Paul G. Tobey [eMVP]
- Re: Readfile 0 byte from serial byte
- From: charlie
- Readfile, timeout and CRLF
- Prev by Date: Re: Test;Harware for Windows 5?
- Next by Date: Re: Readfile 0 byte from serial byte
- Previous by thread: Re: Readfile 0 byte from serial byte
- Next by thread: Re: Readfile 0 byte from serial byte
- Index(es):
Relevant Pages
|