Connect PicoScope 5444B within function

Post your MATLAB discussions here
Post Reply
MoJou
Newbie
Posts: 0
Joined: Fri Jan 29, 2016 10:25 am

Connect PicoScope 5444B within function

Post by MoJou »

Hello,
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
PS5000aConfig;
%% 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
connect(ps5000aDeviceObj);
%do something ...
disconnect(ps5000aDeviceObj);

end

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
exist. 
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)
                delete(obj);

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

Regards

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

Re: Connect PicoScope 5444B within function

Post by MoJou »

Hi,

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

Code: Select all

  disp('test1')

    if(isstruct(evalin('base', 'ps5000aEnuminfo')) && isstruct(evalin('base', 'ps5000aStructs')))
    disp('test2')
        % Do nothing - structures have been loaded
    
    else
       disp('test3')
       error('Failed to load enumerations and/or structures from ps5000aMFile');
    
    end
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?
Regards

Hitesh

Re: Connect PicoScope 5444B within function

Post by Hitesh »

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.

Regards,

Post Reply