Effacer les filtres
Effacer les filtres

How to use parallel computing for a BytesAvailableFnc of a serial object?

2 vues (au cours des 30 derniers jours)
Oliver Klein
Oliver Klein le 29 Juin 2023
Modifié(e) : Harald le 18 Juil 2023
Hi,
I am using BytesAvailableFcn to read a specific number of bytes from a serial input. On the same time I am using videoinput to record a video and also evaluate the values of the serial input. Because there is so much happening at the same time, the serial bytes are not always read in when they hit the specific number of bytes, so there is a delay.
I want to use the Parallel Computing Toolbox to make the BytesAvailableFcn a background function, which reads the bytes without waiting for other task to finish. How or where can I specify the function as parfeval? Or can I just use parfeval somewhere at the beginning and the function will be compute in the background?
Thank you

Réponse acceptée

Harald
Harald le 30 Juin 2023
Hi Oliver,
you could use the backgroundPool function. This even works without Parallel Computing Toolbox. As soon as you run the parfeval command (you can do so "somewhere at the beginning"), the evaluation of that command starts, and further commands will be run at the same time.
Best wishes,
Harald
  2 commentaires
Oliver Klein
Oliver Klein le 18 Juil 2023
Modifié(e) : Oliver Klein le 18 Juil 2023
So even if I use the BytesAvailableFcn from a serial object, parfeval still works? Or do I have to change my code so there is a background function which starts to read out the serial puffer and doesnt stop. The function which is given to parfeval will be called directly doesnt it?
So is the best version to make the serial object and after that call an independent function through parfeval(backgroundPool, @function) which includes an while(1) and always read out the input buffer of the serial object?
Or is the best version just to call parfeval(backgroundPool, @BytesAvailableFnc) before or after the initialization of the serial object?
I hope my questions are understandable...
Harald
Harald le 18 Juil 2023
Modifié(e) : Harald le 18 Juil 2023
Hi Oliver,
let's put it that way: if you have something that does not work, then please share a code example for it and the problematic behavior (e.g., the full error message). At least for me, that is easier to follow than a lot of words.
In general I would say that the safest way of making sure that the serial input object is available in the function you pass to parfeval is to create it inside that function.
Best wishes,
Harald

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Parallel Computing Fundamentals dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by