Current section

Files

Jump to
klf200 lib klf200.ex
Raw

lib/klf200.ex

defmodule Klf200 do
@moduledoc """
Documentation for `Klf200`.
"""
@doc """
Connect to KLF 200 device
"""
def connect(ip, pw) do
# not matching on other return errors on purpose and let it crash instead
case Klf200.Client.start_link() do
{:ok, pid} -> pid
{:error, {:already_started, pid}} -> pid
end
:ok = Klf200.Client.connect(ip)
:ok = Klf200.Client.login(pw)
Klf200.Client.command(:GW_GET_ALL_NODES_INFORMATION_REQ)
end
def nodes() do
Klf200.Client.command(:GW_GET_ALL_NODES_INFORMATION_REQ)
Klf200.Client.nodes()
end
def position(%{node: node}, pos) when is_integer(node) and is_integer(pos), do: position(node, pos)
def position(node, pos) when is_integer(node) and is_integer(pos) do
Klf200.Client.command(:GW_COMMAND_SEND_REQ, %{node: node, position: pos})
end
def disconnect do
Klf200.Client.disconnect()
end
end