xboard & UCI speaking device on serial port

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
flok
Posts: 558
Joined: Tue Jul 03, 2018 10:19 am
Full name: Folkert van Heusden

xboard & UCI speaking device on serial port

Post by flok »

Hi,

I'm trying to connect xboard (or icsdrone) to a chess-playing device that speaks UCI and is connected to a serial port (usb-uart).

I tried this:

Code: Select all

xboard -fcp ./wrapper.sh -fUCI
where wrapper.sh is:

Code: Select all

/usr/bin/socat -v STDIO,echo=0,raw /dev/ttyACM0,raw,echo=0,b115200 2> err.txt
This doesn't work: xboard complains that "polyglot: pipex_exit(): wrapper.sh child exited with status 1".

If I run wrapper.sh from the commandline (./wrapper.sh) then all is fine: I can enter UCI commands:

Code: Select all

folkert@snsv ~/Projects/esp32chesstest/app (master)$ ./wrapper.sh 
id name Dog
id author Folkert van Heusden
uciok
info depth 1 score cp 10 nodes 21 time 8 nps 2625 pv e2e4
info depth 2 score cp 0 nodes 153 time 54 nps 2833 pv e2e4
info depth 3 score cp 15 nodes 1511 time 530 nps 2850 pv e2e3
# heap free: 145932
bestmove e2e3
For icsdrone:

run.sh:

Code: Select all

/usr/games/polyglot -noini -log true -ec ./run.sh
and

Code: Select all

#! /bin/sh

icsdrone \
        -icsPort 5000 -icsHost nightmare-chess.nl -handle Dog -password hello \
        -dontReuseEngine off \
        -program ./run.sh \
        -resign off \
        -logging on
Any ideas?
User avatar
hgm
Posts: 28353
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: xboard & UCI speaking device on serial port

Post by hgm »

Shell scripts are not binaries. So they cannot be executed. They must be interpreted bij a shell. If the file mentioned as a command on the command line has executable status but fail to execute, the shell will instead read it as text, and interpret it. But that is a shell feature, not an OS feature. And apparently not a Polyglot feature.

Have you tried to use -fcp 'sh wrapper' for the engine?
User avatar
flok
Posts: 558
Joined: Tue Jul 03, 2018 10:19 am
Full name: Folkert van Heusden

Re: xboard & UCI speaking device on serial port

Post by flok »

hgm wrote: Sun Oct 02, 2022 8:19 am Shell scripts are not binaries. So they cannot be executed. They must be interpreted bij a shell. If the file mentioned as a command on the command line has executable status but fail to execute, the shell will instead read it as text, and interpret it. But that is a shell feature, not an OS feature. And apparently not a Polyglot feature.
That's not true.
Read about the "binfmt_script" linux kernel module. E.g. in https://0xax.gitbooks.io/linux-insides/ ... all-4.html (and the kernel code: https://github.com/torvalds/linux/blob/ ... t_script.c ). That's standard functionality for quite a while.

e.g.:

Code: Select all

folkert@snsv ~/Projects/esp32chesstest/app (master)$ cat test.c 
#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
	const char name[] = "./hello.sh";

	execl(name, name, nullptr);

	return 0;
}
folkert@snsv ~/Projects/esp32chesstest/app (master)$ cat hello.sh 
#! /bin/sh

echo Hello, world.
folkert@snsv ~/Projects/esp32chesstest/app (master)$ g++ test.c ; ./a.out 
Hello, world.
Have you tried to use -fcp 'sh wrapper' for the engine?
I did try that but that didn't help.
User avatar
flok
Posts: 558
Joined: Tue Jul 03, 2018 10:19 am
Full name: Folkert van Heusden

Re: xboard & UCI speaking device on serial port

Post by flok »

flok wrote: Sun Oct 02, 2022 1:52 am For icsdrone:

run.sh:

Code: Select all

/usr/games/polyglot -noini -log true -ec ./run.sh
and
This is wrong. -ec ./run.sh must be -ec ./wrapper.sh That's not the only problem though as fixing that does not fix it.
User avatar
flok
Posts: 558
Joined: Tue Jul 03, 2018 10:19 am
Full name: Folkert van Heusden

Re: xboard & UCI speaking device on serial port

Post by flok »

Found it!

Apparently socat exits when it cannot do some ioctl on the tty (tcgetattr failed).
If I choose (for now) to ignore that with "-s", then it works fine.

Code: Select all

Last game for Dolly was history game 29.

Dolly (1591) vs. Dog (2500) --- Sat Feb 21, 10:21 CET 2009
Unrated blitz match, initial time: 2 minutes, increment: 12 seconds.

Move  Dolly              Dog                
----  ----------------   ----------------
  1.  Nf3     (0:00)     e6      (0:00)  
  2.  Nc3     (0:08)     Qf6     (0:08)  
  3.  d4      (0:08)     Bb4     (0:08)  
  4.  Ng5     (0:09)     Bxc3+   (0:09)  
  5.  bxc3    (0:09)     Qf5     (0:09)  
  6.  Nxe6    (0:09)     Qxe6    (0:05)  
  7.  Rb1     (0:09)     Qxa2    (0:06)  
  8.  Ra1     (0:09)     Qxa1    (0:10)  
  9.  Kd2     (0:10)     Nf6     (0:10)  
 10.  f3      (0:10)     Nd5     (0:10)  
 11.  Bb2     (0:10)     Qxb2    (0:10)  
 12.  e4      (0:10)     Qxc3+   (0:10)  
 13.  Ke2     (0:10)     Qe3+    (0:11)  
      {White checkmated} 0-1