Re: Quirk reading comm port

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Andrew Jarvis (someone_at_somewhere)
Date: 11/22/04


Date: Mon, 22 Nov 2004 09:45:41 -0000

Dear Valentin,

Many thanks for replying but you ought to learn to read a program before you
criticise it.

The "buffer" that I am filling with zeroes is actually a structure used for
overlapped I/O operations. I'm not exactly sure what you mean by "string
operations on memory is bottleneck" but its hardly relevant in this
instance.

You wrote "As Windows is not a realtime system, you cannot be sure that your
message will be received during specific time."

I am not concerned about time taken. My problem is that although the data is
received and ReadFile sets the overlap event, the call to
GetOverlappedResult returns zero as the number of bytes read. (I realise now
that I did not make this clear in my post).

I fixed a bug somewhere else in the program and this problem has now gone
away but there is still no reason why it should happen.

Consider keeping your posts polite in future.

Matt 7:3 "And why do you look at the speck in your brother's eye, but do not
consider the plank in your own eye?"

Yours sincerely,
Andrew Jarvis

"valentin tihomirov" <spam@abelectron.com> wrote in message
news:308808F2tr2e5U1@uni-berlin.de...
> Excuse me, I think your system sux. You fill a buffer with zeroes (string
> operations on memory is bottleneck of PC) while this is your device which
> must send asciiz. Observing the 0 you'll make sure that string is received
> completely. As Windows is not a realtime system, you cannot be sure that
> your message will be received during specific time, only byte order is
> guaranteed.
>

----- Original Message -----
From: "Andrew Jarvis" <someone@somewhere>
Newsgroups: microsoft.public.win32.programmer.kernel
Sent: Tuesday, November 16, 2004 4:35 PM
Subject: Quirk reading comm port

> Dear All,
>
> The code is intended to provide a read with timeout of a number of
> characters from a serial port which is does the majority of the time.
>
> Occassionally the call to GetOverlappedResult returns 0 even though it
> should not be reached unless the ReadFile has completed successfully.
>
> Any suggestions?
>
> Yours,
> AJ
>
>
> OVERLAPPED readOverlap;
>
> ZeroMemory(&readOverlap, sizeof readOverlap);
>
> readOverlap.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
>
> ReadFile(hCom, buffer, bytesToRead, NULL, &readOverlap);
>
> if (WaitForSingleObject(readOverlap.hEvent, timeout) == WAIT_OBJECT_0)
> {
> GetOverlappedResult(hCom, &readOverlap, &bytesRead, FALSE);
> .
> .
> .
> }
> else
> PurgeComm(hCom, PURGE_RXABORT);



Relevant Pages

  • Re: Discovering variable types...
    ... >- but I suppose MS expect us to use wrappers ... memory allocations for your variables from disk as well. ... >They most certainly are of fixed size, changing the size of a String ... >>me to keep buffer size and current postion right in the memory block. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Secure C library
    ... I read much of the new "security TR", and gee, I don't know. ... the buffer from the buffer size. ... It is not hard to design a better form of buffer and string handling. ... but this is just one example of how thoughtful interface design can ...
    (comp.std.c)
  • Re: Secure C library
    ... >> string functions don't make much sense once you add bounds-checking ... >> designing an interface just for the purpose of reducing the frequency ... > make buffer size decisions more visible, ... Bstrlib is also very interoperable with char *'s, ...
    (comp.std.c)
  • Re: Calling dll functions from vb.net with pointer returns!
    ... (ByRef pulLen As Integer, ByVal pszFilter As String, ByVal ulFlags As ... OUT PTCHAR Buffer, ... Address of a buffer to receive a set of NULL-terminated device instance ... pszFilter must specify the name of a device ...
    (microsoft.public.dotnet.languages.vb)
  • Re: why I can not write to the file after initialize the MFC in a service program
    ... you check EVERY return from a call that can fail, ... Why do you need an intermedate buffer to write literal strings anyway? ... For example, if AfxWinInit fails, you copy a 45-character string into a ... So you are going to try to initialize MFC EACH TIME THROUGH THE LOOP? ...
    (microsoft.public.vc.mfc)