www.gusucode.com > opcgui 工具箱 matlab 源码程序 > opcgui/opcDataAccessExplorer.m

    function varargout = opcDataAccessExplorer(fileName)
%OPC Data Access Explorer 
%   opcDataAccessExplorer opens the OPC Data Access Explorer app. Graphically browse the
%   contents of an OPC server, view server item properties, and create and configure OPC
%   Toolbox clients, groups and items. Read and write OPC data, configure and start a logging
%   session and export logged data to the workspace.
%
%   Clients, groups and items configured using the OPC Data Access Explorer can be exported
%   to the workspace, to a MAT-file or as an OPC Session File which can be imported into the
%   app at a later stage.
%
%   opcDataAccessExplorer(SessionName) opens the OPC Data Access Explorer app and loads a
%   previously saved OPC Session File. SessionName is the name of the OPC Session File to load.
%   If an extension is not specified in SessionName, .osf is used.
%
%   See also openosf.
%

% Copyright 2003-2013 The MathWorks, Inc.
% coded by OPTI-NUM solutions (Pty) Ltd.

try
    opcVer = opcmex('version');
catch ME
    throwAsCaller(ME);
end

% Make sure that the jvm and swing is available
error(javachk('swing','opcDataAccessExplorer'));

% Check if the user has a SIMULINK license available
blHasSimulink = license('test','simulink');

configDir = prefdir;

if nargin == 1
    % The user specified a session file name
    [pathStr,fName,fExt] = fileparts(fileName);
    if isempty(fExt)
        fileName = [fileName, '.osf'];
        [pathStr,fName,fExt] = fileparts(fileName);
    end
    % Try to get the full path to the file
    aFileName = which(fileName);
    if isempty(aFileName)
        % which cannot find the file
        if isempty(pathStr)
            % The file must be in the current directory
            fileName = fullfile(pwd,fileName);
        else
            % cd to the directory, get the pwd and cd back
            oldDir = cd;
            cd(pathStr);
            fileName = fullfile(pwd,[fName,fExt]);
            cd(oldDir);
        end
    else
        % which returned the file
        fileName = aFileName;
    end
    pathStr = fileparts(fileName);
    if ~exist(fileName,'file')
        error('opc:opctool:nofile', ...
            '%s does not exist or is not on the path.', fileName);
    end
    % Launch the GUI, and open the session file
    h = com.mathworks.toolbox.opc.OPCTool(opcVer, pathStr, blHasSimulink, fileName, configDir);
else
    % No session file, just launch the GUI
    h = com.mathworks.toolbox.opc.OPCTool(opcVer, pwd, blHasSimulink, configDir);
end
% Return output arguments if requested
if nargout == 1
    varargout{1} = h;
end