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 January 2021
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 % January 2021 0051 0052 %------------- BEGIN CODE -------------- 0053 0054 % Check if the submodelName is a string. 0055 if(~ischar(submodelName)) 0056 error('Please specify a valid submodel name.'); 0057 end; 0058 0059 % Check if the portName is a string. 0060 if(~ischar(portName)) 0061 error('Please specify a valid port name.'); 0062 end; 0063 0064 % Check that we have at least 3 arguments 0065 if(nargin < 3) 0066 error('Not enough input arguments were specified.'); 0067 end; 0068 0069 % set the default values for the optional arguments 0070 portType = 1; 0071 dataType = 1; 0072 rows = 1; 0073 columns = 1; 0074 quantity=''; 0075 unit=''; 0076 domain = ''; 0077 across = ''; 0078 through = ''; 0079 causality = ''; 0080 hasSeparateHighAndLowTerminals = false; 0081 acceptsAnyNumberOfTerminals = false; 0082 description = ''; 0083 0084 % Optional argument 4: portType 0085 if(nargin > 3) 0086 portType = varargin{1}; 0087 if(~isnumeric(portType)) 0088 error('Argument 4 (portType) should be numeric'); 0089 end; 0090 end; 0091 % Optional argument 5: dataType 0092 if(nargin > 4) 0093 dataType = varargin{2}; 0094 if(~isnumeric(portType)) 0095 error('Argument 5 (dataType) should be numeric'); 0096 end; 0097 end; 0098 % Optional argument 6: rows 0099 if(nargin > 5) 0100 rows = varargin{3}; 0101 if(~isnumeric(rows)) 0102 error('Argument 6 (rows) should be numeric'); 0103 end; 0104 end; 0105 % Optional argument 7: columns 0106 if(nargin > 6) 0107 columns = varargin{4}; 0108 if(~isnumeric(columns)) 0109 error('Argument 7 (columns) should be numeric'); 0110 end; 0111 end; 0112 % Optional argument 8: description 0113 if(nargin > 7) 0114 description = varargin{5}; 0115 if(~ischar(description)) 0116 error('Argument 8 (description) should be a string'); 0117 end; 0118 end; 0119 % Optional argument 9: quantity 0120 if(nargin > 8) 0121 quantity = varargin{6}; 0122 if(~ischar(quantity)) 0123 error('Argument 9 (quantity) should be a string'); 0124 end; 0125 end; 0126 % Optional argument 10: unit 0127 if(nargin > 9) 0128 unit = varargin{7}; 0129 if(~ischar(unit)) 0130 error('Argument 10 (unit) should be a string'); 0131 end; 0132 end; 0133 % Optional argument 11: domain 0134 if(nargin > 10) 0135 domain = varargin{8}; 0136 if(~ischar(domain)) 0137 error('Argument 11 (domain) should be a string'); 0138 end; 0139 end; 0140 % Optional argument 12: across 0141 if(nargin > 11) 0142 across = varargin{9}; 0143 if(~ischar(across)) 0144 error('Argument 12 (across) should be a string'); 0145 end; 0146 end; 0147 % Optional argument 13: through 0148 if(nargin > 12) 0149 through = varargin{10}; 0150 if(~ischar(through)) 0151 error('Argument 13 (through) should be a string'); 0152 end; 0153 end; 0154 % Optional argument 14: causality 0155 if(nargin > 13) 0156 causality = varargin{11}; 0157 if(~ischar(causality)) 0158 error('Argument 14 (causality) should be a string'); 0159 end; 0160 end; 0161 % Optional argument 15: hasSeparateHighAndLowTerminals 0162 if(nargin > 14) 0163 hasSeparateHighAndLowTerminals = varargin{12}; 0164 if(~islogical(hasSeparateHighAndLowTerminals)) 0165 error('Argument 15 (hasSeparateHighAndLowTerminals) should be a boolean'); 0166 end; 0167 end; 0168 % Optional argument 16: acceptsAnyNumberOfTerminals 0169 if(nargin > 15) 0170 acceptsAnyNumberOfTerminals = varargin{13}; 0171 if(~islogical(acceptsAnyNumberOfTerminals)) 0172 error('Argument 16 (acceptsAnyNumberOfTerminals) should be a boolean'); 0173 end; 0174 end; 0175 0176 % invoke 20-sim with the xmlrpc call 0177 size = struct('rows', int32(rows), 'columns', int32(columns)); 0178 portDefinition = struct('name', portName, 0179 'portType', int32(portType), 0180 'size', size, 0181 'orientationOut', isOutput, 0182 'quantity', quantity, 0183 'unit', unit, 0184 'dataType', int32(dataType), 0185 'domain', domain, 0186 'across', across, 0187 'through', through, 0188 'causality', causality, 0189 'hasSeparateHighAndLowTerminals', hasSeparateHighAndLowTerminals, 0190 'acceptsAnyNumberOfTerminals', acceptsAnyNumberOfTerminals, 0191 'description', description); 0192 inputs = struct('submodelName', submodelName, 'portDefinition', portDefinition); 0193 0194 retval = xrlinvoke('xxsim.model.addPort', inputs); 0195 end