How can I use COM objects with a "parfor" loop via "actxserver"?
조회 수: 1 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2023년 5월 26일
답변: MathWorks Support Team
2023년 6월 5일
I am creating a MATLAB script where I invoke commands on a COM server created with "actxcommand". For example,
MotorCAD_File = 'C:\mymcadfile';
parfor (i = 1:10)
mcad = actxserver('motorcad.appautomation')
invoke(mcad, 'LoadFromFile', [MotorCAD_File '.mot']);
invoke(mcad, 'Quit');
mcad = 0;
end
When I run this code with more than one parallel worker, I get the following error:
Error using MotorCAD_DiaANDMagnet_Mot_Creation
Error: The remote procedure call failed
How can I avoid this error?
채택된 답변
MathWorks Support Team
2023년 5월 26일
When using "actxserver" with a "parfor" loop, it should be defined as a "parallel.pool.Constant", as follows:
a = parallel.pool.Constant(@() actxserver('motorcad.appautomation'));
parfor (i = 1:10)
mcad = a.Value;
invoke(mcad, 'LoadFromFile', [MotorCAD_File '.mot']);
invoke(mcad, 'Quit');
mcad = 0;
end
For more information on "parallel.pool.Constant", please see the following documentation link:
Using the code above, this error should not occur.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Use COM Objects in MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!