Using public class methods and libraries in parfeval()
Show older comments
Hello everyone,
I've been googling the entire day, but nobody seems to have quite the same problem as myself at the moment.
I've programmed a matlab-class to communicate to a USB-SPI Interface Chip via the provided drivers. No Problem here. I can execute everything and read and write Data properly and quickly.
My Problem starts, as soon as I start to put this Code into a parallel pool. Since it's some very active Code (i.e. polling of IO-Pins and such) I need it to run separately from everything else.
My Code:
Firstly, I open the (properly working outside of a parallel pool) Class:
% Open ACCELEROMETER Class
ACC = ADXL372;
% Configure both Channels, as per documentation
[P1,C1]=ACC.ADXL_Config(1);
[P2,C2]=ACC.ADXL_Config(2);
My constructor looks as follows:
function ADXL = ADXL372()
if ~libisloaded( ADXL.Libname )
loadlibrary( ADXL.Libname, 'libMPSSE_spi_matlabFriendly.h');
end
if ~libisloaded( ADXL.Libname2 )
loadlibrary( ADXL.Libname2);
end
clc
% Get the number of SPI channels available.
calllib(ADXL.Libname,'SPI_GetNumChannels',ADXL.pNumchannels);
disp(['Channels Found: ', num2str(get(ADXL.pNumchannels,'value'))]);
% Connect to SPI channel 0. Valid numbers are 0:(Numchannels-1).
E = calllib(ADXL.Libname,'SPI_OpenChannel',0,ADXL.pChannelHandle);
disp(['Channel Opened with Errorcode: ', num2str(E)]);
% Set GPIO for Receiving Interrupt
E=calllib(ADXL.Libname,'FT_WriteGPIO',ADXL.pChannelHandle,0,0);
disp(['GPIO Set with Errorcode: ',num2str(E)]);
% Set Latency Timer to 1ms
E=calllib(ADXL.Libname2,'FT_SetLatencyTimer',ADXL.pChannelHandle,1);
disp(['LatencyTimer Set with Errorcode: ',num2str(E)]);
% Define the channel configuration struct, and initialize the channel.
ChConfig.ClockRate = uint32(10e6); % Clock speed, Hz
ChConfig.LatencyTimer = uint32(1); % Users guide section 3.4, suggested value is 2-255 for all devices
ChConfig.configOptions = uint32(0b100000); % Bit 1 is CPOL, bit 0 is CPHA. Higher order bits configure the chip select.
ChConfig.Pin = uint32(0x00000000);
E = calllib(ADXL.Libname,'SPI_InitChannel',ADXL.pChannelHandle,ChConfig);
disp(['SPI configured with Errorcode: ',num2str(E)]);
end
I've found solutions to make my main file know, that the function exists. Now at least I'm not getting the "Unknown Function ..." Error.
F = parfeval(gcp(),@(varargin) ACC.ReadFIFO(varargin{:}),4,Dauer,10);
with ReadFIFO being:
function [MessungA,MessungB,TVectorA,TVectorB] = ReadFIFO(ADXL,Time,Means)
% Some code that's irrelevant to this question
end
The Problem:
I need to run ReadFIFO in a separate pool for the rest of my program to work properly. First I got errors, that the function was unkown. Now I'm getting Errors that say "Library was not found", as if the pool doesn't receive the loaded libraries.
I can provide more code, but it essentially all looks like this example:
calllib(ADXL.Libname,'SPI_ChangeCS',ADXL.pChannelHandle, uint32(0b100000));
Accepted Answer
More Answers (0)
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!