xxsimAddPort

PURPOSE ^

xxsimAddPort - Add a new port to the interface of an existing submodel.

SYNOPSIS ^

function retval = xxsimAddPort(submodelName, portName, isOutput, varargin)

DESCRIPTION ^

 xxsimAddPort - Add a new port to the interface of an existing submodel.

 Syntax:
   retval = xxsimAddPort(submodelName, portName, isOutput, portType, dataType,
            rows, columns, description, quantity, unit, domain, across,through,
            causality, hasSeparateHighAndLowTerminals,
            acceptsAnyNumberOfTerminals)

 Inputs:
   submodelName = Name of the submodel to obtain the port definitions from.
   portName     = Name of the new port to add
   isOutput     = true: output port, false: input port
   portType     = (Optional) The type of this port. 1=signal, 2=iconic, 3=bond
                  graph (default: 1 signal).
   dataType     = (Optional) The data type for this port. 1=real, 2=integer,
                  3=boolean, 4=string (default: 1 real)
   rows         = (Optional) The row size for this port (default: 1)
   columns      = (Optional) The column size for this port (default: 1)
   description  = (Optional) The description text for this port (default:
                  empty)
   quantity     = (Optional) The quantity of the port (signal-only; default:
                  empty)
   unit         = (Optional) The unit of the port (signal-only; default: empty)
   domain       = (Optional) Domain of the port (iconic /bond graph-only;
                  default: empty)
   across       = (Optional) The across variable for this port (iconic /bond
                  graph-only; default: empty)
   through      = (Optional) The through variable for this port (iconic /bond
                  graph-only; default: empty)
   causality    = (Optional)
   hasSeparateHighAndLowTerminals = (Optional) Set to true to separate the high
                  and low terminals. Typically used for e.g. for electric
                  circuit ports (default: false)
   acceptsAnyNumberOfTerminals    = (Optional) Set to true to allow to connect
                  more than 1 signal (default: false)

 Outputs:
   retval = true on success, false on failure

 Examples:
   retval = xxsimAddPort('PID', 'enable', false, 1, 3)

     - adds an 'enable' input signal with data type boolean to the submodel
       "PID".

 Author: Controllab Products B.V.
 Email: info@controllab.nl
 Website: https://www.20sim.com
 August 2023

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function retval = xxsimAddPort(submodelName, portName, isOutput, varargin)
0002 % xxsimAddPort - Add a new port to the interface of an existing submodel.
0003 %
0004 % Syntax:
0005 %   retval = xxsimAddPort(submodelName, portName, isOutput, portType, dataType,
0006 %            rows, columns, description, quantity, unit, domain, across,through,
0007 %            causality, hasSeparateHighAndLowTerminals,
0008 %            acceptsAnyNumberOfTerminals)
0009 %
0010 % Inputs:
0011 %   submodelName = Name of the submodel to obtain the port definitions from.
0012 %   portName     = Name of the new port to add
0013 %   isOutput     = true: output port, false: input port
0014 %   portType     = (Optional) The type of this port. 1=signal, 2=iconic, 3=bond
0015 %                  graph (default: 1 signal).
0016 %   dataType     = (Optional) The data type for this port. 1=real, 2=integer,
0017 %                  3=boolean, 4=string (default: 1 real)
0018 %   rows         = (Optional) The row size for this port (default: 1)
0019 %   columns      = (Optional) The column size for this port (default: 1)
0020 %   description  = (Optional) The description text for this port (default:
0021 %                  empty)
0022 %   quantity     = (Optional) The quantity of the port (signal-only; default:
0023 %                  empty)
0024 %   unit         = (Optional) The unit of the port (signal-only; default: empty)
0025 %   domain       = (Optional) Domain of the port (iconic /bond graph-only;
0026 %                  default: empty)
0027 %   across       = (Optional) The across variable for this port (iconic /bond
0028 %                  graph-only; default: empty)
0029 %   through      = (Optional) The through variable for this port (iconic /bond
0030 %                  graph-only; default: empty)
0031 %   causality    = (Optional)
0032 %   hasSeparateHighAndLowTerminals = (Optional) Set to true to separate the high
0033 %                  and low terminals. Typically used for e.g. for electric
0034 %                  circuit ports (default: false)
0035 %   acceptsAnyNumberOfTerminals    = (Optional) Set to true to allow to connect
0036 %                  more than 1 signal (default: false)
0037 %
0038 % Outputs:
0039 %   retval = true on success, false on failure
0040 %
0041 % Examples:
0042 %   retval = xxsimAddPort('PID', 'enable', false, 1, 3)
0043 %
0044 %     - adds an 'enable' input signal with data type boolean to the submodel
0045 %       "PID".
0046 %
0047 % Author: Controllab Products B.V.
0048 % Email: info@controllab.nl
0049 % Website: https://www.20sim.com
0050 % August 2023
0051 
0052 %------------- BEGIN CODE --------------
0053     % Check if the submodelName is a string.
0054     if(~ischar(submodelName))
0055         error('Please specify a valid submodel name.');
0056     end
0057     
0058     % Check if the portName is a string.
0059     if(~ischar(portName))
0060         error('Please specify a valid port name.');
0061     end
0062     
0063     % Check that we have at least 3 arguments
0064     if(nargin < 3)
0065         error('Not enough input arguments were specified.');
0066     end
0067     
0068     % set the default values for the optional arguments
0069     portType = 1;
0070     dataType = 1;
0071     rows = 1;
0072     columns = 1;
0073     quantity='';
0074     unit='';
0075     domain = '';
0076     across = '';
0077     through = '';
0078     causality = '';
0079     hasSeparateHighAndLowTerminals = false;
0080     acceptsAnyNumberOfTerminals = false;
0081     description = '';
0082 
0083     % Optional argument 4: portType
0084     if(nargin > 3)
0085         portType = varargin{1};
0086         if(~isnumeric(portType))
0087             error('Argument 4 (portType) should be numeric');
0088         end
0089     end
0090     % Optional argument 5: dataType
0091     if(nargin > 4)
0092         dataType = varargin{2};
0093         if(~isnumeric(portType))
0094             error('Argument 5 (dataType) should be numeric');
0095         end
0096     end
0097     % Optional argument 6: rows
0098     if(nargin > 5)
0099         rows = varargin{3};
0100         if(~isnumeric(rows))
0101             error('Argument 6 (rows) should be numeric');
0102         end
0103     end
0104     % Optional argument 7: columns
0105     if(nargin > 6)
0106         columns = varargin{4};
0107         if(~isnumeric(columns))
0108             error('Argument 7 (columns) should be numeric');
0109         end
0110     end
0111     % Optional argument 8: description
0112     if(nargin > 7)
0113         description = varargin{5};
0114         if(~ischar(description))
0115             error('Argument 8 (description) should be a string');
0116         end
0117     end
0118     % Optional argument 9: quantity
0119     if(nargin > 8)
0120         quantity = varargin{6};
0121         if(~ischar(quantity))
0122             error('Argument 9 (quantity) should be a string');
0123         end
0124     end
0125     % Optional argument 10: unit
0126     if(nargin > 9)
0127         unit = varargin{7};
0128         if(~ischar(unit))
0129             error('Argument 10 (unit) should be a string');
0130         end
0131     end
0132     % Optional argument 11: domain
0133     if(nargin > 10)
0134         domain = varargin{8};
0135         if(~ischar(domain))
0136             error('Argument 11 (domain) should be a string');
0137         end
0138     end
0139     % Optional argument 12: across
0140     if(nargin > 11)
0141         across = varargin{9};
0142         if(~ischar(across))
0143             error('Argument 12 (across) should be a string');
0144         end
0145     end
0146     % Optional argument 13: through
0147     if(nargin > 12)
0148         through = varargin{10};
0149         if(~ischar(through))
0150             error('Argument 13 (through) should be a string');
0151         end
0152     end
0153     % Optional argument 14: causality
0154     if(nargin > 13)
0155         causality = varargin{11};
0156         if(~ischar(causality))
0157             error('Argument 14 (causality) should be a string');
0158         end
0159     end
0160     % Optional argument 15: hasSeparateHighAndLowTerminals
0161     if(nargin > 14)
0162         hasSeparateHighAndLowTerminals = varargin{12};
0163         if(~islogical(hasSeparateHighAndLowTerminals))
0164             error('Argument 15 (hasSeparateHighAndLowTerminals) should be a boolean');
0165         end
0166     end
0167     % Optional argument 16: acceptsAnyNumberOfTerminals
0168     if(nargin > 15)
0169         acceptsAnyNumberOfTerminals = varargin{13};
0170         if(~islogical(acceptsAnyNumberOfTerminals))
0171             error('Argument 16 (acceptsAnyNumberOfTerminals) should be a boolean');
0172         end
0173     end
0174 
0175     % invoke 20-sim with the xmlrpc call
0176     size = struct('rows', int32(rows), 'columns', int32(columns));
0177     portDefinition = struct('name', portName,
0178         'portType', int32(portType),
0179         'size', size,
0180         'orientationOut', isOutput,
0181         'quantity', quantity,
0182         'unit', unit,
0183         'dataType', int32(dataType),
0184         'domain', domain,
0185         'across', across,
0186         'through', through,
0187         'causality', causality,
0188         'hasSeparateHighAndLowTerminals', hasSeparateHighAndLowTerminals,
0189         'acceptsAnyNumberOfTerminals', acceptsAnyNumberOfTerminals,
0190         'description', description);
0191     inputs = struct('submodelName', submodelName, 'portDefinition', portDefinition);
0192 
0193     retval = xrlinvoke('xxsim.model.addPort', inputs);
0194 end

Generated on Thu 25-Apr-2024 10:30:24