Test and Measurement Forum

ps4000 Matlab

Post your MATLAB discussions here

ps4000 Matlab

Postby O. Chumak » Fri Dec 04, 2009 2:51 pm

Dear sdk developers,
I tried to use ps4000.dll for incorporating of PicoScope 4424 to the Matlab environment and was successful with the majority of the functions. However there some problems. Most important functions as for example ps4000RunBlock uses callback which is not supported by Matlab. Can such functions be rewritten for Matlab users so that callback routine would be excluded? For example I will ask manually if a record is done and than copy data via variable or memory pointer instead of using callback routine ps4000DataReady.

Best regards,
Oleksiy Chumak.
O. Chumak
 

Re: ps4000 Matlab

Postby Robin » Fri Dec 04, 2009 3:34 pm

Hi

In the SDK there is a wrapper DLL that avoids the need to pass function pointers to run block. The source code (ps4000wrap.c) is also included in the SDK so you can see how to use it.

Robin
Robin
Zen Master
Zen Master
 
Posts: 558
Joined: Fri Sep 19, 2008 10:17 am

Re: ps4000 Matlab

Postby Oleksiy » Fri Dec 04, 2009 4:27 pm

Thank you for the prompt reply.
We tried to use it but in such form it became more complicated. I need header file to load this wrap.dll to Matlab. Using two libraries rises some other questions. We try also to create our wrap file with partial success. Perhaps we can do it finally if you provide us header file or when we prepare our wrapper.
However it would be much easier if the wrapping functions would be simply in the primary dll and in primary header file. If it is not too complicate consider this, it would help as a lot.
Best regards,
Oleksiy.
Oleksiy
Newbie
 
Posts: 0
Joined: Fri Nov 06, 2009 9:54 am

Re: ps4000 Matlab

Postby Christopher » Thu Jul 15, 2010 2:29 pm

I have a picoscope 4xxx and would like to get the dll libraries working in Matlab. I have never played with dlls in Matlab and it seems a little less straightforward than I had hoped, I have been modifying the ps2000 example, but haven't yet been able to get any data from the picoscope. I was wondering if anybody has some simple Matlab code they can provide which just uses the ps4000Api.h/ps4000.dll to get data from the picoscope.
Thanks!
Christopher
Christopher
 

Re: ps4000 Matlab

Postby Oleksiy » Fri Jul 23, 2010 1:36 pm

Here a files set prepared for three PicoScope 4424 units, perhaps it will help you. This program did not work properly but the problem was in communication with three units, with only one unit it could work. You should change the program for only one units mainly by deleting of unnecessary functions. It used ps4000sdk_r6_2_14_0 but may be will work with updated one. Start with Main file.
I am out of office and internet next month and can answer any questions in the end of august.
Good luck!

Oleksiy.
Attachments
PicoMatlab.zip
(5.8 KiB) Downloaded 376 times
Oleksiy
Newbie
 
Posts: 0
Joined: Fri Nov 06, 2009 9:54 am

Re: ps4000 Matlab

Postby Hamsteh » Wed Aug 11, 2010 2:01 am

I too am finding the same issue.

I am finding it difficult to emulate the callback function in ps6000_RunBlock using Matlab.

ps3000_run_block used to work perfectly with Matlab, a similar function would be most appreciated, or if anybody has a workaround it would save me a lot of headaches.

Regards,
Alex
Hamsteh
Newbie
 
Posts: 0
Joined: Mon Aug 09, 2010 5:36 am

Re: ps4000 Matlab

Postby Robin » Wed Aug 11, 2010 7:39 am

Robin
Zen Master
Zen Master
 
Posts: 558
Joined: Fri Sep 19, 2008 10:17 am

Re: ps4000 Matlab

Postby Robin » Mon Oct 04, 2010 2:43 pm

Submitted by Oleksiy:

I have added library and header file from ps4000sdk to the previous set, thus it is functioning set now.

Just to summarize: there is set of files to run three units Picoscope
4424 in Matlab environment. It is functioning, however troubles with memory management lead to occasional errors mainly in Enumerate units function. You can significantly simplify program to operate only one unit and the errors must disappear. Or just use it like an inspiration.
Once you make functioning program publish it here for others users and the topic will be solved. Good luck.

Oleksiy Chumak.
Attachments
PicoMatlab.zip
(400.47 KiB) Downloaded 325 times
Robin
Zen Master
Zen Master
 
Posts: 558
Joined: Fri Sep 19, 2008 10:17 am

Re: ps4000 Matlab

Postby sunny.tanvirahmed » Fri Mar 08, 2013 3:05 am

Hi,
I need to use picoscope 4424 in my work place for data aquisition with the help of matlab. To say honestly, I have only learned how to use matlab(I have used C before so I knw the basics of programming) but I don't think I have advanced enough knowledge to write a program that can control the drivers and allow data aquisition from the picoscope 4424.

Can someone help me/ guide me on how to transfer data from picoscope 4424(I just need to use one channel) to my pc with the help of matlab? I have dowloaded PS4000sdk_r10_4_3_1 and also downloaded PicoMatlab.zip(from this forum), but how can I integrate both of this?

I have given below, the codes and errors which are given after I tried to start the program:

SamplePeriod=1e-007s
TimeMeasured=0.026214s
Warning: Message from C preprocessor:
lcc preprocessor warning: c:\SDKnew\ps4000Api.h:921 No newline at end of file

> In loadlibrary at 371
In PicoMatlabStartSetup at 5
In PicoMatlabMain at 3
1
AV706/069
OpenUnit=0
GetUnitInfo=0
AV706/069
PicoSerial=AV706/069
??? Undefined function or method 'UnitHandle' for input arguments of type 'double'.

Error in ==> PicoMatlabRunMeas at 15
Status =
calllib('ps4000','ps4000SetChannel',UnitHandle(k),Channel,Enabled,Coupling,VRange);

Error in ==> PicoMatlabMain at 4
PicoMatlabRunMeas

>>
sunny.tanvirahmed
Newbie
 
Posts: 0
Joined: Fri Mar 08, 2013 2:57 am

Re: ps4000 Matlab

Postby Hitesh » Fri Mar 08, 2013 12:42 pm

Hi,

The example that this Customer provided is for 3 units. I would suggest that you need to simplify this or create a new script that will open the script.

There is some guidance on this forum that shows how to call library functions - please see http://www.picotech.com/support/topic10809.html

There is also a new Software Development Kit that you can download from the website http://www.picotech.com/software.html

You will need the PicoIpp.dll in addition to the PS4000.dll file.

Try the following code to help get you started:

Code: Select all
if not(libisloaded('ps4000'))
    loadlibrary('ps4000','ps4000Api.h')
end

unitHandle = 0;
[open_status unitHandle] = calllib('ps4000','ps4000OpenUnit',unitHandle);
disp(strcat('OpenUnit=',num2str(open_status)))

String = char(uint16(ones(1,127)));
String_ptr = libpointer('voidPtr',[uint16(String) 0]);
StringLength = int16(128);
RequiredSize = int16(128);
RequiredSize_Ptr = libpointer('int16Ptr',RequiredSize);
InfoCode = uint32(4);
[info_status String] = calllib('ps4000','ps4000GetUnitInfo',UnitHandleTemp,String,StringLength,RequiredSize_Ptr,InfoCode);

disp(strcat('GetUnitInfo=',num2str(info_status)));

disp(strcat('PicoSerial=',String))

close_status = calllib('ps4000','ps4000CloseUnit',unitHandle);
disp(strcat('Closing ',num2str(close_status)))
end
%%
unloadlibrary('ps4000');


Are you trying to capture block data or streaming data? What sample interval are you looking for and what is the voltage range of the signal?

Regards,
Hitesh

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

Re: ps4000 Matlab

Postby sunny.tanvirahmed » Wed Mar 13, 2013 5:54 am

Thanks for the quick reply and tips :D
I have tried to modify the code to make it for a single unit instead of 3.I am attaching the program I am working on.
The problems are that:
1. even after I plug in the picoscope it still shows “open unit = 0”
2. When I tried to run the program without plugging in picoscope then it shows open unit =3
3. I have given the new error which is given by the program below:

SamplePeriod=1e-007s
TimeMeasured=0.026214s
Warning: Message from C preprocessor:
lcc preprocessor warning: C:\SDKpico\ps4000Api.h:831 No newline at end of file

> In loadlibrary at 371
In PicoMatlabStartSetupS at 2
In PicoMatlabMain at 4
OpenUnit=0
GetUnitInfo=0
PicoSerial=AV706/069
Closing0
??? Error using ==> calllib
Library was not found

Error in ==> PicoMatlabRunMeas at 15
Status =
calllib('ps4000','ps4000SetChannel',UnitHandle(k),Channel,Enabled,Coupling,VRange);

Error in ==> PicoMatlabMain at 5
PicoMatlabRunMeas


I am trying to capture streaming data, sample interval can be 1Mb/s to 10Mb/s and voltage range is in the range of mV. And the trigger is a sudden change in voltage.

It will be great if you can provide some guidance :)
Attachments
PicoMatlab.zip
(8.99 KiB) Downloaded 176 times
sunny.tanvirahmed
Newbie
 
Posts: 0
Joined: Fri Mar 08, 2013 2:57 am

Re: ps4000 Matlab

Postby Hitesh » Wed Mar 13, 2013 3:11 pm

Hi Sunny,

Your script is successfully opening and closing the scope - the '0' returned for open unit indicates that the function has returned successfully. If you examine the UnitHandle parameter after calling the ps4000OpenUnit function, you will find that it should have a positive non-zero value. This 'handle' value is then used when calling the various functions to acquire data.

The serial number returned gives away the fact the unit was opened :D

If no unit is connected then an error code of 3 (PICO_NOT_FOUND) is expected.

The example script that you downloaded captures data in rapid block mode. For streaming data capture, please refer to the PicoScope 4000 Series Programmer's Guide as this will help with your script:

http://www.picotech.com/document/pdf/ps4000pg.en-7.pdf

The Programmer's Guide contains details of the API functions, enumerations to use and error codes. In the attached zip file, there are some prototype files which you can use to when calling the loadlibrary function i.e.

Code: Select all
loadlibrary('PS4000', 'PS4000MFile');

loadlibrary('ps4000wrap.dll', 'ps4000WrapMFile');


The examples above would work with the new PS4000.dll from the current SDK - note the capitalised 'PS' (This is probably why you could not call the ps4000SetChannel function). The current SDK is missing the ps4000wrap.dll so I have included it in the zip file. The wrapper dll is needed to be able to capture streaming data without the use of C-style callback functions.

The forum post that I referred to previously shows how to access the enumerations and structures from the prototype file.

The PS4000MFile.m contains details of the enumerations.

You can use the C console example from the SDK to help with structuring your code and for referring to the enumerations.

Section 4.6.4.1 (Using streaming mode) shows the functions you need to call in order to capture data. There is one exception - instead of step 6, you will need to use the following functions from the wrapper dll to be able to collect data:

  • GetStreamingLatestValues
  • IsReady
  • IsTriggerReady
  • AvailableData
  • AutoStopped

After calling ps4000RunStreaming this would be the order of function calls as pseudo-code:

Code: Select all
Loop

GetStreamingLatestValues

Sub loop (while ready == 0)

ready = IsReady

End Sub loop

IsTriggerReady

AvailableData

Check if AutoStopped (if so, break out of loop)

End loop


In the zip file there are functions to help with converting the ADC counts returned from the driver into voltage values as well as vice-versa.

I hope this helps.
Attachments
ps4000_matlab_functions.zip
Function files for MATLAB and wrapper dll.
(23.9 KiB) Downloaded 208 times
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2063
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