Running function in parallel on App Designer
32 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I'm building an app which suppose to capture images from the camera while doing more things in parallel. I'm using 'parfeval' to run the function in the background and 'afterEach' to print it every time an image is captured.
Those are the functions:
methods (Access = private)
function getFrameFromCamera(app)
h = msgbox("Connecting to camera..", "Message");
app.Cam = gigecam(app.ip);
app.Cam.PixelFormat = 'BayerGB8';
app.Cam.Timeout = 15;
app.Cam.GevSCPSPacketSize = 1200;
app.Cam.Width = 1920;
app.Cam.Height = 1080;
app.Cam.CenterX = 'True';
app.Cam.CenterY = 'True';
delete(h);
while true
app.tmpImage = snapshot(app.Cam);
send(app.D, app);
end
end
function processDisp(app)
app.Image3.ImageSource = app.tmpImage;
end
end
The code in the button's function:
function ConnectButtonPushed(app, event)
app.ConnectedLamp.Color = 'yellow';
pause(0.05);
try
if ~isempty(app.CameraIPListBox.Value)
h = msgbox("Checking if the camera is available..", "Message");
app.ip = app.CameraIPListBox.Value;
gigecam(app.ip);
delete(h);
h = msgbox("Starting parallel pool (parpool) using the 'local' profile..", "Message");
imaqreset;
delete(gcp('nocreate'));
parpool('local', 1);
app.D = parallel.pool.DataQueue;
afterEach(app.D, @processDisp);
%app.Process = 0;
delete(h);
app.f = parfeval(@getFrameFromCamera, 0, app);
app.ConnectedLamp.Color = 'green';
end
catch
delete(h);
app.ConnectedLamp.Color = 'red';
msgbox("The camera is in use.", "Error");
end
end
For some reason, i get this warning twice and the functions don't excecute:
Warning: Unable to save App Designer app object. Save not supported for matlab.apps.AppBase objects
I tried to run in the background simple functions which only print and i still get the same results. I also tried to send every variable seperatly, and not the "app" variable - same results. Any idea how to solve this?
4 Commenti
Mario Malic
il 29 Mar 2021
Interesting. It's great that it works! It would be great if you could share the code as an answer, as I'm also interested in this.
Risposte (0)
Vedere anche
Categorie
Scopri di più su MATLAB Support Package for IP Cameras in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!