A process-owned Hamlib rig.
Wraps a Hamlib.Nif handle in a GenServer so that:
- one process owns the serial line (single controlling process — the right model for a UART, and what a consuming app's rig-control layer wants),
- commands are serialized (no two callers driving the rig at once),
- the port is opened on start and closed/cleaned up on terminate.
Starting
{:ok, rig} =
Hamlib.Rig.start_link(
model: Hamlib.model(:dummy),
conf: %{} # config tokens applied before open
)For a real serial rig:
{:ok, rig} =
Hamlib.Rig.start_link(
model: 3073, # e.g. an Icom CI-V model number
conf: %{
"rig_pathname" => "/dev/tty.usbserial-XXXX",
"serial_speed" => "19200",
"ptt_type" => "RTS"
}
)For NET rigctl (talk to an external rigctld):
{:ok, rig} =
Hamlib.Rig.start_link(
model: Hamlib.model(:netrigctl),
conf: %{"rig_pathname" => "127.0.0.1:4532"}
)Android / DigiRig note
On Android there is no /dev/tty* for USB serial; the serial path Hamlib
expects must be bridged to the Android USB host API. That bridge is tracked
separately; the API here is identical regardless of how the bytes reach the
radio.
Summary
Functions
Returns a specification to start this module under a supervisor.
Close the rig port (rig stays initialized; reopen with open/1).
Get frequency in Hz from the current VFO. {:ok, hz}.
Get current {mode_string, passband_hz}.
Get PTT state as a boolean. {:ok, true|false}.
Open the rig port (if started with open: false, or after close/1).
Set frequency in Hz on the current VFO.
Set mode by string ("USB", "PKTUSB", …) and passband Hz (0 = normal).
Key/unkey the transmitter. true = TX, false = RX.
Start a rig process. Options
Types
@type option() :: {:model, integer()} | {:conf, %{optional(String.t()) => String.t()}} | {:name, GenServer.name()} | {:open, boolean()}
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec close(GenServer.server()) :: :ok | {:error, term()}
Close the rig port (rig stays initialized; reopen with open/1).
@spec get_freq(GenServer.server()) :: {:ok, float()} | {:error, term()}
Get frequency in Hz from the current VFO. {:ok, hz}.
@spec get_mode(GenServer.server()) :: {:ok, {String.t(), integer()}} | {:error, term()}
Get current {mode_string, passband_hz}.
@spec get_ptt(GenServer.server()) :: {:ok, boolean()} | {:error, term()}
Get PTT state as a boolean. {:ok, true|false}.
@spec open(GenServer.server()) :: :ok | {:error, term()}
Open the rig port (if started with open: false, or after close/1).
@spec set_freq(GenServer.server(), number()) :: :ok | {:error, term()}
Set frequency in Hz on the current VFO.
@spec set_mode(GenServer.server(), String.t(), integer()) :: :ok | {:error, term()}
Set mode by string ("USB", "PKTUSB", …) and passband Hz (0 = normal).
@spec set_ptt(GenServer.server(), boolean()) :: :ok | {:error, term()}
Key/unkey the transmitter. true = TX, false = RX.
@spec start_link([option()]) :: GenServer.on_start()
Start a rig process. Options:
:model(required) — Hamlib model number (seeHamlib.model/1).:conf— map of Hamlib config tokens applied before opening the port.:open— open the port on start (defaulttrue).falseleaves the rig initialized + configured but closed, to open later withopen/1.:name— optional GenServer name.