Help creating emacs calls to cli

I am trying to make my first emacs package, that will control an Amatuer radio remotely. There is a command line tool called rigctl that can already do this. It can take to parameters. The first is always a letter, the second is usually a number (not a string).

I managed to find the shell-command-to-string when looking online. The problem is when I pass a number I have to convert the param to a string. I am struggling a bit to get this working as intended.

The printf %s was suggested as sometimes rigctl gets information back from the radio. This stops any newline’s being sent back to emacs.

The man page for rigctl is here

 (defun rigctl (cmd param)
  "Send command to rigctl"
  (let (par (number-to-string param))
  (shell-command-to-string (concat "printf %s $(" hamlib-rigctl-command " --model=" hamlib-rigctl-model " --rig-file=" hamlib-rigctl-rigfile " " cmd " " par ")"))))

Thank you in advance for your help :slight_smile:

Just uploaded what I have so far to github


or I can make the existing code work, if division worked as I expected.

This always results with sending 0 to rigctl

(defun rig-set-af (volume)
  "Set the radio's audio frequency (volume) gain"
  (interactive "NSet volume: ")
  (rigctl "L AF" (number-to-string (/ volume 100)))
  (message "AF gain set to %s" (rig-get-af)))

Why does say (/ 50 100) result in 0 instead of 0.5 as I expect. I guess it is something to do with int vs float!

Division on integers will return integers. This can be sidestepped like so: (/ 50 100.0)

That works. Thanks weycadosi :slight_smile: