tm_mercury v0.6.0 TM.Mercury.Reader
Link to this section Summary
Functions
Execute the reader's bootloader
Execute the reader's firmware from the bootloader
Returns a specification to start this module under a supervisor
Clear the tag buffer
Enumerate the logical antenna ports and report the antenna detection status of each one
Invoked in order to access the value stored under key
in the given term term
Invoked in order to access the value under key
and update it at the same time
Return the antenna port configuration used by the reader
Return the antenna return loss of logical antenna ports
Return the identity of the program currently running on the device
Return the current value of an optional reader parameter with a given key
Get the power-consumption mode of the reader
Get the current TX power for reading tags in centi-dBm
Return the RF regulatory environment that the reader will operate within
Return the tags that have accumulated in the reader's buffer while waiting on a synchronous read timeout to expire
Return the tag protocol used by the reader
Get the radio's temperature
Return the current TX and RX antenna port
Return hardware, firmware, and bootloader version details
Catch-all handlers for op commands that don't require state binding or special handling
Invoked when the server is started. start_link/3
or start/3
will
block until it returns
Invoked to "pop" the value under key
out of the given data structure
Start reading tags asynchronously using a custom read plan.
Tag reads will be sent to the process with pid listener
until stop_read_async
is called
Stop reading tags asynchronously
Read tags synchronously using a read plan and timeout
Reboot the reader
Disconnect the reader
Set the antenna port configuration used by the reader
Set the reader's serial baud rate
Set the value of an optional reader parameter with a given key
Set the power-consumption mode of the reader
Set the current TX power for reading tags in centi-dBm
Set the RF regulatory environment that the reader will operate within
Set the tag protocol used by the reader
Start a process and open a connection with the reader over UART connected via TTL / USB
Return the reader's transport connection status
Link to this section Types
command_result()
command_result() :: :ok
command_result() :: :ok
error()
error() :: {:error, term()}
error() :: {:error, term()}
query_result()
query_result() :: {:ok, term()}
query_result() :: {:ok, term()}
read_plan()
read_plan() ::
TM.Mercury.SimpleReadPlan.t() | TM.Mercury.StopTriggerReadPlan.t()
read_plan() :: TM.Mercury.SimpleReadPlan.t() | TM.Mercury.StopTriggerReadPlan.t()
read_timeout()
read_timeout() :: pos_integer()
read_timeout() :: pos_integer()
Link to this section Functions
boot_bootloader(pid)
boot_bootloader(pid()) :: command_result() | error()
boot_bootloader(pid()) :: command_result() | error()
Execute the reader's bootloader.
boot_firmware(pid)
boot_firmware(pid()) :: command_result() | error()
boot_firmware(pid()) :: command_result() | error()
Execute the reader's firmware from the bootloader.
child_spec(init_arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
clear_tag_id_buffer(pid)
clear_tag_id_buffer(pid()) :: command_result() | error()
clear_tag_id_buffer(pid()) :: command_result() | error()
Clear the tag buffer.
detect_antennas(pid)
Enumerate the logical antenna ports and report the antenna detection status of each one.
fetch(term, key)
Invoked in order to access the value stored under key
in the given term term
.
This function should return {:ok, value}
where value
is the value under
key
if the key exists in the term, or :error
if the key does not exist in
the term.
Many of the functions defined in the Access
module internally call this
function. This function is also used when the square-brackets access syntax
(structure[key]
) is used: the fetch/2
callback implemented by the module
that defines the structure
struct is invoked and if it returns {:ok, value}
then value
is returned, or if it returns :error
then nil
is
returned.
See the Map.fetch/2
and Keyword.fetch/2
implementations for examples of
how to implement this callback.
Callback implementation for Access.fetch/2
.
get(structure, key, default)
get_and_update(data, key, function)
Invoked in order to access the value under key
and update it at the same time.
The implementation of this callback should invoke fun
with the value under
key
in the passed structure data
, or with nil
if key
is not present in it.
This function must return either {get_value, update_value}
or :pop
.
If the passed function returns {get_value, update_value}
,
the return value of this callback should be {get_value, new_data}
, where:
get_value
is the retrieved value (which can be operated on before being returned)update_value
is the new value to be stored underkey
new_data
isdata
after updating the value ofkey
withupdate_value
.
If the passed function returns :pop
, the return value of this callback
must be {value, new_data}
where value
is the value under key
(or nil
if not present) and new_data
is data
without key
.
See the implementations of Map.get_and_update/3
or Keyword.get_and_update/3
for more examples.
Callback implementation for Access.get_and_update/3
.
get_antenna_port(pid)
get_antenna_port(pid()) :: query_result() | error()
get_antenna_port(pid()) :: query_result() | error()
Return the antenna port configuration used by the reader
get_antenna_return_loss(pid)
Return the antenna return loss of logical antenna ports.
get_current_program(pid)
get_current_program(pid()) :: query_result() | error()
get_current_program(pid()) :: query_result() | error()
Return the identity of the program currently running on the device.
get_param(pid, key)
get_param(pid(), atom()) :: query_result() | error()
get_param(pid(), atom()) :: query_result() | error()
Return the current value of an optional reader parameter with a given key.
get_power_mode(pid)
get_power_mode(pid()) :: query_result() | error()
get_power_mode(pid()) :: query_result() | error()
Get the power-consumption mode of the reader.
This is not related to the TX/RX power.
get_read_tx_power(pid)
get_read_tx_power(pid()) :: query_result() | error()
get_read_tx_power(pid()) :: query_result() | error()
Get the current TX power for reading tags in centi-dBm.
Examples
iex> TM.Mercury.Reader.get_read_tx_power(pid)
{:ok, 2500} # 25 dBm
get_reader_stats(pid, option, flags)
TODO
get_region(pid)
get_region(pid()) :: query_result() | error()
get_region(pid()) :: query_result() | error()
Return the RF regulatory environment that the reader will operate within.
get_tag_id_buffer(pid, metadata_flags)
get_tag_id_buffer(pid(), list()) :: query_result() | error()
get_tag_id_buffer(pid(), list()) :: query_result() | error()
Return the tags that have accumulated in the reader's buffer while waiting on a synchronous read timeout to expire.
get_tag_protocol(pid)
get_tag_protocol(pid()) :: query_result() | error()
get_tag_protocol(pid()) :: query_result() | error()
Return the tag protocol used by the reader
get_temperature(pid)
get_temperature(pid()) :: query_result() | error()
get_temperature(pid()) :: query_result() | error()
Get the radio's temperature
get_tx_rx_ports(pid)
Return the current TX and RX antenna port.
get_version(pid)
get_version(pid()) :: query_result() | error()
get_version(pid()) :: query_result() | error()
Return hardware, firmware, and bootloader version details.
handle_call(msg, from, state)
Catch-all handlers for op commands that don't require state binding or special handling
init(arg)
Invoked when the server is started. start_link/3
or start/3
will
block until it returns.
init_arg
is the argument term (second argument) passed to start_link/3
.
Returning {:ok, state}
will cause start_link/3
to return
{:ok, pid}
and the process to enter its loop.
Returning {:ok, state, timeout}
is similar to {:ok, state}
except handle_info(:timeout, state)
will be called after timeout
milliseconds if no messages are received within the timeout.
Returning {:ok, state, :hibernate}
is similar to {:ok, state}
except the process is hibernated before entering the loop. See
c:handle_call/3
for more information on hibernation.
Returning {:ok, state, {:continue, continue}}
is similar to
{:ok, state}
except that immediately after entering the loop
the c:handle_continue/2
callback will be invoked with the value
continue
as first argument.
Returning :ignore
will cause start_link/3
to return :ignore
and
the process will exit normally without entering the loop or calling
c:terminate/2
. If used when part of a supervision tree the parent
supervisor will not fail to start nor immediately try to restart the
GenServer
. The remainder of the supervision tree will be started
and so the GenServer
should not be required by other processes.
It can be started later with Supervisor.restart_child/2
as the child
specification is saved in the parent supervisor. The main use cases for
this are:
- The
GenServer
is disabled by configuration but might be enabled later. - An error occurred and it will be handled by a different mechanism than the
Supervisor
. Likely this approach involves callingSupervisor.restart_child/2
after a delay to attempt a restart.
Returning {:stop, reason}
will cause start_link/3
to return
{:error, reason}
and the process to exit with reason reason
without
entering the loop or calling c:terminate/2
.
Callback implementation for GenServer.init/1
.
pop(data, key)
Invoked to "pop" the value under key
out of the given data structure.
When key
exists in the given structure data
, the implementation should
return a {value, new_data}
tuple where value
is the value that was under
key
and new_data
is term
without key
.
When key
is not present in the given structure, a tuple {value, data}
should be returned, where value
is implementation-defined.
See the implementations for Map.pop/3
or Keyword.pop/3
for more examples.
Callback implementation for Access.pop/2
.
read_async_start(pid, listener, on_time_ms \\ 100, off_time_ms \\ 400, rp \\ %{__struct__: TM.Mercury.SimpleReadPlan, antennas: {1, 1}, autonomous_read: false, fast_search: false, filter: "", protocol: :gen2, tag_op: nil, weight: 1000}, rate_limit \\ :infinity)
read_async_start(
pid(),
pid(),
pos_integer(),
pos_integer(),
read_plan(),
timeout()
) :: query_result() | error()
read_async_start( pid(), pid(), pos_integer(), pos_integer(), read_plan(), timeout() ) :: query_result() | error()
Start reading tags asynchronously using a custom read plan.
Tag reads will be sent to the process with pid listener
until stop_read_async
is called.
If on_time_ms
is not provided, it will default to 100
.
If off_time_ms
is not provided, it will default to 400
.
If a read plan is not provided, it will default to SimpleReadPlan
.
read_async_stop(pid)
Stop reading tags asynchronously
read_sync(pid, timeout_ms \\ 100, rp \\ %{__struct__: TM.Mercury.SimpleReadPlan, antennas: {1, 1}, autonomous_read: false, fast_search: false, filter: "", protocol: :gen2, tag_op: nil, weight: 1000})
read_sync(pid(), read_timeout(), read_plan()) :: query_result() | error()
read_sync(pid(), read_timeout(), read_plan()) :: query_result() | error()
Read tags synchronously using a read plan and timeout.
If a timeout is not provided, it will default to 100
.
If a read plan is not provided, it will default to SimpleReadPlan
.
reboot(pid)
reboot(pid()) :: command_result() | error()
reboot(pid()) :: command_result() | error()
Reboot the reader.
reconnect(pid)
reconnect(pid()) :: command_result() | error()
reconnect(pid()) :: command_result() | error()
Disconnect the reader.
The connection will be restarted.
reset_reader_stats(pid, flags)
TODO
set_antenna_port(pid, ports)
set_antenna_port(pid(), term()) :: command_result() | error()
set_antenna_port(pid(), term()) :: command_result() | error()
Set the antenna port configuration used by the reader
set_baud_rate(pid, rate)
set_baud_rate(pid(), pos_integer()) :: command_result() | error()
set_baud_rate(pid(), pos_integer()) :: command_result() | error()
Set the reader's serial baud rate.
The host's baud rate must be changed separately.
set_param(pid, key, value)
set_param(pid(), atom(), term()) :: query_result() | error()
set_param(pid(), atom(), term()) :: query_result() | error()
Set the value of an optional reader parameter with a given key.
set_power_mode(pid, mode)
set_power_mode(pid(), atom()) :: command_result() | error()
set_power_mode(pid(), atom()) :: command_result() | error()
Set the power-consumption mode of the reader.
set_read_tx_power(pid, level)
set_read_tx_power(pid(), number()) :: command_result() | error()
set_read_tx_power(pid(), number()) :: command_result() | error()
Set the current TX power for reading tags in centi-dBm.
Examples
iex> TM.Mercury.Reader.set_read_tx_power(pid, 2500) # 25 dBm
:ok
set_region(pid, region)
set_region(pid(), atom()) :: command_result() | error()
set_region(pid(), atom()) :: command_result() | error()
Set the RF regulatory environment that the reader will operate within.
set_tag_protocol(pid, protocol)
set_tag_protocol(pid(), atom()) :: command_result() | error()
set_tag_protocol(pid(), atom()) :: command_result() | error()
Set the tag protocol used by the reader
start_link(device, opts \\ [])
Start a process and open a connection with the reader over UART connected via TTL / USB
The reader requires the following parameters:
device
- the device file for the reader serial connection.
Optional Parameters
The following keys are optional:
speed
- the serial port speed. Defaults to115200
.region
- the regulatory RF environment used by the reader. Defaults to:na
(North America).:none
- Unspecified region:na
- North America:eu
- European Union:kr
- Korea:in
- India:jp
- Japan:prc
- People's Republic of China:eu2
- European Union 2:eu3
- European Union 3:kr2
- Korea 2:prc2
- People's Republic of China (840 MHz):au
- Australia:nz
- New Zealand (Experimental):na2
- Reduced FCC region:na3
- 5 MHz FCC band:open
- Open
power_mode
- the power-consumption mode of the reader. Defaults to:full
.:full
:min_save
:med_save
:max_save
:sleep
status(pid)
Return the reader's transport connection status