Error Connecting to Picoscope in Compiled Exe App

Post your MATLAB discussions here
Post Reply
JYWongXeron
Newbie
Posts: 0
Joined: Tue Jul 26, 2022 12:17 pm

Error Connecting to Picoscope in Compiled Exe App

Post by JYWongXeron »

I have written a very simple app that has a pushbutton which, when pressed, runs the example code "PS3000A_ID_Block_Example.m" from the Picoscope 3000 Series A API MATLAB Generic Instrument Driver addon, as shown below.

Code: Select all

function testGUI2()
    %% Base App Figure
    app.fig = uifigure;
    app.fig.Name = 'Pilot Cable Fault Pinpointing Recognition System';
    app.fig.Position = [100,200,350,300];
    movegui(app.fig, 'center');
    
    %% Create UI elements
    app.gl = uigridlayout(app.fig, [2,1]);
    app.gl.RowHeight = {'2x', '0.5x'};
    
    %% Button
    app.btn = uibutton(app.gl, 'push');
    app.btn.Layout.Row = 2;
    app.btn.Layout.Column = 1;
    
    set(app.btn, 'ButtonPushedFcn', @(src, event) btnPushed());
    
        function btnPushed()
            PS3000A_ID_Block_Example()
        end
end
When I run this on MATLAB R2019a, everything works fine.
But when I compile this app and run the app, it gives the following error in my log file:

Code: Select all

Warning: Escaped character '\P' is not valid. See 'doc sprintf' for supported special characters.
Warning: Folder C:
Error using icdevice (line 259)
The specified MATLAB instrument driver could not be found.  DRIVER must be on the MATLAB path.
Error in PS3000A_ID_Block_Example (line 48)
Error in testGUI2/btnPushed (line 20)
Error in testGUI2>@(src,event)btnPushed() (line 17)
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 335)
Error while evaluating Button PrivateButtonPushedFcn.
Can anyone please tell me how to solve this error or why is this error even happening ? Thank you very much!

Martyn
Site Admin
Site Admin
Posts: 4499
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Error Connecting to Picoscope in Compiled Exe App

Post by Martyn »

In your code, or the instrument driver, do you have any paths as strings? it looks like you may need to change them to use \\ for each occurrence of \

Code: Select all

C:\Program Files

should become

C:\\Program Files
which is why you are getting the warning about Escaped character '\P' is not valid.
Martyn
Technical Support Manager

JYWongXeron
Newbie
Posts: 0
Joined: Tue Jul 26, 2022 12:17 pm

Re: Error Connecting to Picoscope in Compiled Exe App

Post by JYWongXeron »

I have not used any paths as strings in my own code.
So I created a copy of the PS3000aConfig.m file in the MATLAB addon folder i.e. C:\Users\~\AppData\Roaming\MathWorks\MATLAB Add-Ons\Hardware Supports\PicoScope 3000 Series A API MATLAB Generic Instrument Driver) and replaced any occurrence of \ with \\ as you suggested.

then I edited my main GUI code to use the new PS3000aConfig.m, which is shown:

Code: Select all

%% PS3000ACONFIG Configure path and parameter information
% Configures paths according to platforms and loads information from
% prototype files for PicoScope 3000 Series (A API) Oscilloscopes. The folder 
% that this file is located in must be added to the MATLAB path.
%
% Platform Specific Information:-
%
% Microsoft Windows: Download the Software Development Kit installer from
% the Pico Technology Download software and manuals for oscilloscopes and data loggers page.
% 
% Linux: Follow the instructions to install the libps3000a and libpswrappers
% packages from the Pico Technology Linux Software & Drivers for Oscilloscopes and Data Loggers page.
%
% Apple Mac OS X: Follow the instructions to install the PicoScope 6
% application from the Pico Technology Download software and manuals for oscilloscopes and data loggers page.
% Optionally, create a 'maci64' folder in the same directory as this file
% and copy the following files into it:
% 
% * libps3000a.dylib and any other libps3000a library files
% * libps3000aWrap.dylib and any other libps3000aWrap library files
% * libpicoipp.dylib and any other libpicoipp library files
% * libiomp5.dylib
%
% Contact our Technical Support team via the Technical Enquiries form for further assistance.
%
% Run this script in the MATLAB environment prior to connecting to the 
% device.
%
% This file can be edited to suit application requirements.

%% Set Path to Shared Libraries
% Set paths to shared library files according to the operating system and
% architecture.

% Identify architecture e.g. 'win64'

archStr = computer('arch');

% Identify working directory
ps3000aConfigInfo.workingDir = pwd;
ps3000aConfigInfo.workingDir = strrep(ps3000aConfigInfo.workingDir, '\', '\\');

% Find file name
ps3000aConfigInfo.configFileName = mfilename('fullpath');
ps3000aConfigInfo.configFileName = strrep(ps3000aConfigInfo.configFileName, '\', '\\');

% Only require the path to the config file
[ps3000aConfigInfo.pathStr] = fileparts(ps3000aConfigInfo.configFileName);

% Identify architecture e.g. 'win64'
ps3000aConfigInfo.archStr = computer('arch');

try

    addpath(fullfile(ps3000aConfigInfo.pathStr, ps3000aConfigInfo.archStr));
    
catch err
    
    error('PS3000aConfig:OperatingSystemNotSupported', 'Operating system not supported - please contact support@picotech.com');
    
end

% Set the path according to operating system.

if(ismac())
    
    % Libraries (including wrapper libraries) are stored in the PicoScope
    % 6 App folder. Add locations of library files to environment variable.
    
    setenv('DYLD_LIBRARY_PATH', '/Applications/PicoScope6.app/Contents/Resources/lib');
    
    if(strfind(getenv('DYLD_LIBRARY_PATH'), '/Applications/PicoScope6.app/Contents/Resources/lib'))
       
        addpath('/Applications/PicoScope6.app/Contents/Resources/lib');
        
    else
        
        warning('PS3000aConfig:LibraryPathNotFound','Locations of libraries not found in DYLD_LIBRARY_PATH');
        
    end
    
elseif(isunix())
	    
    % Edit to specify location of .so files or place .so files in same directory
    addpath('/opt/picoscope/lib/'); 
		
elseif(ispc())
    
    % Microsoft Windows operating systems
    
    % Set path to dll files if the Pico Technology SDK Installer has been
    % used or place dll files in the folder corresponding to the
    % architecture. Detect if 32-bit version of MATLAB on 64-bit Microsoft
    % Windows.
    
    ps3000aConfigInfo.winSDKInstallPath = '';
    
    if(strcmp(ps3000aConfigInfo.archStr, 'win32') && exist('C:\\Program Files (x86)\\', 'dir') == 7)
       
        try 
            
            addpath('C:\\Program Files (x86)\\Pico Technology\\SDK\\lib\\');
            ps3000aConfigInfo.winSDKInstallPath = 'C:\\Program Files (x86)\\Pico Technology\\SDK';
            
        catch err
           
            warning('PS3000aConfig:DirectoryNotFound', ['Folder C:\\Program Files (x86)\\Pico Technology\\SDK\\lib\\ not found. '...
                'Please ensure that the location of the library files are on the MATLAB path.']);
            
        end
        
    else
        
        % 32-bit MATLAB on 32-bit Windows or 64-bit MATLAB on 64-bit
        % Windows operating systems
        try 
        
            addpath('C:\\Program Files\\Pico Technology\\SDK\\lib\\');
            ps3000aConfigInfo.winSDKInstallPath = 'C:\\Program Files\\Pico Technology\\SDK';
            
        catch err
           
            warning('PS3000aConfig:DirectoryNotFound', ['Folder C:\\Program Files\\Pico Technology\\SDK\\lib\\ not found. '...
                'Please ensure that the location of the library files are on the MATLAB path.']);
            
        end
        
    end
    
else
    
    error('PS3000aConfig:OperatingSystemNotSupported', 'Operating system not supported - please contact support@picotech.com');
    
end

%% Set Path for PicoScope Support Toolbox Files if Not Installed
% Set MATLAB Path to include location of PicoScope Support Toolbox
% Functions and Classes if the Toolbox has not been installed. Installation
% of the toolbox is only supported in MATLAB 2014b and later versions.

% Check if PicoScope Support Toolbox is installed - using code based on
% 

ps3000aConfigInfo.psTbxName = 'PicoScope Support Toolbox';
ps3000aConfigInfo.v = ver; % Find installed toolbox information

if(~any(strcmp(ps3000aConfigInfo.psTbxName, {ps3000aConfigInfo.v.Name})))
   
    warning('PS3000aConfig:PSTbxNotFound', 'PicoScope Support Toolbox not found, searching for folder.');
    
    % If the PicoScope Support Toolbox has not been installed, check to see
    % if the folder is on the MATLAB path, having been downloaded via zip
    % file or copied from the Microsoft Windows Pico SDK installer
    % directory.
    
    ps3000aConfigInfo.psTbxFound = strfind(path, ps3000aConfigInfo.psTbxName);
    
    if(isempty(ps3000aConfigInfo.psTbxFound) && ispc())
        
        % Check if the folder is present in the relevant SDK installation
        % directory on Windows platforms (if the SDK installer has been
        % used).
        
        % Obtain the folder name
        ps3000aConfigInfo.psTbxFolderName = fullfile(ps3000aConfigInfo.winSDKInstallPath, 'MATLAB' , ps3000aConfigInfo.psTbxName);

        % If it is present in the SDK directory, add the PicoScope Support
        % Toolbox folder and sub-folders to the MATLAB path.
        if(exist(ps3000aConfigInfo.psTbxFolderName, 'dir') == 7)

            addpath(genpath(ps3000aConfigInfo.psTbxFolderName));

        end
            
    else
        
        warning('PS3000aConfig:PSTbxDirNotFound', 'PicoScope Support Toolbox directory not found.');
            
    end
    
end

% Change back to the folder where the script was called from.
cd(ps3000aConfigInfo.workingDir);

%% Load Enumerations and Structure Information
% Enumerations and structures are used by certain Intrument Driver functions.

% PLEASE DO NOT EDIT THE LINES BELOW
[ps3000aMethodinfo, ps3000aStructs, ps3000aEnuminfo, ps3000aThunkLibName] = ps3000aMFile; 
ps3000aThunkLibName = strrep(ps3000aThunkLibName, '\', '\\');

[ps3000aWrapMethodinfo, ps3000aWrapStructs, ps3000aWrapEnuminfo, ps3000aWrapThunkLibName] = ps3000aWrapMFile;
ps3000aWrapThunkLibName = strrep(ps3000aWrapThunkLibName, '\', '\\');

the compiled app generates a slightly different error now:

Code: Select all

Warning: Folder C:\Program Files\Pico Technology\SDK\lib\ not found. Please ensure that the location of the library files are on the MATLAB path.

Copyright © 2014-2017 Pico Technology Ltd. All rights reserved.

PicoScope 3000 Series MATLAB Instrument Driver

Error using instrument/delete (line 82)
Operation failed: An error occurred while executing the driver disconnect code.
Dot indexing is not supported for variables of this type.
If this error is not an instrument error, use MIDEDIT to inspect the driver.

Error in icdevice (line 311)

Error in PS3000A_ID_Block_Example (line 50)

Error in testGUI2/btnPushed (line 20)

Error in testGUI2>@(src,event)btnPushed() (line 17)

Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 335)
Error while evaluating Button PrivateButtonPushedFcn.

Martyn
Site Admin
Site Admin
Posts: 4499
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Error Connecting to Picoscope in Compiled Exe App

Post by Martyn »

Code: Select all

Warning: Folder C:\Program Files\Pico Technology\SDK\lib\ not found. Please ensure that the location of the library files are on the MATLAB path.
Would suggest you don't have the SDK installed
Martyn
Technical Support Manager

JYWongXeron
Newbie
Posts: 0
Joined: Tue Jul 26, 2022 12:17 pm

Re: Error Connecting to Picoscope in Compiled Exe App

Post by JYWongXeron »

Alright, I have now uninstalled the PicoSDK and I got the following error when running the compiled app

Code: Select all

Warning: Name is nonexistent or not a directory: C:\Program Files\Pico Technology\SDK\lib

Copyright © 2014-2017 Pico Technology Ltd. All rights reserved.

PicoScope 3000 Series MATLAB Instrument Driver

Error using instrument/delete (line 82)
Operation failed: An error occurred while executing the driver disconnect code.
Dot indexing is not supported for variables of this type.
If this error is not an instrument error, use MIDEDIT to inspect the driver.

Error in icdevice (line 311)

Error in PS3000A_ID_Block_Example (line 50)

Error in testGUI2/btnPushed (line 20)

Error in testGUI2>@(src,event)btnPushed() (line 17)

Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 335)
Error while evaluating Button PrivateButtonPushedFcn.

Martyn
Site Admin
Site Admin
Posts: 4499
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Error Connecting to Picoscope in Compiled Exe App

Post by Martyn »

Sorry for the misunderstanding, I didn't mean uninstall the SDK, just that the warning was suggesting it wasn't there so would need installing. So reinstall it and if the same error comes up it has something to do with where the compiled application is looking for the library files.

You can always try copying ps3000a.dll and picoipp.dll from the SDK lib folder to the same directory as your executable and see if this works.
Martyn
Technical Support Manager

JYWongXeron
Newbie
Posts: 0
Joined: Tue Jul 26, 2022 12:17 pm

Re: Error Connecting to Picoscope in Compiled Exe App

Post by JYWongXeron »

OK I have reinstalled the SDK and recompiled the app.
I have also included the ps3000a.dll and picoipp.dll from the SDK lib folder to the same directory as the executable, as shown in the attached screenshot below.

I still get the same error as follows.

Code: Select all

Warning: Folder C:\Program Files\Pico Technology\SDK\lib\ not found. Please ensure that the location of the library files are on the MATLAB path.

Copyright © 2014-2017 Pico Technology Ltd. All rights reserved.

PicoScope 3000 Series MATLAB Instrument Driver

Error using instrument/delete (line 82)
Operation failed: An error occurred while executing the driver disconnect code.
Dot indexing is not supported for variables of this type.
If this error is not an instrument error, use MIDEDIT to inspect the driver.

Error in icdevice (line 311)

Error in PS3000A_ID_Block_Example (line 50)

Error in testGUI2/btnPushed (line 20)

Error in testGUI2>@(src,event)btnPushed() (line 17)

Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 335)
Error while evaluating Button PrivateButtonPushedFcn.

Attachments
Untitled.png

Post Reply