gusucode.com > vnt工具箱matlab源码程序 > vnt/vntblks/vntmasks/private/privatevntsldevicesetup.m

    function privatevntsldevicesetup(obj, allDevices, objConstructors)
%PRIVATEVNTSLDEVICESETUP Validates the current device selection.
%
%    PRIVATEVNTSLDEVICESETUP(OBJ, ALLDEVICES, OBJCONSTRUCTORS)
%    validates the device selection value contained in OBJ, a DDG object,
%    using ALLDEVICES, a list of available devices, and OBJCONSTRUCTORS, a list of
%    object constructors. 

%    SS 09-19-06
%    Copyright 2006-2012 The MathWorks, Inc.

localValidateDeviceSelection(obj, allDevices, objConstructors);
localUpdateDeviceInformation(obj);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function localValidateDeviceSelection(obj, allDevices, objConstructors)

% If the current device selected is valid, update the device menu and
% return. 
if ismember(obj.Device, allDevices),
    selectedIndex = find( strcmp(allDevices, obj.Device)==true );
    obj.DeviceMenu = obj.Device;
    obj.ObjConstructor = objConstructors{selectedIndex}; %#ok<FNDSB>
    return;
end

errorStrings = privatevntslstring('errorstrings');

% If the device is invalid and something other than 'none'.
if ~strcmpi(obj.Device,'(none)')
    % Selected device is invalid. 
    if ~strcmpi(allDevices{1},'(none)'),
        msg = sprintf(errorStrings.DifferentDevice, obj.Device, allDevices{1});
    else
        msg = errorStrings.NoDevice;
    end
    
    % Create a modal error dialog. 
    uiwait( errordlg(msg, errorStrings.DeviceErrorTitle, 'modal') );
end

% If the current selection was '(none)' we silently select the first
% available device.
obj.IsDifferentDevice = true;
obj.Device = allDevices{1};
obj.DeviceMenu = allDevices{1};
obj.ObjConstructor = objConstructors{1};

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function localUpdateDeviceInformation(obj)

if strcmpi(class(obj), 'vntdialog.xcpcantl') || ...
   strcmpi(class(obj), 'vntdialog.j1939cantl') || ...
   strcmpi(obj.Device, '(none)') || ...
   strcmpi(obj.Device, 'Select a device')
    return;
elseif ~(obj.IsDifferentDevice) && ...
        (~isempty(obj.CANObject) && isvalid(obj.CANObject))
    return;
elseif obj.IsDifferentDevice
    if ~isempty(obj.CANObject) && isvalid(obj.CANObject)
        % Clean up our previous CAN object. 
        delete(obj.CANObject);
    end
end

% Create the CAN object for the device selected. 

switch class(obj)
    case 'vntdialog.canconfiguration'
        try
            obj.CANObject = eval(obj.ObjConstructor);
        catch %#ok<CTCH>
            %@TODO: To generate error if this condition occurs.
            % Create a modal error dialog. 
            errorStrings = privatevntslstring('errorstrings');
            msg = sprintf(errorStrings.DeviceInaccessible, obj.Device);
            uiwait( errordlg(msg, errorStrings.DeviceErrorTitle, 'modal') );            
            obj.ObjectCreationFailed = true;
            return;
        end
        obj.ObjectCreationFailed = false;
    case {'vntdialog.canreceive' 'vntdialog.cantransmit' 'vntdialog.canreplay' 'vntdialog.canlog' }
    otherwise
        assert(false, 'vnt:vntblks:InvalidBlock', 'Invalid block');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%