gusucode.com > target工具箱matlab源码程序 > target/foundation/blks/masks/setOutPortType.m

    function [status, errMsg] = setOutPortType(action, blk, portNum, portName, portStorageClass)
%
% status = makePortInportedExternPtr(portNum)

% Copyright 2005-2014 The MathWorks, Inc.

errMsg = '';
status = 0;

switch action
    case 'delete'
        ports = get_param(blk, 'PortHandles');
        numOutPorts = length(ports.Outport);
        for i = 1 : numOutPorts
            outPortHandle = ports.Outport(portNum(i));
            portName = get_param(outPortHandle, 'Name');
            if ~isempty(portName)
                try
                    set_param(outPortHandle, 'Name', '');
                catch evalException
                    status = -1;
                    errMsg = evalException.message;
                end
            end
        end
    case 'set'
        ports = get_param(blk, 'PortHandles');
        numOutPorts = length(ports.Outport);
        for i = 1 : length(portNum)
            % Check the validity of the port number
            if ( (portNum(i) < 1) || (portNum(i) > numOutPorts) )
                continue;
            end
            
            % Set the port name first. Otherwise we cannot set the
            % RTWStorageClass
            outPortHandle = ports.Outport(portNum(i));
            name = get_param(outPortHandle, 'Name');
            storageClass = get_param(outPortHandle, 'RTWStorageClass');
            if ~isequal(name, portName{i})
                set_param(outPortHandle, 'Name', portName{i});
            end
            if ~isequal(storageClass, portStorageClass{i})
                set_param(outPortHandle, 'RTWStorageClass', portStorageClass{i});
            end
        end
    case 'checkAndSet'
        ports = get_param(blk, 'PortHandles');
        
        %Check if the specified port has the name set and RTWStrorageClass
        %set to ImportedExternPointer
        maskType = get_param(blk, 'MaskType');
        for i = 1 : length(portNum)
            outPortHandle = ports.Outport(portNum(i));
            
            %Check if the signal is named
            name = get_param(outPortHandle, 'Name');
            storageClass = get_param(outPortHandle, 'RTWStorageClass');
            if ( ~strcmp(name, portName{i}) || ~strcmp(storageClass, portStorageClass{i}) )
                question = sprintf('Signal at output port %d of <%s> block must be named to "%s" and its RTWStorageClass must be set to "%s". Do you want to perform this operation automatically?', ...
                    i, maskType, portName{i}, portStorageClass{i});
                buttonName = questdlg(question, 'DM642 Video Port', 'OK', 'Cancel', 'OK');
                if ( strcmp(buttonName, 'OK') )
                    if ~isequal(name, portName{i})
                        set_param(outPortHandle, 'Name', portName{i});
                    end
                    if ~isequal(storageClass, portStorageClass{i})
                        set_param(outPortHandle, 'RTWStorageClass', portStorageClass{i});
                    end
                else
                    status = -1; %#ok<NASGU>
                    error(message('TARGETFOUNDATION:blocks:InvalidOuputSignal', num2str(i), maskType));
                end
            end
        end
end
end