exbee v0.0.3 Exbee View Source

Communicate with XBee wireless radios in Elixir.

This assumes that XBee modules are in API mode. In API mode, XBee modules send and receive commands via encoded frames. Possible frames include:

Frames are sent via the Exbee.send_frame/2 function. Frames received on the serial port are reported as messages to the current process. The messages have the following form:

{:exbee, frame}

This example starts an Exbee process and sends an Exbee.ATCommandFrame to change the value of the NJ parameter. Upon receiving the command, the XBee module will return an Exbee.ATCommandStatusFrame indicating the status of the request.

iex> {:ok, pid} = Exbee.start_link(serial_port: "COM1")
iex> Exbee.send_frame(pid, %Exbee.ATCommandFrame{command: "NJ", value: 1})
:ok

iex> flush()
{:exbee, %Exbee.ATCommandResultFrame{command: "NJ", status: :ok, value: <0x01>}}

Link to this section Summary

Functions

Send a frame to a given device

Return a map of available serial devices with information about each

Start a new Exbee process

Shuts down the device process

Link to this section Types

Link to this type device_option() View Source
device_option ::
  {:serial_port, String.t} |
  {:speed, non_neg_integer} |
  {:data_bits, 5..8} |
  {:stop_bits, 1..2} |
  {:parity, :none | :even | :odd | :space | :mark} |
  {:flow_control, :none | :hardware | :software}

Link to this section Functions

Link to this function send_frame(pid, frame) View Source
send_frame(pid, Exbee.EncodableFrame.t) :: :ok | {:error, term}

Send a frame to a given device.

A frame must implement the Exbee.EncodableFrame protocol, making it possible to define custom frames.

Link to this function serial_ports() View Source
serial_ports() :: map

Return a map of available serial devices with information about each.

iex> Exbee.serial_ports()
%{
  "COM1" => %{description: "USB Serial", manufacturer: "FTDI", product_id: 1, vendor_id: 2},
  "COM2" => %{...},
  "COM3" => %{...}
}

Depending on the device and the operating system, not all fields may be returned.

fields are:

  • :vendor_id - The 16-bit USB vendor ID of the device providing the port. Vendor ID to name lists are managed through usb.org
  • :product_id - The 16-bit vendor supplied product ID
  • :manufacturer - The manufacturer of the port
  • :description - A description or product name
  • :serial_number - The device’s serial number if it has one
Link to this function start_link(options \\ []) View Source
start_link([device_option]) :: {:ok, pid} | {:error, term}

Start a new Exbee process.

iex> {:ok, pid} = Exbee.start_link(serial_port: "COM1", speed: 9600)

Options can either be passed directly, or they’ll be read from :exbee config values. The following options are available:

  • :serial_port - The serial interface connected to the Xbee device.
  • :speed - (number) set the initial baudrate (e.g., 115200)
  • :data_bits - (5, 6, 7, 8) set the number of data bits (usually 8)
  • :stop_bits - (1, 2) set the number of stop bits (usually 1)
  • :parity - (:none, :even, :odd, :space, or :mark) set the parity. Usually this is :none. Other values:

    • :space means that the parity bit is always 0
    • :mark means that the parity bit is always 1
  • :flow_control - (:none, :hardware, or :software) set the flow control strategy.

The following are some reasons for which the device may fail to start:

  • :enoent - the specified port couldn’t be found
  • :eagain - the port is already open
  • :eacces - permission was denied when opening the port
Link to this function stop(pid) View Source
stop(pid) :: :ok

Shuts down the device process.