View Source OpcUA.Client behaviour (Opex62541 v0.1.4)
OPC UA Client API module.
This module provides functions for configuration, read/write nodes attributes and discovery of a OPC UA Client.
OpcUA.Client
is implemented as a __using__
macro so that you can put it in any module,
you can initialize your Client manually (see test/client_tests
) or by overwriting
configuration/1
and monitored_items/1
to autoset the configuration and subscription items. It also helps you to
handle Client's "subscription" events (monitorItems) by overwriting handle_subscription/2
callback.
The following example shows a module that takes its configuration from the environment (see test/client_tests/terraform_test.exs
):
defmodule MyClient do
use OpcUA.Client
# Use the `init` function to configure your Client.
def init({parent_pid, 103} = _user_init_state, opc_ua_client_pid) do
%{parent_pid: parent_pid, opc_ua_client_pid: opc_ua_client_pid}
end
def configuration(_user_init_state), do: Application.get_env(:my_client, :configuration, [])
def monitored_items(_user_init_state), do: Application.get_env(:my_client, :monitored_items, [])
def handle_subscription_timeout(subscription_id, state) do
send(state.parent_pid, {:subscription_timeout, subscription_id})
state
end
def handle_deleted_subscription(subscription_id, state) do
send(state.parent_pid, {:subscription_delete, subscription_id})
state
end
def handle_monitored_data(changed_data_event, state) do
send(state.parent_pid, {:value_changed, changed_data_event})
state
end
def handle_deleted_monitored_item(subscription_id, monitored_id, state) do
send(state.parent_pid, {:item_deleted, {subscription_id, monitored_id}})
state
end
end
Because it is small a GenServer, it accepts the same options for supervision
to configure the child spec and passes them along to GenServer
:
defmodule MyModule do
use OpcUA.Client, restart: :transient, shutdown: 10_000
end
Summary
Callbacks
Optional callback that gets the Server configuration and discovery connection parameters.
Optional callback that handles a deleted monitored items events.
Optional callback that handles a subscriptions timeout events.
Optional callback that handles node values updates from a Client to a Server.
Optional callback that handles a subscriptions timeout events.
Functions
Adds a monitored item used to request a server for notifications of each change of value in a specific node. The following option must be filled
Sends an OPC UA Server request to start subscription (to monitored items, events, etc).
Returns a specification to start this module under a supervisor.
Connects the OPC UA Client by a url. The following must be filled
Connects the OPC UA Client by a url using a username and a password. The following must be filled
Connects the OPC UA Client by a url without a session. The following must be filled
Adds a monitored item used to request a server for notifications of each change of value in a specific node. The following option must be filled
Sends an OPC UA Server request to delete a subscription.
Disconnects the OPC UA Client.
Finds Servers Connected to a Discovery Server. The following must be filled
Finds Servers Connected to a Discovery Server. The following must be filled
Gets the OPC UA Client current Configuration.
Get endpoints from a OPC UA Server. The following must be filled
Gets the state of the OPC UA Client.
Callback implementation for GenServer.init/1
.
Reads 'Access level' of a node in the server.
Reads 'array_dimensions' of a node in the server.
Reads the browse name attribute of a node in the server.
Reads 'contains_no_loops' attribute of a node in the server.
Reads 'data_type' attribute of a node in the server.
Reads description attribute of a node in the server.
Reads the display name attribute of a node in the server.
Reads 'event_notifier' attribute of a node in the server.
Reads 'Executable' attribute of a node in the server.
Reads 'Historizing' attribute of a node in the server.
Reads 'Inverse name' attribute of a node in the server.
Reads 'Is Abstract' attribute of a node in the server.
Reads 'Minimum Sampling Interval level' of a node in the server.
Reads the node_class attribute of a node in the server.
Reads the node_id attribute of a node in the server.
Reads 'Symmetric' attribute of a node in the server.
Reads 'user_access_level' attribute of a node in the server.
Reads 'user_executable' attribute of a node in the server.
Reads 'user_write_mask' attribute of a node in the server.
Reads 'value' attribute of a node in the server.
Note: If the value is an array you can search a scalar using index
parameter.
Reads 'Value' attribute (matching data type) of a node in the server.
Reads 'value' attribute of a node in the server.
Note: If the value is an array you can search a scalar using index
parameter.
Reads 'Value Rank' of a node in the server.
Reads 'Write Mask' attribute of a node in the server.
Resets the OPC UA Client.
Sets the OPC UA Client configuration.
Sets the OPC UA Client configuration with all security policies for the given certificates. The following must be filled
Starts up a OPC UA Client GenServer.
Stops a OPC UA Client GenServer.
Change 'Access level' of a node in the server.
Change 'Array Dimensions' of a node in the server.
Creates a blank 'value array' attribute of a node in the server. Note: the array must match with 'value_rank' and 'array_dimensions' attribute.
Change the browse name of a node in the server.
Change 'contains_no_loops' attribute of a node in the server.
Change 'data_type' attribute of a node in the server.
Change description attribute of a node in the server.
Change the display name attribute of a node in the server.
Change 'event_notifier' attribute of a node in the server.
Change 'Executable' attribute of a node in the server.
Change 'Historizing' attribute of a node in the server.
Change 'Inverse name' attribute of a node in the server.
Change 'Is Abstract' attribute of a node in the server.
Change 'Minimum Sampling Interval level' of a node in the server.
Change 'node_class' attribute of a node in the server. Avalable value are
Change 'node_id' attribute of a node in the server.
Change 'symmetric' attribute of a node in the server.
Change 'user_access_level' attribute of a node in the server.
Change 'user_executable' attribute of a node in the server.
Change 'user_write_mask' attribute of a node in the server.
Change 'Value' attribute of a node in the server.
Change 'Value rank' of a node in the server.
Change 'Write Mask' attribute of a node in the server.
Types
@type config_options() :: {:config, map()} | {:conn, conn_params()}
@type conn_params() :: {:hostname, binary()} | {:port, non_neg_integer()} | {:users, keyword()}
Callbacks
@callback configuration(term()) :: config_options()
Optional callback that gets the Server configuration and discovery connection parameters.
Optional callback that handles a deleted monitored items events.
It's first argument is the subscription_id
of the subscription that the monitored
item belongs to. The second element is the 'monitored_item_id' which is an unique
number asigned to a monitored item when its created.
The third argument it's the GenServer state (Parent process).
Optional callback that handles a subscriptions timeout events.
It's first argument is the subscription_id
of the subscription.
The second argument it's the GenServer state (Parent process).
Optional callback that handles node values updates from a Client to a Server.
It's first argument is a tuple, in which its first element is the subscription_id
of the subscription that the monitored item belongs to. the second element
is the 'monitored_item_id' which is an unique number asigned to a monitored item when
its created and the third element of the tuple is the new value of the monitored item.
the second argument it's the GenServer state (Parent process).
Optional callback that handles a subscriptions timeout events.
It's first argument is the subscription_id
of the subscription.
The second argument it's the GenServer state (Parent process).
@callback monitored_items(term()) :: monitored_items_options()
Functions
@spec add_monitored_item(GenServer.server(), list()) :: {:ok, integer()} | {:error, term()} | {:error, :einval}
Adds a monitored item used to request a server for notifications of each change of value in a specific node. The following option must be filled:
:subscription_id
-> integer().:monitored_item
-> %NodeId{}.
Sends an OPC UA Server request to start subscription (to monitored items, events, etc).
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec connect_by_url(GenServer.server(), list()) :: :ok | {:error, term()} | {:error, :einval}
Connects the OPC UA Client by a url. The following must be filled:
:url
-> binary().
@spec connect_by_username(GenServer.server(), list()) :: :ok | {:error, term()} | {:error, :einval}
Connects the OPC UA Client by a url using a username and a password. The following must be filled:
:url
-> binary().:user
-> binary().:password
-> binary().
@spec connect_no_session(GenServer.server(), list()) :: :ok | {:error, term()} | {:error, :einval}
Connects the OPC UA Client by a url without a session. The following must be filled:
:url
-> binary().
@spec delete_monitored_item(GenServer.server(), list()) :: :ok | {:error, term()} | {:error, :einval}
Adds a monitored item used to request a server for notifications of each change of value in a specific node. The following option must be filled:
:subscription_id
-> integer().:monitored_item_id
-> integer().
@spec delete_subscription(GenServer.server(), integer()) :: :ok | {:error, term()} | {:error, :einval}
Sends an OPC UA Server request to delete a subscription.
@spec disconnect(GenServer.server()) :: :ok | {:error, term()} | {:error, :einval}
Disconnects the OPC UA Client.
@spec find_servers(GenServer.server(), binary()) :: :ok | {:error, term()} | {:error, :einval}
Finds Servers Connected to a Discovery Server. The following must be filled:
:url
-> binary().
@spec find_servers_on_network(GenServer.server(), binary()) :: :ok | {:error, term()} | {:error, :einval}
Finds Servers Connected to a Discovery Server. The following must be filled:
:url
-> binary().
@spec get_config(GenServer.server()) :: {:ok, map()} | {:error, term()} | {:error, :einval}
Gets the OPC UA Client current Configuration.
@spec get_endpoints(GenServer.server(), binary()) :: :ok | {:error, term()} | {:error, :einval}
Get endpoints from a OPC UA Server. The following must be filled:
:url
-> binary().
@spec get_state(GenServer.server()) :: {:ok, binary()} | {:error, term()} | {:error, :einval}
Gets the state of the OPC UA Client.
Callback implementation for GenServer.init/1
.
@spec read_node_access_level(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: {:ok, integer()} | {:error, binary()} | {:error, :einval}
Reads 'Access level' of a node in the server.
@spec read_node_array_dimensions(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: {:ok, list()} | {:error, binary()} | {:error, :einval}
Reads 'array_dimensions' of a node in the server.
@spec read_node_browse_name(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: {:ok, %OpcUA.QualifiedName{name: term(), ns_index: term()}} | {:error, binary()} | {:error, :einval}
Reads the browse name attribute of a node in the server.
@spec read_node_contains_no_loops(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: {:ok, {binary(), binary()}} | {:error, binary()} | {:error, :einval}
Reads 'contains_no_loops' attribute of a node in the server.
@spec read_node_data_type(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: {:ok, %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}} | {:error, binary()} | {:error, :einval}
Reads 'data_type' attribute of a node in the server.
@spec read_node_description(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: {:ok, {binary(), binary()}} | {:error, binary()} | {:error, :einval}
Reads description attribute of a node in the server.
@spec read_node_display_name(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: {:ok, {binary(), binary()}} | {:error, binary()} | {:error, :einval}
Reads the display name attribute of a node in the server.
@spec read_node_event_notifier(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: {:ok, term()} | {:error, binary()} | {:error, :einval}
Reads 'event_notifier' attribute of a node in the server.
@spec read_node_executable(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: {:ok, boolean()} | {:error, binary()} | {:error, :einval}
Reads 'Executable' attribute of a node in the server.
@spec read_node_historizing(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: {:ok, boolean()} | {:error, binary()} | {:error, :einval}
Reads 'Historizing' attribute of a node in the server.
@spec read_node_inverse_name(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: {:ok, {binary(), binary()}} | {:error, binary()} | {:error, :einval}
Reads 'Inverse name' attribute of a node in the server.
@spec read_node_is_abstract(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: {:ok, boolean()} | {:error, binary()} | {:error, :einval}
Reads 'Is Abstract' attribute of a node in the server.
@spec read_node_minimum_sampling_interval(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: {:ok, integer()} | {:error, binary()} | {:error, :einval}
Reads 'Minimum Sampling Interval level' of a node in the server.
@spec read_node_node_class(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: {:ok, %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}} | {:error, binary()} | {:error, :einval}
Reads the node_class attribute of a node in the server.
@spec read_node_node_id(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: {:ok, %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}} | {:error, binary()} | {:error, :einval}
Reads the node_id attribute of a node in the server.
@spec read_node_symmetric(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: {:ok, boolean()} | {:error, binary()} | {:error, :einval}
Reads 'Symmetric' attribute of a node in the server.
@spec read_node_user_access_level(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: :ok | {:error, binary()} | {:error, :einval}
Reads 'user_access_level' attribute of a node in the server.
@spec read_node_user_executable(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: :ok | {:error, binary()} | {:error, :einval}
Reads 'user_executable' attribute of a node in the server.
@spec read_node_user_write_mask(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: :ok | {:error, binary()} | {:error, :einval}
Reads 'user_write_mask' attribute of a node in the server.
@spec read_node_value( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, integer() ) :: {:ok, term()} | {:error, binary()} | {:error, :einval}
Reads 'value' attribute of a node in the server.
Note: If the value is an array you can search a scalar using index
parameter.
@spec read_node_value_by_data_type( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, integer() ) :: {:ok, term()} | {:error, binary()} | {:error, :einval}
Reads 'Value' attribute (matching data type) of a node in the server.
@spec read_node_value_by_index( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, integer() ) :: {:ok, term()} | {:error, binary()} | {:error, :einval}
Reads 'value' attribute of a node in the server.
Note: If the value is an array you can search a scalar using index
parameter.
@spec read_node_value_rank(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: {:ok, integer()} | {:error, binary()} | {:error, :einval}
Reads 'Value Rank' of a node in the server.
@spec read_node_write_mask(GenServer.server(), %OpcUA.NodeId{ identifier: term(), identifier_type: term(), ns_index: term() }) :: {:ok, integer()} | {:error, binary()} | {:error, :einval}
Reads 'Write Mask' attribute of a node in the server.
@spec reset(GenServer.server()) :: :ok | {:error, term()} | {:error, :einval}
Resets the OPC UA Client.
@spec set_config(GenServer.server(), map()) :: :ok | {:error, term()} | {:error, :einval}
Sets the OPC UA Client configuration.
@spec set_config_with_certs(GenServer.server(), list()) :: :ok | {:error, term()} | {:error, :einval}
Sets the OPC UA Client configuration with all security policies for the given certificates. The following must be filled:
* `:private_key` -> binary() or function().
* `:certificate` -> binary() or function().
* `:security_mode` -> interger().
NOTE: [none: 1, sign: 2, sign_and_encrypt: 3]
Starts up a OPC UA Client GenServer.
@spec stop(GenServer.server()) :: :ok
Stops a OPC UA Client GenServer.
@spec write_node_access_level( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, integer() ) :: :ok | {:error, binary()} | {:error, :einval}
Change 'Access level' of a node in the server.
@spec write_node_array_dimensions( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, list() ) :: :ok | {:error, binary()} | {:error, :einval}
Change 'Array Dimensions' of a node in the server.
@spec write_node_blank_array( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, integer(), list() ) :: :ok | {:error, binary()} | {:error, :einval}
Creates a blank 'value array' attribute of a node in the server. Note: the array must match with 'value_rank' and 'array_dimensions' attribute.
@spec write_node_browse_name( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, %OpcUA.QualifiedName{name: term(), ns_index: term()} ) :: :ok | {:error, binary()} | {:error, :einval}
Change the browse name of a node in the server.
@spec write_node_contains_no_loops( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, boolean() ) :: :ok | {:error, binary()} | {:error, :einval}
Change 'contains_no_loops' attribute of a node in the server.
@spec write_node_data_type( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()} ) :: :ok | {:error, binary()} | {:error, :einval}
Change 'data_type' attribute of a node in the server.
@spec write_node_description( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, binary(), binary() ) :: :ok | {:error, binary()} | {:error, :einval}
Change description attribute of a node in the server.
@spec write_node_display_name( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, binary(), binary() ) :: :ok | {:error, binary()} | {:error, :einval}
Change the display name attribute of a node in the server.
@spec write_node_event_notifier( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, integer() ) :: :ok | {:error, binary()} | {:error, :einval}
Change 'event_notifier' attribute of a node in the server.
@spec write_node_executable( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, boolean() ) :: :ok | {:error, binary()} | {:error, :einval}
Change 'Executable' attribute of a node in the server.
@spec write_node_historizing( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, boolean() ) :: :ok | {:error, binary()} | {:error, :einval}
Change 'Historizing' attribute of a node in the server.
@spec write_node_inverse_name( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, binary(), binary() ) :: :ok | {:error, binary()} | {:error, :einval}
Change 'Inverse name' attribute of a node in the server.
@spec write_node_is_abstract( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, boolean() ) :: :ok | {:error, binary()} | {:error, :einval}
Change 'Is Abstract' attribute of a node in the server.
write_node_minimum_sampling_interval(pid, node_id, minimum_sampling_interval)
View Source@spec write_node_minimum_sampling_interval( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, integer() ) :: :ok | {:error, binary()} | {:error, :einval}
Change 'Minimum Sampling Interval level' of a node in the server.
@spec write_node_node_class( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, integer() ) :: :ok | {:error, binary()} | {:error, :einval}
Change 'node_class' attribute of a node in the server. Avalable value are:
UNSPECIFIED = 0,
OBJECT = 1,
VARIABLE = 2,
METHOD = 4,
OBJECTTYPE = 8,
VARIABLETYPE = 16,
REFERENCETYPE = 32,
DATATYPE = 64,
VIEW = 128,
@spec write_node_node_id( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()} ) :: :ok | {:error, binary()} | {:error, :einval}
Change 'node_id' attribute of a node in the server.
@spec write_node_symmetric( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, boolean() ) :: :ok | {:error, binary()} | {:error, :einval}
Change 'symmetric' attribute of a node in the server.
@spec write_node_user_access_level( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, integer() ) :: :ok | {:error, binary()} | {:error, :einval}
Change 'user_access_level' attribute of a node in the server.
@spec write_node_user_executable( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, boolean() ) :: :ok | {:error, binary()} | {:error, :einval}
Change 'user_executable' attribute of a node in the server.
@spec write_node_user_write_mask( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, integer() ) :: :ok | {:error, binary()} | {:error, :einval}
Change 'user_write_mask' attribute of a node in the server.
Change 'Value' attribute of a node in the server.
@spec write_node_value_rank( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, integer() ) :: :ok | {:error, binary()} | {:error, :einval}
Change 'Value rank' of a node in the server.
This attribute indicates whether the value attribute of the variable is an array and how many dimensions the array has. It may have the following values:
value_rank >= 1: the value is an array with the specified number of dimensions value_rank = 0: the value is an array with one or more dimensions value_rank = -1: the value is a scalar value_rank = -2: the value can be a scalar or an array with any number of dimensions value_rank = -3: the value can be a scalar or a one dimensional array
@spec write_node_write_mask( GenServer.server(), %OpcUA.NodeId{identifier: term(), identifier_type: term(), ns_index: term()}, integer() ) :: :ok | {:error, binary()} | {:error, :einval}
Change 'Write Mask' attribute of a node in the server.