www.gusucode.com > ArmCortexMFastModelSupportPackage > ArmCortexMFastModelSupportPackage/CortexM-VirtualPlatform-Supplements/+matlabshared/+target/+armcortexmvirtualtarget/externalModeLoadAndRun.m

    function externalModeLoadAndRun(hCS,executableFile,u,varargin)
    %EXTERNALMODELOADANDRUN External Mode wrapper around load and run.
    % Tracks the PID and output file for an external mode simulation.
    %
    %   Copyright 2018 Arm Holdings
    
    % Get run info instance
    runInfo = matlabshared.target.armcortexmvirtualtarget.VirtualPlatformRunInfo.getInstance();    
    
    % Get the PID, port, and outputfile of the application running on the host
    [pid, port, outfile] = matlabshared.target.armcortexmvirtualtarget.loadAndRun(hCS, executableFile, u, varargin{:});
    
    % Store the PID and outputfile in the run info
    runInfo.addPIDOutFile(get(hCS.getModel(), 'Name'), pid, outfile);

    
    %Set the dynamic port number    
    data = codertarget.data.getData(hCS);
    switch (data.ExtMode.Configuration)
        case 'Ethernet IO'
            ip = data.ConnectionInfo.EthernetIO.IPAddress;
            verbosity = data.ConnectionInfo.EthernetIO.Verbose;    
            
            % create external mode arguments overriding the port number with the
            % dynamic one.
            extModeArgs = sprintf('''%s'' %d %s', ip, verbosity, port);
        case 'XCP Ethernet IO'
            ip = data.ConnectionInfo.XCPEthernetIO.IPAddress;
            verbosity = data.ConnectionInfo.XCPEthernetIO.Verbose;            
            symbolsFileName = '';
            
            % create external mode arguments overriding the port number with the
            % dynamic one.
            extModeArgs = sprintf('''%s'' %d %s %s', ip, verbosity, port, symbolsFileName);
        otherwise
            assert('Unrecognized External Mode Configuration');
    end
    
    set_param(hCS, 'ExtModeMexArgs', extModeArgs); %breaks rtwbuild, makes model dirty (unsaved changs)
    
end