Test and Measurement Forum

Connect PicoScope 5444B within function

Post your MATLAB discussions here

Connect PicoScope 5444B within function

Postby MoJou » Tue Apr 19, 2016 4:29 pm

I am trying to connect the PicoScope 5444B within a function call. When I use the example-Scripts i.e. PS5000A_IC_Generic_Driver_Block.m everything is fine. Also sometimes connecting a device with for example

Code: Select all
function somefunction( void )
%SOMEFUNCTION Summary of this function goes here
%   Detailed explanation goes here
%% Device Connection
% Create device -  specify serial number if required
% Specify serial number as 2nd argument if required.
ps5000aDeviceObj = icdevice('picotech_ps5000a_generic.mdd');
% Connect device
%do something ...


it is working. But somehow at some point matlab is no longer able to connect the device. It gives the error message
Code: Select all
Warning: The data type 'FcnPtr' used by function ps5000aRunBlock does not exist.
Warning: The data type 'FcnPtr' used by function ps5000aGetStreamingLatestValues does not
Close unit status: 12
Error using instrument/delete (line 82)
Operation failed: An error occurred while executing the driver disconnect code.
Unit not closed.
If this error is not an instrument error, use MIDEDIT to inspect the driver.

Error in icdevice (line 310)

Error in Stream (line 119)
ps5000aDeviceObj = icdevice('picotech_ps5000a_generic.mdd');

When i run exactly the same code as script i got no issues.

Connecting the device within a function worked before several times. I changed nothing. Now I am not longer to connect the device within a function. Restarting the System, Reconnecting the device didnt help.

With the Picoscope 4225B there is no problem like this.

I am using
-Windows 7 64 Bit
-Matlab 2015b 64 Bit
-Example-Files and library from PicoSDK

For more Version-Information:
(Creation Date of PS5000A_IC_GENERIC_DRIVER_BLOCK is Creation time: 05-Jul-2013 13:00:29)
The Example-Files from Mathworks File-Exchange are not working

Posts: 0
Joined: Fri Jan 29, 2016 10:25 am

Re: Connect PicoScope 5444B within function

Postby MoJou » Wed Apr 20, 2016 7:02 am


actually the problem seems to be in picotech_ps5000a_generic.mdd. I added the following outputs (test1 to test3):
Code: Select all

    if(isstruct(evalin('base', 'ps5000aEnuminfo')) && isstruct(evalin('base', 'ps5000aStructs')))
        % Do nothing - structures have been loaded
       error('Failed to load enumerations and/or structures from ps5000aMFile');

When running my function only test1 is visible, then the error occurs. So the Problem is that
Code: Select all
isstruct(evalin('base', 'ps5000aEnuminfo'))

does not work within a function. Replacing 'base' with 'caller' does also not work. In the Picoscope 4000 driver there is no line like this, so there is no problem. My simple solution is to initially connect and disconnect the device (in a script) and afterwards call the function. This works but it is not that "nice". Do you have better suggestions?
Posts: 0
Joined: Fri Jan 29, 2016 10:25 am

Re: Connect PicoScope 5444B within function

Postby Hitesh » Wed Apr 20, 2016 8:30 am

Hi Mojou,

The issue occurs when calling the code from within a function as the Instrument Driver is expecting to find the enumerations struct from the base workspace as opposed to the function workspace.

There is a workaround shown in this MATLAB Answers post.

We will be fixing the Instrument Driver in the next release to resolve this issue.

Please note that Pico Technology is not responsible for the content of external sites.


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