PicoScope 6000 series with 64-bit MATLAB

Post your MATLAB discussions here
Post Reply
mpreciado78
Newbie
Posts: 0
Joined: Thu Nov 28, 2013 12:19 pm

PicoScope 6000 series with 64-bit MATLAB

Post by mpreciado78 »

Hi!

I am having problems trying to control the PicoScope 6403 in 64-bit Matlab (tried 2011 and 2013). When trying to use loadlibrary with the provided PS6000.dll, I have:

....PS6000.dll is not a valid Win32 application.

I have read that this message is also given when it really means "Win32 for your 64bits system."

It is actually the same as posted here http://www.picotech.com/support/topic11267.html

So I understand what I need is to get a 64 bits version of PS6000.dll...

is there any 64 bits driver available for 6000 series?

Thanks in advance!
Miguel

Karunen
Advanced User
Advanced User
Posts: 194
Joined: Thu Nov 21, 2013 9:22 am

Re: PicoScope 6000 series with 64-bit MATLAB

Post by Karunen »

Hi mpreciado78,

You can get the 64 bit version of the PS6000.dll from http://www.picotech.com/software.html.
1. select your Picoscope
2.select the software development kit option and click the download button when it appears.

You require the PS6000.dll and the PicoIpp.dlr located in the x64 folder.

You will also have to download and install Microsoft Windows SDK 7.1, you can find instructions on how to get the sdk and install it from the link below.
http://www.mathworks.com/matlabcentral/answers/101105

NOTE: Pico Technology Ltd. is not responsible for the content of external third-party sites.

Lastly you need to run mex –setup in MATLAB to configure the compiler.


Thank you,
Karunen

Technical Specialist
Pico Technology

mpreciado78
Newbie
Posts: 0
Joined: Thu Nov 28, 2013 12:19 pm

Re: PicoScope 6000 series with 64-bit MATLAB

Post by mpreciado78 »

Many thanks for your response!

I managed to be able to do access to the API by using this 64 bits PS6000.dll with loadlibrary('PS6000.dll','ps6000Api.h');

Which .h need to be used for this PicoIpp.dll in "loadlibrary"? What is this for? I already got all the functions of the interface by the previous library... I wonder if that is related the callback functions, where I am stuck now, trying to solve it with the PS6000wrap.dll/PS6000wrap.h.

Hitesh

Re: PicoScope 6000 series with 64-bit MATLAB

Post by Hitesh »

Hi mpreciado78,

There is no need to load the PicoIpp.dll file into MATLAB, judt ensure that it is on the MATLAB path for the PS6000.dll file.

MATLAB is unable to support C-style callback functions, hence the wrapper dll is provided.

If you have the latest SDK (10.5.0.28), this contains an updated ps6000Wrap.dll file that will copy streaming data in the callback to an application buffer that you have defined in MATLAB.

The steps to call are as follows:
  • After calling ps6000SetChannel for each of the channels, call setEnabledChannels
  • After registering your driver buffers via ps6000SetDataBuffer, define an application buffer for each channel and call setAppAndDriverBuffers - your application buffer should be same size as the buffer registered for the driver. It is a buffer used to copy data into.
  • Call ps6000RunStreaming
  • Loop - use a condition such as the autoStop flag:

    Code: Select all

    * Call GetStreamingLatestValues
    
    * Sub-loop - poll the driver using IsReady
    
    * Call AvailableData
    
    * Call IsTriggerReady if data has been collected and a trigger has been set
    
    * Process data collected in application buffer
    
    * Call AutoStopped to check if autoStop flag has been set if the autoStop parameter was set in the call to ps6000RunStreaming
    
  • End loop
  • Call ps6000Stop
  • Process data
I hope this helps.

mpreciado78
Newbie
Posts: 0
Joined: Thu Nov 28, 2013 12:19 pm

Re: PicoScope 6000 series with 64-bit MATLAB

Post by mpreciado78 »

Dear Hitesh,

Thanks for you response.


I am having problems with the trigger. I am able to capture data, but not synchronized with the trigger (selftriggered channel A in this example). Adding the suggested code does not seem to help too much... maybe I misunderstood something. This is the code I am using:

Code: Select all


function PicoMatlab
close all;
global data;

data=struct ('unithandle',0,...
    'handle',0,...
    'fighandle',0,...
    'guitimebase',0,...
    'timebase',0,...
    'guiInputRange',0,...
    'InputRange',0);

if ~libisloaded('PS6000')
    loadlibrary('PS6000.dll','ps6000Api.h');   
end

if ~libisloaded('ps6000Wrap')
    loadlibrary('ps6000Wrap.dll','ps6000wrap.h');  
end
   

unithandle= libpointer('int16Ptr',0);
STATUS=calllib('PS6000','ps6000OpenUnit',unithandle,[])
% 
data.unithandle=unithandle.value;

if data.unithandle<1
    'Error openning the unit'
    return
end


channel=0;
enable=1;
typeACDC=1; %DC 1Mohm
% range=9;%plusminus 10 volts
range=8;%plusminus 10 volts
offet=0;
bandwidthlim=0 %full bandwidth;

STATUS=calllib('PS6000', 'ps6000SetChannel', data.unithandle, channel, enable,...
    typeACDC,range,offet,bandwidthlim)

pEnabChannels= libpointer('int16Ptr',[1 0 0 0]);
STATUS=calllib('ps6000Wrap','setEnabledChannels', data.unithandle,pEnabChannels);




enable=1;
channel=0; 
threshold=10000 ;
thresdir=2;
delay=0;
autoTriggerms=1000;


%trigger with SetSimpleTrigger. This is where I believe there can be something wrong. I tried all thresholds and directions possible.
STATUS=calllib('PS6000','ps6000SetSimpleTrigger',data.unithandle, enable,...
    channel,threshold,thresdir,delay,autoTriggerms)

BUFFERSIZE=2e2;

%set data buffer
channel=0; %channel A
bufferLength=BUFFERSIZE;
pBuffer= libpointer('int16Ptr',zeros(1,round(bufferLength)));
downSampleRatioMode=0;
STATUS=calllib('PS6000','ps6000SetDataBuffer',data.unithandle,channel,...
    pBuffer,bufferLength,downSampleRatioMode)

channel=0;
pAppBuffer= libpointer('int16Ptr',zeros(1,round(bufferLength)));
pDrvBuffer= libpointer('int16Ptr',zeros(1,round(bufferLength)));

STATUS=calllib('ps6000Wrap','setAppAndDriverBuffers', data.unithandle,...
    channel,pAppBuffer,pDrvBuffer,BUFFERSIZE);



sampleInterval=1000;
pSampleInterval= libpointer('ulongPtr',sampleInterval); 
sampleIntervalTimeUnits=2; 
maxPreTrigSamp=0;
maxPostTrigSamp=BUFFERSIZE;
autoStop=0;
downSampleRatio=1;
downSampleRatioMode=0;
overviewBufferSize=BUFFERSIZE;

figure(22);
    STATUS=calllib('PS6000','ps6000RunStreaming',data.unithandle,pSampleInterval,...
        sampleIntervalTimeUnits,maxPreTrigSamp,maxPostTrigSamp,autoStop,downSampleRatio,...
        downSampleRatioMode,overviewBufferSize)
    

for(I=1:300);
    STATUS=calllib('ps6000Wrap','GetStreamingLatestValues',data.unithandle);

    ready=calllib('ps6000Wrap','IsReady',data.unithandle)
     while(~ready) 
         'esperando el ready'
          STATUS=calllib('ps6000Wrap','GetStreamingLatestValues',data.unithandle); %infinite loop never ready if I do not include this line
         ready=calllib('ps6000Wrap','IsReady',data.unithandle)
     end
     
     pStartIndex=libpointer('ulongPtr',0);
    STATUS=calllib('ps6000Wrap','AvailableData',data.unithandle, pStartIndex);
     
    
    pTriggeredAt=libpointer('ulongPtr',1e4);
    STATUS=calllib('ps6000Wrap','IsTriggerReady',data.unithandle,pTriggeredAt);
    
    At=sampleInterval*(10.^(3*sampleIntervalTimeUnits-15));
    t=At*(1:length(pBuffer.value));
    
    plot(t,pBuffer.value); %nothing obtained in pAppBuffer or pDrvBuffer, Aplication and Driver buffer defined as suggested. The plotted signal does not seem to be triggered as specified.
    hold on;
    drawnow;
   
    
end

  STATUS=calllib('PS6000','ps6000Stop',data.unithandle);
  
STATUS=calllib('PS6000','ps6000CloseUnit',data.unithandle)





return









mpreciado78
Newbie
Posts: 0
Joined: Thu Nov 28, 2013 12:19 pm

Re: PicoScope 6000 series with 64-bit MATLAB

Post by mpreciado78 »

Summarizing my previous post. I am trying to trigger, but I was not able to make it work. I am using simple trigger and complex trigger, and none seem to give me a triggered signal.

Simple trigger:

Code: Select all

enable=1;
channel=0; 
threshold=10000 ;
thresdir=2;
delay=0;
autoTriggerms=1000;

STATUS=calllib('PS6000','ps6000SetSimpleTrigger',data.unithandle, enable,...
    channel,threshold,thresdir,delay,autoTriggerms)
Complex trigger mode:

Code: Select all


thresholdUpper=5000;
hysteresisUpper=100;
thresholdLower=1000;
hysteresisLower=100;
channel=0;
thresholdMode=0;

pTriggerProperties= libpointer('int32Ptr',[thresholdUpper,hysteresisUpper,...
    thresholdLower,hysteresisLower,channel,thresholdMode]);
nProperties=1; %only one set of properties
auxEnable=0;
autoTrig=0;
STATUS=calllib('ps6000Wrap','SetTriggerProperties',data.unithandle,pTriggerProperties,...
    nProperties,auxEnable,autoTrig);

pTriggerConditions= libpointer('int32Ptr',[1 0 0 0 0 0 0]); %none but channel A care
nConditions=1; 
STATUS=calllib('ps6000Wrap','SetTriggerConditions',data.unithandle,pTriggerConditions,...
    nConditions);

STATUS=calllib('PS6000','ps6000SetTriggerChannelDirections',data.unithandle,...
2,2,2,2,2,2); %all set rising


Hitesh

Re: PicoScope 6000 series with 64-bit MATLAB

Post by Hitesh »

Hi mpreciado78,

You might benefit from generating a prototype file (see http://www.mathworks.co.uk/help/matlab/ ... files.html) using the header file and dll. This will allow you to access enumerations and structures.

[The extension m has been deactivated and can no longer be displayed.]

The prototype file also contains structure definitions for the advanced trigger functions. You can load these in by calling:

Code: Select all

%% LOAD ENUMERATION AND STRUCTURE DATA
% Load information from prototype file

[ps6000Methodinfo, ps6000Structs, ps6000Enuminfo, ps6000ThunkLibName] = PS6000MFile;

%% OPEN UNIT
% Load library and open the unit

loadlibrary('PS6000.dll', 'PS6000MFile');
Below is a snippet of code that might help for a simple trigger:

Code: Select all

%% SET TRIGGER

enableTrig = 1;
voltageRange = 2000; %2V (Change if voltage range changes)

direction = ps6000Enuminfo.enPS6000ThresholdDirection.PS6000_RISING;
delay = numPreTriggerSamples;
autoTriggerMs = 0;
maxADCValue = 32512;
triggerLevelMv = 800;

threshold = mv2adc(triggerLevelMv, voltageRange, maxADCValue);

[status.setSimpleTrig] = calllib('PS6000', 'ps6000SetSimpleTrigger', handle, enableTrig, channelA, threshold, direction, delay, autoTriggerMs);
The mv2adc function file is available through our PicoScope 2000, 3000a or 5000a SDK releases but I have attached it here.

[The extension m has been deactivated and can no longer be displayed.]

I hope this helps.

mpreciado78
Newbie
Posts: 0
Joined: Thu Nov 28, 2013 12:19 pm

Re: PicoScope 6000 series with 64-bit MATLAB

Post by mpreciado78 »

Histesh,

Thanks for the info. These definitions are very useful and helpful for writing the code in Matlab.

However, I did not manage to succeed. I only got captures with an strange behavior where sometimes I get samples calling the last streaming samples functions, and sometimes I get nothing and wait for IsReady forever. And no trigger at all.

I have spent several days stuck and I've already given up, I'll wait to see if somebody else manage and upload an example code for streaming triggered in Matlab. I'll go for another solution, an ADC with Matlab support instead, for the moment.

Reg.,
Miguel

Hitesh

Re: PicoScope 6000 series with 64-bit MATLAB

Post by Hitesh »

Hi Miguel,

I'm happy to take a look at your code if you'd like to send your script to support@picotech.com

Regards,

Post Reply