필터 지우기
필터 지우기

I want to use a backgroudpool to open a class

조회 수: 4 (최근 30일)
Kilian
Kilian 2024년 4월 30일
답변: Walter Roberson 2024년 4월 30일
Hello,
I want to write a Matlab code that controls a device via an API. I want to implemement a Function that runs in the background and records data out of the device.
That is how i start the function in my maincode:
f1 = parfeval(Pool, @Measurement, 0, actualSystemValuesInstance);
The actualSystemValuesInstance variable holds the class needed to request data from the device. This is my function to handle the Task.
function [] = Measurement(actualSystemValuesInstance)
fileID = fopen('data.csv', 'a+');
fmtstr = '%12.12f;%12.12f;%12.12f\r\n';
t = timer();
t.Period = 1;
t.ExecutionMode = 'fixedRate';
t.BusyMode = 'queue';
t.TimerFcn = @recordData;
function recordData(~, ~)
outputcurrent = actualSystemValuesInstance.GetOutputCurrent();
outputvoltage = actualSystemValuesInstance.GetOutputVoltage();
time = now;
fprintf(fileID, fmtstr, outputvoltage, outputcurrent, time);
end
end
My Problem is, that my Function isnt starting because the class is unknown. Is there a diffrent was to hand over the class to my function?
I also tried to opend and define the API with the classes in the background, there i also get an error. Furthermore I tested the same situation with parpool, there I have the same problem that the class arrives empty in my function.
Is it even possible to use parallel Functions in my application?
PS:
I wanted to use the function in the backround, that my measurements cant be blocked by other runtimes in my Maincode and i wanted to try to do it without timer controled interrrupts.

채택된 답변

Walter Roberson
Walter Roberson 2024년 4월 30일
variables that are class members are modeled to be received in the parfeval() as if they were save() and load()
If your class contains volatile fields, those fields generally come out empty on the destination.
actualSystemValuesInstance.GetOutputCurrent()
That has the look of a class that holds volatile fields.
Generally speaking, the way around this is to construct the class object on the destination.

추가 답변 (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