public static synchronized ModbusSlave createSerialSlave ( SerialParameters serialParams ) throws ModbusException { ModbusSlave slave = null ; if ( serialParams == null ) { throw new ModbusException ( "Serial parameters are null" ) ; } else if ( ModbusUtil . isBlank ( serialParams . getPortName ( ) ) ) { throw new ModbusException ( "Serial port name is empty" ) ; } // If we have a slave already assigned to this port if ( slaves . containsKey ( serialParams . getPortName ( ) ) ) { slave = slaves . get ( serialParams . getPortName ( ) ) ; // Check if any of the parameters have changed if ( ! serialParams . toString ( ) . equals ( slave . getSerialParams ( ) . toString ( ) ) ) { close ( slave ) ; slave = null ; } } // If we don;t have a slave, create one if ( slave == null ) { slave = new ModbusSlave ( serialParams ) ; slaves . put ( serialParams . getPortName ( ) , slave ) ; return slave ; } return slave ; }
Creates a serial modbus slave or returns the one already allocated to this port