Hamlib.Nif (hamlib_ex v0.1.0)

Copy Markdown View Source

Raw NIF surface over the Hamlib C API (via the hlx_* C shim and a Rustler crate at native/hamlib_nif).

This is the low-level binding — prefer Hamlib.Rig for a managed, process-owned interface. Every function here corresponds 1:1 to a shim call.

Return shapes

  • Operations that don't return data → :ok | {:error, {code, reason}}

  • get_freq/1{:ok, hz} | {:error, {code, reason}}

  • get_mode/1{:ok, {mode_string, passband_hz}} | {:error, …}

  • get_ptt/1{:ok, boolean} | {:error, …}

code is the integer Hamlib error (negative), reason its text. A handle is an opaque resource from init/1; the BEAM frees the underlying rig when the handle is garbage-collected (close + cleanup), even on owner crash.

Lifecycle

{:ok, h} = Hamlib.Nif.init(model)            # allocate (no I/O)
:ok = Hamlib.Nif.set_conf(h, "rig_pathname", path)
:ok = Hamlib.Nif.set_conf(h, "serial_speed", "19200")
:ok = Hamlib.Nif.open(h)                      # opens the port
...
:ok = Hamlib.Nif.close(h)

Summary

Types

{hamlib_error_code, reason_string}.

Opaque rig handle resource (from init/1).

Functions

Close the rig port (rig stays initialized; reopenable).

Get frequency in Hz from the current VFO.

Get current {mode_string, passband_hz}.

Get PTT state as a boolean.

Allocate + initialize a rig for a Hamlib model number. No port I/O.

Open the configured rig port.

Set a Hamlib config token by name (e.g. "rig_pathname", "serial_speed", "ptt_type").

Set Hamlib's global debug verbosity (0 = silent … 5 = trace).

Set frequency in Hz on the current VFO.

Set mode by string + passband Hz (0 = rig's normal width).

Set PTT: true = transmit, false = receive.

Hamlib library version string.

Types

error()

@type error() :: {integer(), String.t()}

{hamlib_error_code, reason_string}.

handle()

@type handle() :: reference()

Opaque rig handle resource (from init/1).

Functions

close(handle)

@spec close(handle()) :: :ok | {:error, error()}

Close the rig port (rig stays initialized; reopenable).

get_freq(handle)

@spec get_freq(handle()) :: {:ok, float()} | {:error, error()}

Get frequency in Hz from the current VFO.

get_mode(handle)

@spec get_mode(handle()) :: {:ok, {String.t(), integer()}} | {:error, error()}

Get current {mode_string, passband_hz}.

get_ptt(handle)

@spec get_ptt(handle()) :: {:ok, boolean()} | {:error, error()}

Get PTT state as a boolean.

init(model)

@spec init(integer()) :: {:ok, handle()} | {:error, atom()}

Allocate + initialize a rig for a Hamlib model number. No port I/O.

open(handle)

@spec open(handle()) :: :ok | {:error, error()}

Open the configured rig port.

set_conf(handle, token, value)

@spec set_conf(handle(), String.t(), String.t()) :: :ok | {:error, error() | atom()}

Set a Hamlib config token by name (e.g. "rig_pathname", "serial_speed", "ptt_type").

set_debug(level)

@spec set_debug(0..5) :: :ok

Set Hamlib's global debug verbosity (0 = silent … 5 = trace).

set_freq(handle, freq_hz)

@spec set_freq(handle(), float()) :: :ok | {:error, error()}

Set frequency in Hz on the current VFO.

set_mode(handle, mode, passband_hz)

@spec set_mode(handle(), String.t(), integer()) :: :ok | {:error, error() | atom()}

Set mode by string + passband Hz (0 = rig's normal width).

set_ptt(handle, on)

@spec set_ptt(handle(), boolean()) :: :ok | {:error, error()}

Set PTT: true = transmit, false = receive.

version()

@spec version() :: String.t()

Hamlib library version string.