/** * Add port. * * @param simulinkBlock block to add port to * @param portType port type * @param portNumber number of this port */ private void addPort(SimulinkBlock simulinkBlock, EPortType portType, int portNumber) { if (portType.in) { new SimulinkInPort(simulinkBlock, portType.createPortName(portNumber)); } else { new SimulinkOutPort(simulinkBlock, portType.createPortName(portNumber)); } }
/** * Build port. * * @param portIndex index of the port (refers to {@link EPortType}). * @param portCount number of ports * @param simulinkBlock block this ports belong to * @param section MDL section that describes the block * @throws SimulinkModelBuildingException if an illegal port setup was found */ private void processPort( int portIndex, int portCount, SimulinkBlock simulinkBlock, MDLSection section) throws SimulinkModelBuildingException { // nothing to do for zero ports if (portCount == 0) { return; } // check for an unknown port type if (portIndex >= EPortType.values().length) { throw new SimulinkModelBuildingException( "Block " + simulinkBlock + " at " + section + " has an unknown port with index " + portIndex); } // determine port type EPortType portType = EPortType.values()[portIndex]; // check that port type is supported if (portType.unsupported) { throw new SimulinkModelBuildingException( "Block " + simulinkBlock + " at " + section + " has an unsupported port type " + portType.name() + "."); } // check if there is more than port for a non-multiple port type if (portCount > 1 && !portType.multiple) { throw new SimulinkModelBuildingException( "Block " + simulinkBlock + " at " + section + " has an " + portCount + " " + portType.name() + " whereas only one is supported."); } // everything is ok, so add ports for (int i = 1; i <= portCount; i++) { addPort(simulinkBlock, portType, i); } }