Filter löschen
Filter löschen

I want to use a backgroudpool to open a class

1 Ansicht (letzte 30 Tage)
Kilian am 30 Apr. 2024
Beantwortet: Walter Roberson am 30 Apr. 2024
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);
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?
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.

Antworten (1)

Walter Roberson
Walter Roberson am 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.
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.


Mehr zu Parallel Computing Fundamentals finden Sie in Help Center und File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by