[fpc-pascal] How to poll for a byte in Input?

Martin Schreiber mse00000 at gmail.com
Sat Dec 10 18:50:09 CET 2011


On 12/10/2011 02:58 PM, tcoq wrote:
> Chad, 
> Thank you very much. I will try your approach, as I'm interested in the piping.
> 
> I also did some experimenting with SetConsoleMode, and also with SetFileAttributes, and with ReadFileEx. But no answer there. Still blocks. 
> 
IIRC non blocking pipes are difficult on Windows. MSEgui uses a separate
thread in tpipereader for simulating non blocking pipes on Windows.
http://gitorious.org/mseide-msegui
http://gitorious.org/mseide-msegui/mseide-msegui/blobs/master/lib/common/kernel/msepipestream.pas

Asynchronous IO on Windows is done by adding FILE_FLAG_OVERLAPPED to
createfile() parameters and a toverlapped with an event object in
readfile().
http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365467%28v=VS.85%29.aspx
getoverlappedresult() can then be called with toverlapped or
waitforsingleobject() with toverlapped.event  as parameter.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687032%28v=vs.85%29.aspx

Don't forget to create and free the event object!
An example with FILE_FLAG_OVERLAPPED is here
http://gitorious.org/mseide-msegui/mseide-msegui/blobs/master/lib/common/serialcomm/msecommport.pas

All IIRC! ;-)

Martin



More information about the fpc-pascal mailing list