Error: OBJ must be connected to the hardware with FOPEN
9 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 28 Sep 2017
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 Comments
See Also
Categories
Find more on Parallel for-Loops (parfor) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!