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

    function [success, errMsg] = vntslcbpreapply(obj, dlg)
%VNTSLCBPREAPPLY Callback to apply changes made in the DDG mask.
%
%    [SUCCESS, ERRMSG] = VNTSLCBPREAPPLY(OBJ, DLG) callback that applies changes from
%    the dynamic dialog DLG to OBJ, the dialog's source object. Returns S
%    as false to indicate failure, or true to indicate success. If any
%    errors need to be returned, it is provided in the string E.
%
%    This function is invoked every time the mask is closed using the OK
%    button or whenever the Apply button is pressed.

%    SS 04-01-08
%    Copyright 2008-2012 The MathWorks, Inc.

% Initialize.
success = true;
errMsg = '';

% Check if the user is operating on the library. If so, the mask is
% disabled so don't apply anything to avoid dirtying the library.
if isDisableDialog(dlg)
    return;
end

block = class(obj);
if strcmpi(block, 'vntdialog.canconfiguration')
    if ~strcmp(obj.Device, '(none)') && ~obj.ObjectCreationFailed
        success = privatecanslbusspeed (dlg, obj.BusSpeed, 'Apply');
        if ~success
            return;
        end
    end
end

% 1) Apply changes to the DDG fields.
% preApplyCallback is a C++ function that returns a success and error
% message.  For about 3-4 months (late '03), in the M world, it was
% returning these arguments in a reverse order. This appears to be fixed,
% but check to make sure.
[success, errMsg] = obj.preApplyCallback(dlg);
if ischar(success)
    warning(message('vnt:vntblks:ddgApply'));
    tmp = success;
    success = errMsg;
    errMsg = tmp;
end

% 2) Apply changes to the actual block.
% Note, when a block parameter is changed, it will trigger a call
% to the S-Function's mdlInitializeSizes routine.
% Update specific block fields based on the subsystem

switch block
    case 'vntdialog.canconfiguration'
        obj.Block.Device = obj.Device;
        obj.Block.DeviceMenu = obj.DeviceMenu;
        if strcmp(obj.Device, '(none)')
            return;
        end
        obj.Block.ObjConstructor = obj.ObjConstructor;        
        obj.Block.BusSpeed = obj.BusSpeed;
        if (obj.EnableBitParameters)
            obj.Block.EnableBitParameters = 'on';
        else
            obj.Block.EnableBitParameters = 'off';
        end
        obj.Block.SJW = obj.SJW;
        obj.Block.TSEG1 = obj.TSEG1;
        obj.Block.TSEG2 = obj.TSEG2;
        obj.Block.NSamples = obj.NSamples;
        obj.Block.AckMode = obj.AckMode;
    case 'vntdialog.canreceive'
        obj.Block.Device = obj.Device;
        obj.Block.DeviceMenu = obj.DeviceMenu;
        obj.Block.ObjConstructor = obj.ObjConstructor;    
        if (obj.EnableStandardIDsFilter)
            obj.Block.EnableStandardIDsFilter = 'on';
        else
            obj.Block.EnableStandardIDsFilter = 'off';
        end
        obj.Block.StandardIDs = obj.StandardIDs;
        if (obj.EnableExtendedIDsFilter)
            obj.Block.EnableExtendedIDsFilter = 'on';
        else
            obj.Block.EnableExtendedIDsFilter = 'off';
        end
        obj.Block.StdIDsCombo = obj.StdIDsCombo;
        obj.Block.ExtIDsCombo = obj.ExtIDsCombo;
        % Set that Filter Status has been updated.
        obj.Block.InternalFilterUpdateStatus = 'on';
        
        obj.Block.ExtendedIDs = obj.ExtendedIDs;
        obj.Block.SampleTime = obj.SampleTime;
        obj.Block.MsgsPerTimestep = obj.MsgsPerTimestep;
        % Check if CAN Configuration block is present
        privatecansladdconfig(obj, 'Receive');
    case 'vntdialog.cantransmit'
        obj.Block.Device = obj.Device;
        obj.Block.DeviceMenu = obj.DeviceMenu;
        obj.Block.ObjConstructor = obj.ObjConstructor;
        if (obj.EnablePeriodicTransmit)
            obj.Block.EnablePeriodicTransmit = 'on';
        else
            obj.Block.EnablePeriodicTransmit = 'off';
        end        
        obj.Block.MessagePeriod = obj.MessagePeriod;
        % Check if CAN Configuration block is present
        privatecansladdconfig(obj, 'Transmit');
    case 'vntdialog.canlog'
        obj.Block.FullPathFileName = obj.FullPathFileName;        
        [~, name, ext] = fileparts(obj.Block.FullPathFileName);
        obj.Block.FileName = strcat(name, ext);
        obj.Block.VariableName = obj.VariableName;
        obj.Block.MaxNumMessages = obj.MaxNumMessages;
        obj.Block.LogFrom = obj.LogFrom;
        obj.Block.Device = obj.Device;
        obj.Block.DeviceMenu = obj.DeviceMenu;
        obj.Block.ObjConstructor = obj.ObjConstructor;
        obj.Block.SampleTime = obj.SampleTime;
        if strcmpi(obj.Block.LogFrom, 'CAN Bus') && ...
            ~(strcmpi(obj.DeviceMenu, 'Select a device') || strcmpi(obj.DeviceMenu, '(none)'))
            % Check if CAN Configuration block is present
            privatecansladdconfig(obj, 'Log');
        end        
    case 'vntdialog.canreplay'
        obj.Block.FullPathFileName = obj.FullPathFileName;
        [~, name, ext] = fileparts(obj.Block.FullPathFileName);
        obj.Block.FileName = strcat(name, ext);
        obj.Block.VariableName = obj.VariableName;
        obj.Block.NoTimesReplay = obj.NoTimesReplay;
        obj.Block.ReplayTo = obj.ReplayTo;
        obj.Block.Device = obj.Device;
        obj.Block.DeviceMenu = obj.DeviceMenu;
        obj.Block.ObjConstructor = obj.ObjConstructor;
        obj.Block.SampleTime = obj.SampleTime;      
        if strcmpi(obj.Block.ReplayTo, 'CAN Bus') && ...
            ~(strcmpi(obj.DeviceMenu, 'Select a device') || strcmpi(obj.DeviceMenu, '(none)'))
            % Check if CAN Configuration block is present
            privatecansladdconfig(obj, 'Replay');
        end
    case 'vntdialog.xcpcantl'
        obj.Block.Device = obj.Device;
        obj.Block.DeviceMenu = obj.DeviceMenu;
        obj.Block.ObjConstructor = obj.ObjConstructor;
        obj.Block.BusSpeedStr = obj.BusSpeedStr;
        obj.Block.SampleTime = obj.SampleTime;
    case 'vntdialog.j1939cantl'
        obj.Block.Device = obj.Device;
        obj.Block.DeviceMenu = obj.DeviceMenu;
        obj.Block.ObjConstructor = obj.ObjConstructor;
        obj.Block.ConfigName = obj.ConfigName;
        obj.Block.BusSpeedStr = obj.BusSpeedStr;
        obj.Block.SampleTime = obj.SampleTime;        
    otherwise
        assert(false, 'vnt:vntblks:InvalidBlock', 'Invalid block.');
end