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

3 次查看(过去 30 天)
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

采纳的回答

Harald
Harald 2023-6-30
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 个评论
Oliver Klein
Oliver Klein 2023-7-18
编辑:Oliver Klein 2023-7-18
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 2023-7-18
编辑:Harald 2023-7-18
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Parallel Computing Fundamentals 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by