Re: Readfile 0 byte from serial byte



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
>
>


.



Relevant Pages

  • Re: looking for implementation of strtok
    ... contains a ',' character. ... we enter the ugly loop that simply implements strspn: ... loop sets spanp to delim, then loops while seting sc (the "span ... If there are no more tokens, we set *lastp to NULL (this is, I ...
    (comp.lang.c)
  • Re: EV_RXCHAR event received, but ReadFile sometimes failed to read a byte from serial port
    ... With non-overlapped ReadFile, if a ReadFile is pending, a WriteFile issued after the ... Why do you declare BOOL variables (prefix 'b') with some meaningless prefix ('f', ... Why read only one character? ... to use the events in serial ports at all. ...
    (microsoft.public.vc.mfc)
  • Re: Event Based or Get-Key based
    ... say, much like you'd program a GUI - the main loop just collects input, and that input is then passed to call backs. ... the queue when character death is detected. ... Executing an ENDGAME event removes all pending events ... it queues up a select-action ...
    (rec.games.roguelike.development)
  • Re: Which assembler can handle the BIG stuff ?
    ... |> jnz loop;or JNS/JNGE if endmark included in size ... | Yeah, but this is done once, not once per character, so it isn't going ... |> Ok, I'd use KESYS Fn50 to create a formatted, sorted table ... I don't sort ...
    (alt.lang.asm)
  • Re: Histogram of character frequencies
    ... to any valid character value). ... quits the loop without entering the body. ... we then use feof() to test for an end of file ... Dig the sig! ...
    (comp.lang.c)

Quantcast