Azzera filtri
Azzera filtri

I want to use a backgroudpool to open a class

4 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Walter Roberson
Walter Roberson il 30 Apr 2024
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.

Più risposte (0)

Categorie

Scopri di più su Parallel Computing Fundamentals in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by