Author image Alexander Bluhm
and 4 contributors

NAME

OPCUA::Open62541 - Perl XS wrapper for open62541 OPC UA library

SYNOPSIS

  use OPCUA::Open62541;

  my $server = OPCUA::Open62541::Server->new();

  my $client = OPCUA::Open62541::Client->new();

DESCRIPTION

The open62541 is a library implementing an OPC UA client and server. This module provides access to the C functionality from Perl programs.

EXPORT

Refer to OPCUA::Open62541::Constant module about the exported values.

METHODS

Refer to the open62541 documentation for the semantic of classes and methods.

Variant

$variant = OPCUA::Open62541::Variant->new()
$variant->isEmpty()
$variant->isScalar()
$variant->hasScalarType($data_type)
$variant->hasArrayType($data_type)
$variant->setScalar($p, $data_type)
$data_type = $variant->getType()
$p = $variant->getScalar()

Server

$server = OPCUA::Open62541::Server->new()
$server_config = $server->getConfig()
$status_code = $server->run($server, $running)

$running should be TRUE at statup. When set to FALSE during method invocation, the server stops magically.

$status_code = $server->run_startup($server)
$wait_ms = $server->run_iterate($server, $wait_internal)
$status_code = $server->run_shutdown($server)
$status_code = $server->readValue(\%nodeId, \$outValue)
$status_code = $server->writeValue(\%nodeId, $value)
\%browseResult = $server->browse($maxReferences, \%browseDescription)
$server->setAdminSessionContext($context)

This method is only available if open62541 library supports it.

$status_code = $server->addVariableNode(\%requestedNewNodeId, \%parentNodeId, \%referenceTypeId, \%browseName, \%typeDefinition, \%attr, $nodeContext, \%outNewNodeId)
$status_code = $server->addVariableTypeNode(\%requestedNewNodeId, \%parentNodeId, \%referenceTypeId, \%browseName, \%typeDefinition, \%attr, $nodeContext, \%outNewNodeId)
$status_code = $server->addObjectNode(\%requestedNewNodeId, \%parentNodeId, \%referenceTypeId, \%browseName, \%typeDefinition, \%attr, $nodeContext, \%outNewNodeId)
$status_code = $server->addObjectTypeNode(\%requestedNewNodeId, \%parentNodeId, \%referenceTypeId, \%browseName, \%attr, $nodeContext, \%outNewNodeId)
$status_code = $server->addViewNode(\%requestedNewNodeId, \%parentNodeId, \%referenceTypeId, \%browseName, \%attr, $nodeContext, \%outNewNodeId)
$status_code = $server->addReferenceTypeNode(\%requestedNewNodeId, \%parentNodeId, \%referenceTypeId, \%browseName, \%attr, $nodeContext, \%outNewNodeId)
$status_code = $server->addDataTypeNode(\%requestedNewNodeId, \%parentNodeId, \%referenceTypeId, \%browseName, \%attr, $nodeContext, \%outNewNodeId)
$status_code = $server->deleteNode(\%nodeId, $deleteReferences)
$status_code = $server->addReference(\%sourceId, \%refTypeId, \%targetId, $isForward)
$status_code = $server->deleteReference(\%sourceNodeId, \%referenceTypeId, $isForward, \%targetNodeId, $deleteBidirectional)
$namespace_index = $server->addNamespace($namespace_name)

ServerConfig

$status_code = $server_config->setDefault()
$status_code = $server_config->setMinimal($port, $certificate)
$server_config->setCustomHostname($custom_hostname)
$server_config->setGlobalNodeLifecycle(\%lifecycle)
$lifecycle{GlobalNodeLifecycle_constructor} = sub { my ($server, $sessionId, $sessionContext, $nodeId, \$nodeContext) = @_ }
$lifecycle{GlobalNodeLifecycle_destructor} = sub { my ($server, $sessionId, $sessionContext, $nodeId, $nodeContext) = @_ }
$lifecycle{GlobalNodeLifecycle_createOptionalChild} = sub { my ($server, $sessionId, $sessionContext, $sourceNodeId, $targetParentNodeId, $referenceTypeId) = @_ }
$lifecycle{GlobalNodeLifecycle_generateChildNodeId} = sub { my ($server, $sessionId, $sessionContext, $sourceNodeId, $targetParentNodeId, $referenceTypeId, \%targetNodeId) = @_ }

Call $server->setAdminSessionContext() to set $server and $sessionContext in the callback.

$logger = $server_config->getLogger()
$buildinfo = $server_config->getBuildInfo()

Client

$client = OPCUA::Open62541::Client->new()
$client_config = $client->getConfig()
$status_code = $client->connect($url)
$status_code = $client->connect_async($endpointUrl, $callback, $userdata)
$callback = sub { my ($client, $userdata, $requestId, $status_code) = @_ }

There should be an interval of 100ms between the call to connect_async() and run_iterate() or open62541 may try to operate on a non existent socket.

$status_code = $client->run_iterate($timeout)
$status_code = $client->disconnect()
$status_code = $client->disconnect_async(\$requestId)
$client_state = $client->getState()
$status_code = $client->sendAsyncBrowseRequest(\%request, \&callback, $data, \$reqId)
$callback = sub { my ($client, $userdata, $requestId, \%response) = @_ }
$response = $client->Service_browse(\%request)
$status_code = $client->readDisplayNameAttribute(\%nodeId, \$outDisplayName)
$status_code = $client->readDescriptionAttribute(\%nodeId, \$outDescription)
$status_code = $client->readValueAttribute(\%nodeId, \$outValue)
$status_code = $client->readDataTypeAttribute(\%nodeId, \$outDataType)
$status_code = $client->readValueAttribute_async(\%nodeId, \&callback, $data, \$reqId)
$callback = sub { my ($client, $userdata, $requestId, \%var) = @_ }

ClientConfig

$status_code = $client_config->setDefault()
$logger = $client_config->getLogger()

Logger

The Logger uses the embedded logger of a client or server config. The scope of the logger object may extend the lifetime of the client or sever object. It contains Perl callbacks to the log and clear functions. The log functions are exported to Perl.

$logger->setCallback($log, $context, $clear);
$log = sub { my ($context, $level, $category, $message) = @_ }
$clear = sub { my ($context) = @_ }
$logger->logTrace($category, $msg, ...);
$logger->logDebug($category, $msg, ...);
$logger->logInfo($category, $msg, ...);
$logger->logWarning($category, $msg, ...);
$logger->logError($category, $msg, ...);
$logger->logFatal($category, $msg, ...);

SEE ALSO

OPC UA library, https://open62541.org/

OPC Foundation, https://opcfoundation.org/

OPCUA::Open62541::Constant

AUTHORS

Alexander Bluhm <bluhm@genua.de>, Anton Borowka, Arne Becker, Marvin Knoblauch <mknob@genua.de>,

CAVEATS

This interface is far from complete.

The C types UA_Int64 and UA_UInt64 are implemented as Perl integers IV and UV respectively. This only works for Perl that is compiled on a 64 bit platform. 32 bit platforms are currently not supported.

COPYRIGHT AND LICENSE

Copyright (c) 2020 Alexander Bluhm

Copyright (c) 2020 Anton Borowka

Copyright (c) 2020 Arne Becker

Copyright (c) 2020 Marvin Knoblauch

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

Thanks to genua GmbH, https://www.genua.de/ for sponsoring this work.