Writing MATLAB scripts using the PicoScope/Data Logger SDK

Post your MATLAB discussions here
Locked
Hitesh

Writing MATLAB scripts using the PicoScope/Data Logger SDK

Post by Hitesh »

Please post any discussions relating to the use of MATLAB with our products' SDK or example scripts that you wish to share in this forum area. Example scripts, although not available as part of the formal SDK releases, are available for some of our product ranges.

We are in the process of creating Instrument Drivers for use with Instrument Control Toolbox to facilitate the connection of oscilloscope devices and data capture.

An example script for the PicoScope 2000 series can be found on the PicoApps site http://www.picoapps.com/coders-corner/#apps.

The simplest way to get started is to load the library and implement the functions to open and close a unit.

Below is an example for a PicoScope 3000a series unit:

Code: Select all

loadlibrary('ps3000a.dll','ps3000aApi.h');
if ~libisloaded('ps3000a')
    error('library ps3000a.dll or ps3000aApi.h not found') %check if the library is loaded
end

unitHandle = 0;
serial = blanks(40);

[status.open, unitHandle, serial] = calllib('ps3000a', 'ps3000aOpenUnit', unitHandle, serial)

status.close = calllib('ps3000a', 'ps3000aCloseUnit', unitHandle);

unloadlibrary('ps3000a');
Ensure that the location of the header file 'picoStatus.h' is included in the MATLAB path to ensure that the status values can be read - the file can be explicitly declared in the 'loadlibrary' line:

Code: Select all

loadlibrary 'ps3000a.dll' 'ps3000aApi.h' addheader 'picoStatus.h';
A prototypefile can be created using the 'mfilename' argument in order to use enumerations and structures:

Code: Select all

loadlibrary 'ps3000a.dll' 'ps3000aApi.h' addheader 'picoStatus.h' mfilename 'ps3000aMFile';
Once the library has been unloaded, subsequent calls to the loadlibrary function can be made thus:

Code: Select all

loadlibrary('ps3000a.dll', @ps3000aMFile);
It is recommended to use the approach above, rather than using the header files as the prototype files do contain the extracted information from the header files.

NOTE: Ensure that the library case name matches the name passed to the loadlibrary function. For example, if the dll was actually named named 'PS3000A.dll', MATLAB would indicate that it will use the classname 'PS3000A' instead.

Warning messages such as 'Warning: The data type 'FcnPtr' used by function ps3000aRunBlock does not exist. ' may appear - these can be output to variables, The 'FcnPtr' keyword refers to callback functions which MATLAB does not support. Instead use the wrapper dll functions, or in the case of block mode captures, poll the driver using the ps3000aIsReady function call.

To access the enumerations and structures use the line from the top of the ps3000MFile file omitting the 'function' keyword:

Code: Select all

[methodinfo, structs, enuminfo, ThunkLibName] = ps3000aMFile
The structs and enuminfo variables can then be accessed to obtain the desired structure or enumeration. Typing 'structs' or 'enuminfo' at the MATLAB command prompt will list a summary of what is represented by the variables.

Note that prototype files generated for 32-bit dlls will not work with MATLAB 64-bit and vice-versa. Additionally, 'thunk' dll files generated by MATLAB (and available via the SDK) will need to be used for 64-bit versions of MATLAB.

Please refer to the relevant Programmer's Guide for details of the function parameters, return values and data types. MATLAB will convert data types for you.

The libfunctions and libfunctionsview functions can be used to show how MATLAB interprets the various API functions.

For further information on MATLAB please visit http://www.mathworks.com
Last edited by Hitesh on Mon Aug 24, 2015 3:31 pm, edited 6 times in total.
Reason: Updates to description

Hitesh

Writing MATLAB scripts using the PicoScope/Data Logger S

Post by Hitesh »

Hi,

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

Please visit the following post:

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

Thanks,

Liryc
Newbie
Posts: 0
Joined: Mon Sep 16, 2013 9:47 am

Re: Writing MATLAB scripts using the PicoScope/Data Logger S

Post by Liryc »

Hi Hitesh,

I am trying to load the library for the Picoscope 3204.
I am using the following command: loadlibrary('PS3000.dll','PS3000.h');

Matlab seems unable to load the library and I am curious to know whether I am using the correct dll and header file.

Thanks,

Fabrice.

Hitesh

Re: Writing MATLAB scripts using the PicoScope/Data Logger S

Post by Hitesh »

Hi Fabrice,

What is the error message?

You may need to run the following command:

Code: Select all

mex -setup 
You will need to have a C compiler installed on your PC (there might be one installed with MATLAB 32-bit). If you are using a 64-bit version of MATLAB you will need to install Windows SDK 7.1.

Regards,

nhanlm0601
Newbie
Posts: 0
Joined: Fri Nov 01, 2013 7:27 pm

Re: Writing MATLAB scripts using the PicoScope/Data Logger S

Post by nhanlm0601 »

I don't know why it does not let me compile eventhough I compile successfully using Visual Studio2012.
When mex-setup, I set the compiler as visual C++2010


Code: Select all

Error loading library intermediate output follows.
The actual error is at the end of this output.
*********

Type 'u_int64_t' was not found.  Defaulting to type error.

Found on line 6602 of input from line 796 of file C:\\Users\\mnle\\Desktop\\pico4424\\ps4000Api.h
*********
Error using loadlibrary (line 419)
Building PS4000_thunk_pcwin64 failed.  Compiler output is:
cl -I"C:\Program Files\MATLAB\R2012b\extern\include"   /W3
/D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0
/nologo  -I"C:\Users\mnle\Desktop\pico4424"
-I"C:\Users\mnle\Desktop\pico4424" "PS4000_thunk_pcwin64.c" -LD
-Fe"PS4000_thunk_pcwin64.dll"
PS4000_thunk_pcwin64.c
C:\Users\mnle\Desktop\pico4424\ps4000Api.h(54) : error C2628: 'int64_t'
followed by '__int64' is illegal (did you forget a ';'?)
C:\Users\mnle\Desktop\pico4424\ps4000Api.h(54) : warning C4091: 'typedef ' :
ignored on left of '_Longlong' when no variable is declared
C:\Users\mnle\Desktop\pico4424\ps4000Api.h(794) : error C2146: syntax error :
missing ')' before identifier 'holdoff'
C:\Users\mnle\Desktop\pico4424\ps4000Api.h(794) : error C2081: 'u_int64_t' :
name in formal parameter list illegal
C:\Users\mnle\Desktop\pico4424\ps4000Api.h(794) : error C2061: syntax error :
identifier 'holdoff'
C:\Users\mnle\Desktop\pico4424\ps4000Api.h(794) : error C2059: syntax error :
';'
C:\Users\mnle\Desktop\pico4424\ps4000Api.h(794) : error C2059: syntax error :
','
C:\Users\mnle\Desktop\pico4424\ps4000Api.h(796) : error C2059: syntax error :
')'
PS4000_thunk_pcwin64.c(871) : error C2065: 'u_int64_t' : undeclared
identifier
PS4000_thunk_pcwin64.c(871) : error C2146: syntax error : missing ';' before
identifier 'p1'
PS4000_thunk_pcwin64.c(871) : error C2065: 'p1' : undeclared identifier
PS4000_thunk_pcwin64.c(872) : error C2275: 'PS4000_HOLDOFF_TYPE' : illegal
use of this type as an expression
        C:\Users\mnle\Desktop\pico4424\ps4000Api.h(342) : see declaration of
        'PS4000_HOLDOFF_TYPE'
PS4000_thunk_pcwin64.c(872) : error C2146: syntax error : missing ';' before
identifier 'p2'
PS4000_thunk_pcwin64.c(872) : error C2065: 'p2' : undeclared identifier
PS4000_thunk_pcwin64.c(875) : error C2065: 'p1' : undeclared identifier
PS4000_thunk_pcwin64.c(875) : error C2065: 'u_int64_t' : undeclared
identifier
PS4000_thunk_pcwin64.c(875) : error C2143: syntax error : missing ')' before
'const'
PS4000_thunk_pcwin64.c(875) : error C2100: illegal indirection
PS4000_thunk_pcwin64.c(875) : error C2059: syntax error : ')'
PS4000_thunk_pcwin64.c(876) : error C2065: 'p1' : undeclared identifier
PS4000_thunk_pcwin64.c(876) : error C2065: 'p1' : undeclared identifier
PS4000_thunk_pcwin64.c(876) : error C2065: 'p1' : undeclared identifier
PS4000_thunk_pcwin64.c(877) : error C2065: 'p2' : undeclared identifier
PS4000_thunk_pcwin64.c(878) : error C2065: 'p2' : undeclared identifier
PS4000_thunk_pcwin64.c(878) : error C2065: 'p2' : undeclared identifier
PS4000_thunk_pcwin64.c(878) : error C2065: 'p2' : undeclared identifier
PS4000_thunk_pcwin64.c(879) : error C2059: syntax error : ','
PS4000_thunk_pcwin64.c(879) : error C2146: syntax error : missing ')' before
identifier 'u_int64_t'
PS4000_thunk_pcwin64.c(879) : error C2146: syntax error : missing ')' before
identifier 'u_int64_t'
PS4000_thunk_pcwin64.c(879) : error C2065: 'u_int64_t' : undeclared
identifier
PS4000_thunk_pcwin64.c(879) : error C2059: syntax error : 'type'


Error in PicoMatlabStartSetup (line 5)
    loadlibrary('ps4000','ps4000Api.h')
 
>> 

Hitesh

Re: Writing MATLAB scripts using the PicoScope/Data Logger S

Post by Hitesh »

Hi,

This is due to WIN64 not being defined in the ps4000Api.h header file.

Please add the following to the header file in the IFDEF part:

Code: Select all

 #ifdef WIN32
 ...
 ...
 /* Define a 64-bit integer type */
  #include 

 // Add this
 #ifndef _WIN64
	typedef int64_t __int64;
 #endif
	typedef uint64_t u_int64_t;

Locked