8.6 Hamlib - rigctld <> piWebCAT interface
From the downloaded Hamlib document - RIGCTLD(8)
rigctld communicates to a client through a TCP socket using text commands shared with rigctl. The protocol
is simple; commands are sent to rigctld on one line and rigctld responds to "get" commands with the
requested values, one per line, when successful, otherwise, it responds with one line "RPRT x", where x is a
negative number indicating the error code. Commands that do not return values respond with the line
"RPRT x", where x is zero when successful, otherwise is a negative number indicating the error code. Each
line is terminated with a newline ’\n’ character.
The Transmission Control Protocol (TCP) is one of the main protocols of the Internet protocol suite.
rigctld opens a serial TCP socket. Sockets are essentially LAN / internet ports which handle two-way serial data.
The rigctld socket is on IP address 127.0.0.1 ( localhost ) with port number 4532.
127.0.0.1 is an internal IP address which has access restricted to other processes within the the device (ie: RPi)
piWebCAT's Apache web server uses PHP commands to communicate with socket:
These are: socket_create(..) socket_connect(..) socket_read(..) socket_write(..) and socket_close(..)
The data pathway is:
rigctld has to be started at the Linux command line.
This done at piWebCAT startup by a shell_exec(command string) command which allows PHP code to issue
a command string as if it were typed into the RPI terminal at the command line.
A typical command string is:
shell_exec("rigcltd -m 1040 -r /dev/ttyUSB0 -s 38400 --vfo
--set-conf=data-bits=8stopbits=1 -c 00" > /dev/null &);
1040 (rig no), /dev/ttyUSB0 (device), 38400 (baudrate), 8 (databits) and 1 (stopbits) are all read from
the radio's user-entered configuration settings in the database rigs table as shown below.
-c 00 is the Icom CI-V address which is only used for Icom radios.
> /dev/null & allows rigctld to continue running while PHP moves on to the next command.
You do not have to deal with this command string. It is generated automatically from the parameters in
the rigs table, as shown below:
Closing piWebCAT with rigctld
piWebCAT will close down rigctld if current catcomms is HAMLIB and we are in the control window, as follows:
- Exit button clicked.
- On changing rig.
- On switching to the config or metercal windows.
This is done because rigctld startup cannot apply changed startup parameters if rigctld is already running.
(eg: a change of baudrate )
You can also stop rigctld at the RPi command line using: sudo killall rigctld