Test and Measurement Forum

Accessing Picoscope 6404D via Matlab

Post your MATLAB discussions here

Accessing Picoscope 6404D via Matlab

Postby mdawkins » Fri Jan 03, 2014 6:15 pm

Hi,

I am trying to get started in controlling a 6000 series picoscope from within matlab. I have not used Picoscope devices before so am unfamiliar with the process.

From what I can gather so far on these forums and elsewhere, I will require the WIndows SDK 7.1 installed on my PC, and also to download the Picoscope SDK, both of which I have done.

I am now expecting to be able to use loadlibrary in Matlab to load the functions I need to access, control & capture data from the 6404D scope that I have. I was hoping to start with:

loadlibrary('PS6000.dll', 'ps6000Api.h')

but unfortunately I don't seem to have the header file ps6000Api.h

Its probable that I have missed out some installation step along the way, so any help would be appreciated! Is there a step by step guide on how to use the dll functions to control the device?

Thanks
Mark
mdawkins
Newbie
 
Posts: 0
Joined: Fri Jan 03, 2014 5:08 pm

Re: Accessing Picoscope 6404D via Matlab

Postby Hitesh » Mon Jan 06, 2014 9:18 am

Hello Mark,

Please refer to the Programmer's Guide for information on the function calls - there are details for the sequence of steps for block, rapid block and streaming mode acquisition.

Windows SDK 7.1 is required if you are using MATLAB 64-bit.

The ps6000Api.h header file has been omitted from the last SDK build in error so it should be available in the next release.

In the meantime, please find the header file attached below.

ps6000Api.h
PS6000 Header file
(22.43 KiB) Downloaded 139 times


I hope this helps.
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Accessing Picoscope 6404D via Matlab

Postby mdawkins » Wed Jan 15, 2014 9:20 pm

Hi Hitesh,

Thanks for the reply and the missing header file. I can now use loadlibrary successfully although I do get warnings:

Warning: The data type 'FcnPtr' used by function ps6000RunBlock does not exist.
> In loadlibrary at 403
In initialExperiments at 3
Warning: The data type 'FcnPtr' used by function ps6000GetStreamingLatestValues does not exist.
> In loadlibrary at 403
In initialExperiments at 3

Should I be concerned about these?

I must confess that I am not sure how to proceed, even with the programming guide, as I would like to use Matlab which is not one of the example languages. For example, I found an example on this forum for the 3000a series and tried to copy that to open my scope - so I tried:

global data;
loadlibrary('PS6000.dll','ps6000Api.h');
if ~libisloaded('PS6000')
error('library PS6000.dll or ps6000Api.h not found') %check if the library is loaded
end
data.unithandle = 0;
data.serial = [];
[status_open, data.unithandle, data.serial] = calllib('PS6000', 'ps6000OpenUnit', data.unithandle, data.serial)
status_close = calllib('PS6000', 'ps6000CloseUnit', data.unithandle);
unloadlibrary('PS6000');

Unfortunately this caused a Matlab crash on the calllib line. Is there something I'm obviously doing wrong?

I am using 32-bit Matlab on a 32 bit machine, and in fact I had already installed the Windows SDK 7.1

Thanks,
Mark
mdawkins
Newbie
 
Posts: 0
Joined: Fri Jan 03, 2014 5:08 pm

Re: Accessing Picoscope 6404D via Matlab

Postby Hitesh » Mon Jan 20, 2014 9:46 am

Hi Mark,

Which line is MATLAB crashing on? Is it the call to open the unit?

How are you looking to capture data using the PicoScope in MATLAB? If you can provide some information on your application it will help in terms of determining the sequence of calls to make in order to retrieve data.

Thanks,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Accessing Picoscope 6404D via Matlab

Postby mdawkins » Mon Jan 20, 2014 4:44 pm

Hi Hitesh,

Sorry, I wan't clear on which calllib line caused the crash: Matlab crashes at the line:

[status_open, data.unithandle, data.serial] = calllib('PS6000', 'ps6000OpenUnit', data.unithandle, data.serial)

I get the message asking me if I want to "attempt to continue" and if i do so, matlab exits immediately.

I have a matlab tool already built for analysing captured data from scopes etc. At a minimum, I need to be able to set the sample rate/number of samples to capture, execute a run once capture, and retrieve the data into matlab - all using matlab commands.

Is this possible?

Thanks
Mark
mdawkins
Newbie
 
Posts: 0
Joined: Fri Jan 03, 2014 5:08 pm

Re: Accessing Picoscope 6404D via Matlab

Postby Hitesh » Tue Jan 21, 2014 10:52 am

Hi Mark,

Apologies, the header files have been recently changed to support stdint data types so I suspect there is an issue with using the new header file.

What you are looking to do is feasible. Could I ask you to e-mail support@picotech.com please with details of the sampling rate, number of samples etc. and I can provide you with some helper files and further assistance.

Thanks,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Accessing Picoscope 6404D via Matlab

Postby sanyok » Tue May 13, 2014 7:19 am

Hello!

Didn't start a new topic because this one seems to cover the same question and does not contain a solution.

Here our problem:
PicoScope 6404D, used on a Linux machine (OpenSuse 12.3). Drivers downloaded as instructed here http://www.picotech.com/linux.html (don't know the details about installation process because it was done by our admin). Installation directory is "/opt/picoscope/". Group is created successfully
PicoScope Software works like a charm. We can capture signals and generate them with the function generator.

When it comes to access the scope from Matlab (version R2012b, 8.0.0.783), we don't get further than opening the library:

Code: Select all
loadlibrary('/opt/picoscope/lib/libps6000.so.2.0.0','/opt/picoscope/include/libps6000-1.4/ps6000Api.h','alias','lib')

loads the lib and a call to "libisloaded" confirms this. Although, while loading we get this warning:
Warning: The data type 'FcnPtr' used by function ps6000RunBlock does not exist.
> In loadlibrary at 403
Warning: The data type 'FcnPtr' used by function ps6000GetStreamingLatestValues does not exist.
> In loadlibrary at 403


We try to access the device via a call to OpenUnit just as mdawkins suggested above:

Code: Select all
global data
data.unithandle=0;
data.serial = [];
calllib('lib','ps6000OpenUnit',data.unithandle,data.serial)

Unfortunately, the last command crashes Matlab with following error message:

------------------------------------------------------------------------
Abort signal detected at Tue May 13 09:06:07 2014
------------------------------------------------------------------------

Configuration:
Crash Decoding : Disabled
Current Visual : 0x21 (class 4, depth 24)
Default Encoding: UTF-8
GNU C Library : 2.17 stable
MATLAB Root : /usr/local/matlab_classroom-8.0.0
MATLAB Version : 8.0.0.783 (R2012b)
Operating System: Linux 3.7.10-1.28-desktop #1 SMP PREEMPT Mon Feb 3 14:11:15 UTC 2014 (c9a2c6c) x86_64
Processor ID : x86 Family 31 Model 10 Stepping 0, AuthenticAMD
Virtual Machine : Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode
Window System : The X.Org Foundation (11302000), display localhost:10.0

Fault Count: 1


I don't think, the complete stack trace is needed, but here are some possibly interesting entries:

[ 8] 0x00007fb4291c5719 /usr/local/matlab_classroom-8.0.0/bin/glnxa64/libmwmcr.so+00554777
[ 9] 0x00007fb4276b31f0 /lib64/libpthread.so.0+00061936
[ 10] 0x00007fb42732b3d5 /lib64/libc.so.6+00218069 gsignal+000053
[ 11] 0x00007fb42732c858 /lib64/libc.so.6+00223320 abort+000328
[ 12] 0x00007fb42736b44b /lib64/libc.so.6+00480331
[ 13] 0x00007fb427370fc6 /lib64/libc.so.6+00503750
[ 14] 0x00007fb427371d43 /lib64/libc.so.6+00507203
[ 15] 0x00007fb3ab88ce6b /usr/lib64/libusb-1.0.so.0+00015979 libusb_close+000139
[ 16] 0x00007fb3a97222b6 /opt/picoscope/lib/libps6000.so.2.0.0+00316086
[ 17] 0x00007fb3a97223c2 /opt/picoscope/lib/libps6000.so.2.0.0+00316354
[ 18] 0x00007fb3a97226cd /opt/picoscope/lib/libps6000.so.2.0.0+00317133
[ 19] 0x00007fb3a96e8c15 /opt/picoscope/lib/libps6000.so.2.0.0+00080917
[ 20] 0x00007fb3a96e8d1e /opt/picoscope/lib/libps6000.so.2.0.0+00081182
[ 21] 0x00007fb3a96ed058 /opt/picoscope/lib/libps6000.so.2.0.0+00098392 ps6000OpenUnit+000408
[ 22] 0x00007fb3aa1997b7 /tmp/tp7446932d_0356_4347_b595_9591b179b34e/lib_thunk_glnxa64.so+00006071 uint32voidPtrvoidPtrThunk+000071
[ 23] 0x00007fb3aaa0664a /usr/local/matlab_classroom-8.0.0/bin/glnxa64/libmwcli.so+00157258


I also downloaded the SDK R10.5.0.32 for windows but could only state that the header file 'ps6000Api.h' there is identical with the one we already have.

We are open for every suggestion.
sanyok
Newbie
 
Posts: 0
Joined: Wed Apr 02, 2014 1:33 pm

Re: Accessing Picoscope 6404D via Matlab

Postby Hitesh » Tue May 13, 2014 12:10 pm

Hi Sanyok,

Have you run mex -setup to select a compiler?

Try the following:

Code: Select all
data.serial = blanks(20);


The warning messages are standard.

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Accessing Picoscope 6404D via Matlab

Postby sanyok » Wed May 14, 2014 8:47 am

Hello Hitesh!

Thanks for the suggestion! mex -setup made it better. It copied some script file from Matlab installation directory into the user home directory and after that I could call functions mentioned above and (for the beginning) let the LED blink.

I suppose that this command has to be run by every user wanting to access the scope from within Matlab.

This command however:
Code: Select all
data.serial = blanks(20);

created a variable that could not be passed to the function call. So, we stick at [] as the initialization value.

Now, the way is free to play around with the API. Thanks again!

Best regards,
Sanyok
sanyok
Newbie
 
Posts: 0
Joined: Wed Apr 02, 2014 1:33 pm

Re: Accessing Picoscope 6404D via Matlab

Postby Hitesh » Thu May 15, 2014 8:06 am

Hi Sanyok,

The header file now supplied with the SDK uses data types defined in the stdint.h header file.

The serial parameter is defined as an 'int8_t' data type so MATLAB will interpret it as an 'int8' rather than a 'cstring' data type when the library is loaded so that's why the use of blanks doesn't work.

You can confirm this by calling

Code: Select all
libfunctionsview('ps6000')


Hope this helps.
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire


Return to MATLAB

Who is online

Users browsing this forum: No registered users and 0 guests