GetNumberOfConsoleInputEvents

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

GetNumberOfConsoleInputEvents

Postby Steve S » 18 May 2013, 21:33

GetNumberOfConsoleInputEvents() for polling does not work in Winboard with FreeBasic or the gcc compiler platform. Are there any code examples of GetNumberOfConsoleInputEvents() for FreeBasic? Here is some basic code that works in console mode, but will not read if called from Winboard:
Code: Select all
#include once "windows.bi"
dim as HANDLE nStdHandle
dim as uinteger lpcNumberOfEvents
dim as integer terminate=0

nStdHandle=GetStdHandle(STD_INPUT_HANDLE)
print "STDIN =";nStdHandle
print "Press any key ..";

do
   sleep 200
   print ".";
   lpcNumberOfEvents=0
   GetNumberOfConsoleInputEvents(nStdHandle, @lpcNumberOfEvents)
   if lpcNumberOfEvents then
   print
   print "lpcNumberOfEvents  ";lpcNumberOfEvents
   terminate=1
   end if
loop until terminate
Steve S
 
Posts: 3
Joined: 31 Dec 2012, 23:50

Re: GetNumberOfConsoleInputEvents

Postby H.G.Muller » 18 May 2013, 22:15

I am not sure what you are trying to accomplish. You try to run this code aas an engine uner WinBoard? I guess engines do not have a console.
User avatar
H.G.Muller
 
Posts: 3224
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: GetNumberOfConsoleInputEvents

Postby Steve S » 18 May 2013, 22:39

Hello H.G.Muller,
The purpose of using GetNumberOfConsoleInputEvents() is to poll Winboard commands during pondering or analyzing. I assume Winboard sends the commands to STDIN. The above code is an example used in a FreeBasic console. The code would have to be modified to operate under Winboard - for example, output lpcNumberOfEvents to the debug file.
Steve S
 
Posts: 3
Joined: 31 Dec 2012, 23:50

Re: GetNumberOfConsoleInputEvents

Postby H.G.Muller » 19 May 2013, 16:37

I don't think this will work on Windows. When stdin is a pipe, (as when an engine runs under WinBoard) you will need other calls then when stdin is a keyboard. In my engines I always use PeekNamedPipe() to check for input during pondering. (This of course then doesn't work when you run the engine from the command line, so that stdin is a keyboard.)
User avatar
H.G.Muller
 
Posts: 3224
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: GetNumberOfConsoleInputEvents

Postby Steve S » 19 May 2013, 18:46

This is interesting. The documentation on "Chess Engine Communication Protocol" with Tim Mann suggests to try GetNumberOfConsoleInputEvents() to poll for Input/Output. However, it was not clear that this would not function in windows. PeekNamedPipe() seems to solve the problem (for now).
Steve S
 
Posts: 3
Joined: 31 Dec 2012, 23:50

Re: GetNumberOfConsoleInputEvents

Postby H.G.Muller » 19 May 2013, 19:09

Well, actually it says this:

CECP specs wrote:Unfortunately, under Win32, the function to use for polling is different depending on whether the input device is a pipe, a console, or something else. (More Microsoft brain damage here -- did they never hear of device independence?) For pipes, you can use PeekNamedPipe to poll (even when the pipe is unnamed). For consoles, you can use GetNumberOfConsoleInputEvents. For sockets only, you can use select().
User avatar
H.G.Muller
 
Posts: 3224
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 6 guests