OPCUA-Open62541

 view release on metacpan or  search on metacpan

lib/OPCUA/Open62541/Client.pm  view on Meta::CPAN

package OPCUA::Open62541::Client;

use strict;
use warnings;
require Exporter;
use parent 'Exporter';

use OPCUA::Open62541 qw(:ATTRIBUTEID :BROWSERESULTMASK :NODECLASS :NODEIDTYPE);

my %mapping_nodeclass_attributes;
# Base NodeClass
for (
    NODECLASS_OBJECT,
    NODECLASS_VARIABLE,
    NODECLASS_METHOD,
    NODECLASS_OBJECTTYPE,
    NODECLASS_VARIABLETYPE,
    NODECLASS_REFERENCETYPE,
    NODECLASS_DATATYPE,
    NODECLASS_VIEW
 ) {
    $mapping_nodeclass_attributes{$_}{ATTRIBUTEID_NODEID()} = 'm';
    $mapping_nodeclass_attributes{$_}{ATTRIBUTEID_NODECLASS()} = 'm';
    $mapping_nodeclass_attributes{$_}{ATTRIBUTEID_BROWSENAME()} = 'm';
    $mapping_nodeclass_attributes{$_}{ATTRIBUTEID_DISPLAYNAME()} = 'm';
    $mapping_nodeclass_attributes{$_}{ATTRIBUTEID_DESCRIPTION()} = 'o';
    $mapping_nodeclass_attributes{$_}{ATTRIBUTEID_WRITEMASK()} = 'o';
    $mapping_nodeclass_attributes{$_}{ATTRIBUTEID_USERWRITEMASK()} = 'o';
    $mapping_nodeclass_attributes{$_}{ATTRIBUTEID_ROLEPERMISSIONS()} = 'o';
    $mapping_nodeclass_attributes{$_}{ATTRIBUTEID_USERROLEPERMISSIONS()} = 'o';
    $mapping_nodeclass_attributes{$_}{ATTRIBUTEID_ACCESSRESTRICTIONS()} = 'o';
}

# ReferenceType NodeClass
$mapping_nodeclass_attributes{NODECLASS_REFERENCETYPE()}{ATTRIBUTEID_ISABSTRACT()} = 'm';
$mapping_nodeclass_attributes{NODECLASS_REFERENCETYPE()}{ATTRIBUTEID_SYMMETRIC()} = 'm';
$mapping_nodeclass_attributes{NODECLASS_REFERENCETYPE()}{ATTRIBUTEID_INVERSENAME()} = 'o';

# View NodeClass
$mapping_nodeclass_attributes{NODECLASS_VIEW()}{ATTRIBUTEID_CONTAINSNOLOOPS()} = 'm';
$mapping_nodeclass_attributes{NODECLASS_VIEW()}{ATTRIBUTEID_EVENTNOTIFIER()} = 'm';

# Object NodeClass
$mapping_nodeclass_attributes{NODECLASS_OBJECT()}{ATTRIBUTEID_EVENTNOTIFIER()} = 'm';

# Variable NodeClass
$mapping_nodeclass_attributes{NODECLASS_VARIABLE()}{ATTRIBUTEID_VALUE()} = 'm';
$mapping_nodeclass_attributes{NODECLASS_VARIABLE()}{ATTRIBUTEID_DATATYPE()} = 'm';
$mapping_nodeclass_attributes{NODECLASS_VARIABLE()}{ATTRIBUTEID_VALUERANK()} = 'm';
$mapping_nodeclass_attributes{NODECLASS_VARIABLE()}{ATTRIBUTEID_ARRAYDIMENSIONS()} = 'o';
$mapping_nodeclass_attributes{NODECLASS_VARIABLE()}{ATTRIBUTEID_ACCESSLEVEL()} = 'm';
$mapping_nodeclass_attributes{NODECLASS_VARIABLE()}{ATTRIBUTEID_USERACCESSLEVEL()} = 'm';
$mapping_nodeclass_attributes{NODECLASS_VARIABLE()}{ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL()} = 'o';
$mapping_nodeclass_attributes{NODECLASS_VARIABLE()}{ATTRIBUTEID_HISTORIZING()} = 'm';
$mapping_nodeclass_attributes{NODECLASS_VARIABLE()}{ATTRIBUTEID_ACCESSLEVELEX()} = 'o';

# Method NodeClass
$mapping_nodeclass_attributes{NODECLASS_METHOD()}{ATTRIBUTEID_EXECUTABLE()} = 'm';
$mapping_nodeclass_attributes{NODECLASS_METHOD()}{ATTRIBUTEID_USEREXECUTABLE()} = 'm';

# export mapping between nodeclass and valid attribute IDs
sub get_mapping_nodeclass_attributeid { %mapping_nodeclass_attributes };

our @EXPORT_OK = qw(get_mapping_nodeclass_attributeid);

my %attributeid_ids = OPCUA::Open62541::get_mapping_attributeid_ids;

# read namespace array and return list of names
sub get_namespaces {
    my $self = shift;

    my ($value) = $self->get_attributes({
	NodeId_namespaceIndex => 0,
	NodeId_identifierType => NODEIDTYPE_NUMERIC,
	NodeId_identifier     => OPCUA::Open62541::NS0ID_SERVER_NAMESPACEARRAY,
    }, 'value');

    return @{$value->{DataValue_value}{Variant_array} // []};
}

# read attributes for node ID
# allows ATTRIBUTE IDs and names
sub get_attributes {
    my ($self, $nodeid, @attributes) = @_;

    # is there any default that
    die 'no attributes for get_attributes'
	if not @attributes;

    # convert attribute names to IDs
    @attributes = map { $attributeid_ids{$_} // $_ } @attributes;

    my $response = $self->Service_read({
	ReadRequest_nodesToRead => [
	    map {
		{ReadValueId_nodeId => $nodeid, ReadValueId_attributeId => $_}
	    } @attributes



( run in 0.906 second using v1.01-cache-2.11-cpan-e1769b4cff6 )