PS4000 Series - Callback Function Pointer for MATLAB&LABVIEW
PS4000 Series - Callback Function Pointer for MATLAB&LABVIEW
Hi everybody,
I recently started creating a software for fast data acquisition using a PS4224 in fast block mode and Matlab. Unlike in the sdk for the ps3000 series, some ps4000 library function callbacks need function pointers as arguments.
Unfortunately, neither Matlab (calllib) nor Labview support function pointers as far as I know.
Is there a way to avoid writing all the software in c/c++ when using the Fast Block Mode?
I already tried providing function pointers through a Matlab mex-dll, but didn't succeed. (because I'm not a keen c-programmer and didn't manage to give multiple arguments to the ps4000RunBlock function).
Has anyone out there some more ideas on how to solve that problem?
Thank you and cheers,
Thilo
I recently started creating a software for fast data acquisition using a PS4224 in fast block mode and Matlab. Unlike in the sdk for the ps3000 series, some ps4000 library function callbacks need function pointers as arguments.
Unfortunately, neither Matlab (calllib) nor Labview support function pointers as far as I know.
Is there a way to avoid writing all the software in c/c++ when using the Fast Block Mode?
I already tried providing function pointers through a Matlab mex-dll, but didn't succeed. (because I'm not a keen c-programmer and didn't manage to give multiple arguments to the ps4000RunBlock function).
Has anyone out there some more ideas on how to solve that problem?
Thank you and cheers,
Thilo
Re: PS4000 Series - Callback Function Pointer for MATLAB&LABVIEW
Hi Thilo
We currently get around this by using a wrapper DLL.
The wrapper DLL and its source code can be found in the SDK (software development kit), along with our examples. The SDK can be downloaded via http://www.picotech.com/software.html
We will soon be adding functions to the drivers to avoid the need for callbacks in block mode.
Robin
We currently get around this by using a wrapper DLL.
The wrapper DLL and its source code can be found in the SDK (software development kit), along with our examples. The SDK can be downloaded via http://www.picotech.com/software.html
We will soon be adding functions to the drivers to avoid the need for callbacks in block mode.
Robin
Re: PS4000 Series - Callback Function Pointer for MATLAB&LABVIEW
Hi Robin,
thanks for your fast reply. I already noticed the wrapped Dll used in the Labview example but didn't find any further documentation or a fitting header (which is needed when importing libraries to Matlab), so I just sticked to solving the problem with the original library.
It can be done with some effort, by creating a Matlab Mex (dll) which includes the function call to ps4000RunBlock and the callback function as well as the "waiting loop" for ps4000RunBlock. As it also includes the waiting loop for the time until ps4000RunBlock calls its callback, no function pointers have to be transferred between the dll and Matlab.
This method should also work with a properly built DLL for LabView, but I haven't given it a try so far.
Thilo
thanks for your fast reply. I already noticed the wrapped Dll used in the Labview example but didn't find any further documentation or a fitting header (which is needed when importing libraries to Matlab), so I just sticked to solving the problem with the original library.
It can be done with some effort, by creating a Matlab Mex (dll) which includes the function call to ps4000RunBlock and the callback function as well as the "waiting loop" for ps4000RunBlock. As it also includes the waiting loop for the time until ps4000RunBlock calls its callback, no function pointers have to be transferred between the dll and Matlab.
This method should also work with a properly built DLL for LabView, but I haven't given it a try so far.
Thilo
Re: PS4000 Series - Callback Function Pointer for MATLAB&LABVIEW
[quote="Robin"]...
We will soon be adding functions to the drivers to avoid the need for callbacks in block mode.
[/quote]
Is there a release date for these new functions? I need to start programming in Matlab for the 5203 in the next two weeks and I'd rather not have to deal with these callbacks in Matlab! A simple block mode call would help a lot!
Regards, Martin
We will soon be adding functions to the drivers to avoid the need for callbacks in block mode.
[/quote]
Is there a release date for these new functions? I need to start programming in Matlab for the 5203 in the next two weeks and I'd rather not have to deal with these callbacks in Matlab! A simple block mode call would help a lot!
Regards, Martin
Re: PS4000 Series - Callback Function Pointer for MATLAB&LABVIEW
Hi Martin
I have attached a new version of the driver (that will be included i the next release of PicoScope 6). This version includes the following function that can be used to poll the driver:
PICO_STATUS ps5000IsReady (short handle, short * ready);
When you call ps4000RunBlock, you can pass NULL instead of a function pointer.
Robin
I have attached a new version of the driver (that will be included i the next release of PicoScope 6). This version includes the following function that can be used to poll the driver:
PICO_STATUS ps5000IsReady (short handle, short * ready);
When you call ps4000RunBlock, you can pass NULL instead of a function pointer.
Robin
- Attachments
-
- PS5000.zip
- (335.69 KiB) Downloaded 492 times
Re: PS4000 Series - Callback Function Pointer for MATLAB&LABVIEW
Hi Robin,Robin wrote: When you call ps4000RunBlock, you can pass NULL instead of a function pointer.
Robin
just tried:
calllib('PS5000','ps5000RunBlock',adata.unithandle.value,0,adata.numsamp,adtimebase,1,null,0,0,null);
instantly crashes Matlab. Maybe the driver still writes to a null pointer? Note I am using the ps5000RunBlock, not ps4000. What can I do here?
- Martin
Re: PS4000 Series - Callback Function Pointer for MATLAB&LABVIEW
Hi Martin
Yes, I meant ps5000RunBlock (although it is the same for the 4000 series oscilloscopes)
I don't know anything about calling DLLs from Matlab, I'm afraid.
setting the function pointer to NULL certainly works in C and LabVIEW.
Robin
Yes, I meant ps5000RunBlock (although it is the same for the 4000 series oscilloscopes)
I don't know anything about calling DLLs from Matlab, I'm afraid.
setting the function pointer to NULL certainly works in C and LabVIEW.
Robin
Re: PS4000 Series - Callback Function Pointer for MATLAB&LABVIEW
Hi Robin,
it works using the wrapper library provided with the SDK:
err=calllib('ps5000wrap','RunBlock',adata.unithandle.value,0,adata.numsamp,adtimebase,1,0);
while calllib('ps5000wrap','IsReady',adata.unithandle.value)==0
Using RunBlock and IsReady from ps5000wrap.dll works as expected. Using ps5000RunBlock even with null pointer for the callback reliably crashes Matlab.
So my suggestion would be you should integrate a callback-free functions (as in ps5000wrap.dll) into your regular DLL. Providing a header file for the ps5000wrap.dll would also help a bit.
- Martin
it works using the wrapper library provided with the SDK:
err=calllib('ps5000wrap','RunBlock',adata.unithandle.value,0,adata.numsamp,adtimebase,1,0);
while calllib('ps5000wrap','IsReady',adata.unithandle.value)==0
Using RunBlock and IsReady from ps5000wrap.dll works as expected. Using ps5000RunBlock even with null pointer for the callback reliably crashes Matlab.
So my suggestion would be you should integrate a callback-free functions (as in ps5000wrap.dll) into your regular DLL. Providing a header file for the ps5000wrap.dll would also help a bit.
- Martin
-
- Newbie
- Posts: 0
- Joined: Wed May 19, 2010 2:29 pm
Re: PS4000 Series - Callback Function Pointer for MATLAB&LAB
Hi Robin,
I also tried to use the wrapper ps4000wrap.dll together with Matlabs "calllib" however run into problems.
Using the same UnitHandle a call of the function RunBlock
[Status] = calllib('ps4000wrap','RunBlock',int16(UnitHandle),...
int32(nPreSamples),int32(nPostSamples),...
uint32(TimeBase),...
int16(Oversample),int16(SegmentIndex))
returns error 12 (PICO_INVALID_HANDLE)
whereas all other functions of the ps4000.dll work correctly with the UnitHandle
Also I found a mismatch in type declaration of the argument segmentIndex which is short in RunBlock (see ps4000wrap.c) and unsigned short in the ps4000RunBlock declaration in ps4000Api.h.
So Martins suggestion for integrating callback free functions into the ps4000.dll (and ps5000.dll) or providing a header for ps4000wrap.dll is strongly supported.
Regards, Olaf
I also tried to use the wrapper ps4000wrap.dll together with Matlabs "calllib" however run into problems.
Using the same UnitHandle a call of the function RunBlock
[Status] = calllib('ps4000wrap','RunBlock',int16(UnitHandle),...
int32(nPreSamples),int32(nPostSamples),...
uint32(TimeBase),...
int16(Oversample),int16(SegmentIndex))
returns error 12 (PICO_INVALID_HANDLE)
whereas all other functions of the ps4000.dll work correctly with the UnitHandle
Also I found a mismatch in type declaration of the argument segmentIndex which is short in RunBlock (see ps4000wrap.c) and unsigned short in the ps4000RunBlock declaration in ps4000Api.h.
So Martins suggestion for integrating callback free functions into the ps4000.dll (and ps5000.dll) or providing a header for ps4000wrap.dll is strongly supported.
Regards, Olaf
Re: PS4000 Series - Callback Function Pointer for MATLAB&LAB
Hi Olaf
With the attached driver, it is no longer necessary to use a wrapper for block-mode operation.
Instead, call ps4000RunBlock and pass NULL instead of a function pointer. You can then poll the driver using:
PICO_STATUS ps5000IsReady (short handle, short * ready);
Regarding the PICO_INVALID_HANDLE status, it sounds like your application and the wrapper are loading different versions of ps4000.dll.
Also, the source code for the wrapper is available in the SDK.
Hope this helps
Robin
With the attached driver, it is no longer necessary to use a wrapper for block-mode operation.
Instead, call ps4000RunBlock and pass NULL instead of a function pointer. You can then poll the driver using:
PICO_STATUS ps5000IsReady (short handle, short * ready);
Regarding the PICO_INVALID_HANDLE status, it sounds like your application and the wrapper are loading different versions of ps4000.dll.
Also, the source code for the wrapper is available in the SDK.
Hope this helps
Robin
- Attachments
-
- PS4000.zip
- (611.48 KiB) Downloaded 504 times
Re: PS4000 Series - Callback Function Pointer for MATLAB&LAB
Hi Robin,Robin wrote:Hi Olaf
With the attached driver, it is no longer necessary to use a wrapper for block-mode operation.
Instead, call ps4000RunBlock and pass NULL instead of a function pointer. You can then poll the driver using:
PICO_STATUS ps5000IsReady (short handle, short * ready);
Regarding the PICO_INVALID_HANDLE status, it sounds like your application and the wrapper are loading different versions of ps4000.dll.
Also, the source code for the wrapper is available in the SDK.
Hope this helps
Robin
I was wondering if there is an updated driver like this one available for the ps6000? I am having the same issue of runBlock reliably crashing Matlab when fed a NULL pointer and am keen to see if this updated driver might help.
Regards,
Alex
Re: PS4000 Series - Callback Function Pointer for MATLAB&LAB
Hi Alex
Here is the latest driver for the ps6000. It has the new function to poll the driver so it is not necessary to use callbacks in block mode.
PICO_STATUS ps6000IsReady (short handle, short * ready);
Robin
Here is the latest driver for the ps6000. It has the new function to poll the driver so it is not necessary to use callbacks in block mode.
PICO_STATUS ps6000IsReady (short handle, short * ready);
Robin
- Attachments
-
- PS6000.zip
- (722.36 KiB) Downloaded 473 times
Re: PS4000 Series - Callback Function Pointer for MATLAB&LAB
Thankyou Robin for your quick reply, I will attempt using the new drivers now.
Regards,
Alex.
Regards,
Alex.
Re: PS4000 Series - Callback Function Pointer for MATLAB&LAB
Unfortunately the newer driver had the exact same effect as stated earlier. When passed a NULL pointer in the PS6000RunBlock function, Matlab crashes immediately.
Since this I have written a Mex file which acts as a wrapper for the PS6000RunBlock function, also containing the callback and wait -for-ready functionality ( as Thilo suggested).
The code looks correct but does not seem to be linking properly when attempting to compile in matlab.
The Matlab call results in .
Does anybody have any suggestions for fixing this? Your help would be greatly appreciated.
Regards,
Alex
Since this I have written a Mex file which acts as a wrapper for the PS6000RunBlock function, also containing the callback and wait -for-ready functionality ( as Thilo suggested).
The code looks correct but does not seem to be linking properly when attempting to compile in matlab.
The Matlab call
Code: Select all
mex myRunBlock.c
Code: Select all
myrunblock.obj .text: undefined reference to '_ps6000RunBlock@36'
C:\MATLAB701\BIN\WIN32\MEX.PL: Error: Link of 'myRunBlock.dll' failed.
Does anybody have any suggestions for fixing this? Your help would be greatly appreciated.
Regards,
Alex
Re: PS4000 Series - Callback Function Pointer for MATLAB&LAB
Submitted by Oleksiy:
Dear Alex,
I had similar problem and contacted support. I think the solution using mex file will be more difficult as it need deeper knowledge on linking in Matlab. Perhaps if you ask Matlab support they will help you. It have something to do with dynamic and static linking.
I suggest you use wrap library which is part of SDK, there header file also up to my knowledge. If you open two libraries in the beginning they share handles to your units automatically. So the only thing you change
is mentioning wrap library when calling RunBlock command - Status =
calllib('ps4000wrap',ps4000RunBlock,UnitHandle.....
For inspiration I attach file of my program for three units with all required library files. This program worked well. There troubles in memory management when more than one unit is used. It is somewhere between Matlab, java and ps4000 library, which I was not able to solve.
So I finish with Matlab-Picoscope coupling and solve it by writing in C one-task program.
Best luck.
Oleksiy Chumak.
- Attachments
-
- PicoMatlab.zip
- (400.47 KiB) Downloaded 574 times