What I'm trying to do:
Read ADC (Analog-to-Digital Converter) data transferred through serial ports (COM devices).
With the help of 'read' and 'serialport', I managed to get expected output (verified multiple times, proving that there is nothing wrong with the device or relevant configurations for serial communication).
Next, there's the need to read TWO ADC data SIMULTANEOUSLY, while MATLAB runs the code line by line. Then, I searched and found relevant solutions in Background Processing in Help Center. I uses 'parfeval' and 'fetchOutputs', here is my code:
s = serialport("COM5",4000000,"Timeout",15); % ADC #1 Port
s2 = serialport("COM6",4000000,"Timeout",15); % ADC2 #2 Port
RX2 = parfeval(backgroundPool,@read,1,s2,4e6,'uint8');
rawdata = read(s,4e6,"uint8");
rawdata_2 = fetchOutputs(RX2);
Error code
Error using parallel.Future/fetchOutputs
One or more futures resulted in an error.
Error in DualADC_Sample_Test (line 11)
rawdata_2 = fetchOutputs(RX2);
Caused by:
Undefined function 'read' for input arguments of type 'double'.
Another try
After changing the input argument 4e6
to "4000000"
(as a string) in the "RX2 = ..." line above, it says:
Error using parallel.Future/fetchOutputs
One or more futures resulted in an error.
Error in DualADC_Sample_Test (line 11)
rawdata_2 = fetchOutputs(RX2);
Caused by:
Expected input number 2, count, to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64
Instead its type was string.
My Question
I also tried to transform the number into several other classes, including 'single', 'uint64' etc. All failed, showing Undefined function 'read' for input arguments of type 'single'
, 'uint64'
, etc.
From my attempts, it seems that the software's background processing recognizes the function 'read' correctly, but somehow does not accept this input argument. Is it a bug? or am I missing something here?
I've tried to submit a bug report but Mathwork simply replied 'please offer a valid license'. (Yes, I use a hacked one. I am not proud of that.)
Problem appears in both 2022b and 2023a.