I am trying to pass a NET-Object to a function running on a parallel pool in Matlab.
While I thought "parallel.pool.Constant" is the way to do it - as it works fine for other objects (like database connection) - it doesn't work in this case.
As I don't receive an error message, I can't find out why it won't work.
Also the display function doesn't show anything.
Sample-Code:
%% Import Ads.dll
AdsAssembly = NET.addAssembly('D:\TwinCat3\AdsApi\.NET\v4.0.30319\TwinCAT.Ads.dll');
import TwinCAT.Ads.*;
%Create TcAdsClient instance
tcClient = TcAdsClient;
tc = parallel.pool.Constant(tcClient); %Create pool constant to pass object
pool = gcp();
parfeval(pool,@pfcn,0,tc);
function pfcn(tc)
disp(tc.Value);
tcClient = tc.Value;
tcClient.Connect(851); %Connect to ADS port 851 on the local machine
end
An example where it works fine for me (OPC UA Client):
pool = gcp();
Q = parallel.pool.DataQueue;
serverList = opcuaserverinfo('192.168.60.200');
hsInfo = findDescription(serverList, 'K6');
uaClient = opcua(hsInfo);
opc_const = parallel.pool.Constant(uaClient);
parfeval(pool, @pfcn, 0, Q, opc_const);
listener = afterEach(Q, @disp);
function pfcn(Q, opc_const)
par_uaClient = opc_const.Value;
connect(par_uaClient);
conn_state = isConnected(par_uaClient);
send(Q, par_uaClient)
end