Using parfeval to read values from OPC-UA server?

13 visualizaciones (últimos 30 días)
Ilkka
Ilkka el 6 de Mzo. de 2025
Respondida: Walter Roberson el 6 de Mzo. de 2025
Hi!
I am trying to read data from an OPC-UA server in background using parfeval. I have a local OPC-UA simulation server running and the connection and reading values in the main thread works nicely. However, upon executing the readValue function in backgroundPool using parfeval with the needed input arguments (i.e. a connected uaClient and list of nodes), the FevalFuture results in an error "OPC UA Client must be connected to perform this operation".
You can find minimum working code example below:
uaClient = opcua('localhost',53530); % Local OPC-UA simulation server
connect(uaClient);
namespace = browseNamespace(uaClient); % Browse for OPC-UA server namespace
nodes = getAllChildren(namespace); % Get a list of data nodes
values = readValue(nodes); % Test reading values from the data nodes using readValue --> Works well
% Test reading the values in background using parfeval:
readFuture = parfeval(backgroundPool, @readValue, 1, uaClient, nodes) % --> Error, "OPC UA Client must be connected to perform this operation"
It seems that the connection to OPC-UA server is not maintained when providing the uaClient as an input to parfeval. Is there a way to solve this?

Respuesta aceptada

Walter Roberson
Walter Roberson el 6 de Mzo. de 2025

chances are high that opcua creates state variables that cannot be save() and load(), which is required in order to pass objects to process based pools. Process based pools execute in separate processes with their own address space, so variables cannot be simply passed into them and must instead go through an internal save/load cycle. opcua probably uses internal memory allocated in C++, and that memory does not get save()

What you need to do is create the opcua object on the worker.

Más respuestas (0)

Etiquetas

Productos


Versión

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by