PS3000a with Matlab

Post your MATLAB discussions here
Post Reply
jmrcardoso
Newbie
Posts: 0
Joined: Thu Jun 21, 2012 4:52 pm

PS3000a with Matlab

Post by jmrcardoso » Thu Jun 21, 2012 4:57 pm

Hi

I'm trying to connect to 3005 via Matlab but with limited success while retrieving data. Here is some code I'm trying. Could you give me some help on what could be wrong here?

Code: Select all

clc
clear all;
global data;
buffersize = 2000;

% Library Loading ---------------------------------------------------------
aux = libisloaded('ps3000a');
switch(aux)
    case 0
        [notfound, pwarnings] = loadlibrary('ps3000a.dll','ps3000aApi.h', 'addheader' , 'picoStatus.h');                  
        disp('##  Biblioteca ps3000a.dll carregada      ');
        pwarnings;
    case 1
        unloadlibrary('ps3000a');
        disp('##  Unloading...                              ');
        pause(1);
        [notfound, pwarnings] = loadlibrary('ps3000a.dll','ps3000aApi.h', 'addheader' , 'picoStatus.h');                  
        disp('##  Biblioteca ps3000a.dll carregada      ');        
end 

% Initialization of Picoscope ---------------------------------------------
data.unithandle = 0;
data.serial =[];

[status_open, data.unithandle, data.serial] = calllib('ps3000a', 'ps3000aOpenUnit', data.unithandle, data.serial);
get_pico_message(status_open);
assert(status_open == 0,'There is a problem while openning the unit!');

% Simples LED Flashing Test -----------------------------------------------
disp('Flash LED');
num_flashes = 2;
status  = calllib('ps3000a', 'ps3000aFlashLed', data.unithandle, num_flashes);
get_pico_message(status);


% PingUnit ----------------------------------------------------------------
disp('Ping Unit');
status = calllib('ps3000a', 'ps3000aPingUnit', data.unithandle);
get_pico_message(status);


% SetChannel --------------------------------------------------------------
disp('Set Channel');
status = calllib('ps3000a', 'ps3000aSetChannel',...
    data.unithandle, ...        %% handle 
    0, ...                      %% channel A
    1, ...                      %% enable
    0, ...                      %% coupling type
    3, ...                      %% input range (1V)
    0.0);                       %% analogue offset
get_pico_message(status);

% GetTimebase -------------------------------------------------------------
% disp('Get Timebase');



% RunBlock
disp('Run Block');
ptime = libpointer('int32Ptr');
ppar = libpointer('voidPtr');
lpReady = libpointer('int16Ptr');
status = calllib('ps3000a', 'ps3000aRunBlock',...
    data.unithandle, ...         %% handle     
    0, ...                      %% noOfPreTriggerSamples
    buffersize, ...             %% noOfPostTriggerSamples
    0, ...                      %% timebase
    1, ...                      %% oversample 1-256
    ptime, ...               	%% * timeIndisposedMs
    0, ...                      %% segmentIndex
    lpReady, ...
    ppar);  
get_pico_message(status);

% IsReady -----------------------------------------------------------------
disp('isReady');
ready = libpointer('int16Ptr', zeros(1,1));
status = calllib('ps3000a', 'ps3000aIsReady',...
    data.unithandle, ... %% handle
    ready);                   %% ready to collect
get_pico_message(status);

% SetDataBuffer -----------------------------------------------------------
disp('SetDataBuffer');
%bufferlocation = libpointer('int16Ptr', zeros(1,1));
buffer = libpointer('int16Ptr', zeros(buffersize,1));

status = calllib('ps3000a', 'ps3000aSetDataBuffer',...
    data.unithandle, ... %% handle
    0, ...                    %% channel A
    buffer, ...                %% buffer
    buffersize, ...           %% buffer lenght 
    0, ...                    %% segmentIndex
    0);                       %% downsampling
get_pico_message(status);

%GetValues ----------------------------------------------------------------
disp('GetValues');
flow = libpointer('int16Ptr');

status = calllib('ps3000a', 'ps3000aGetValues',...
    data.unithandle, ...      %% handle
    0, ...                    %% startIndex
    buffersize, ...               %% * noOfSamples
    0, ...                    %% downsampling ratio
    0, ...                    %% downsampling mode
    0, ...                    %% segmentIndex    
    flow);                    %% overflow
get_pico_message(status);

pause(1);
status  = calllib('ps3000a', 'ps3000aCloseUnit', data.unithandle);
disp('Closing Unit');
get_pico_message(status);

Hitesh
Site Admin
Site Admin
Posts: 2829
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: PS3000a with Matlab

Post by Hitesh » Fri Jun 22, 2012 8:53 am

Hi jmrcardoso,

What specific issues are you encountering with retrieval of data?

Looking at your code I suggest the following:
  • In your 'SetChannel' function call, the 1V input range has an enumeration value of 6 (see ps3000aApi.h)
  • For your RunBlock function define lpReady and ppar as null parameters (MATLAB does not support callback functions):

    Code: Select all

    ppar = [];
    lpReady = [];
    
You should then be able to read the data out from the buffer variable.

Regards,
Hitesh

Technical Support Engineer

Hitesh
Site Admin
Site Admin
Posts: 2829
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: PS3000a with Matlab

Post by Hitesh » Thu Oct 25, 2012 10:00 am

Hi,

A MATLAB Generic Instrument Driver for using the PicoScope 3000A/B with the MATLAB Instrument Control Toolbox is now available.

A Beta driver is available for testing:

http://www.picotech.com/support/topic11499.html

Thanks,
Hitesh

Technical Support Engineer

Post Reply