Error: OBJ must be connected to the hardware with FOPEN
9 次查看(过去 30 天)
显示 更早的评论
I want to turn on led and run a function within parfor loop. but it gives an error. Please help me.
delete(instrfind({'Port'},{'COM5'}))
a = arduino('COM5');
pinMode(a,2,'OUTPUT');
parfor i = 1:2
if i==1
digitalWrite(a,2,1);
else
c2(); % any function or another command
end
end
0 个评论
回答(1 个)
Walter Roberson
2017-9-28
parfor sessions are different processes and do not have access to devices opened in the client, if I recall correctly. You need to connect to the arduino within the worker; parfevalOnAll() can be useful for that.
However, you are going to have problems with the resource being busy / resource contention if you attempt to talk to the device from more than one worker.
You should consider using parfeval instead of parfor to run your parallel tasks, communicating back to the client when you need to have something done on the device, perhaps by using a pollable queue (needs a fairly recent version of MATLAB.)
Alternately, use spmd and labSend / labReceive with only one of the workers talking to the device.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!