private void openSerialPort(CommPortIdentifier commPortIdentifier) {
        if (openedPort != null) {
            serialPort.close();
        }
        if (commPortIdentifier != null) {
            try {
                serialPort = (SerialPort) commPortIdentifier.open("MonitorConsole", 2000);
            } 
            catch (PortInUseException e) {
                serialPort = null;
                System.out.println(e);
            }
            if (serialPort != null) {
                try {
                    outputStream = serialPort.getOutputStream();
                    inputStream = serialPort.getInputStream();
                } 
                catch (IOException e) {
                    System.out.println(e);
                }
                setSerialPortParams();
            }
            serialPort.notifyOnDataAvailable(true);
            try {
                serialPort.addEventListener(new CommPortListener());
            }
            catch (TooManyListenersException e) {
                    System.out.println(e);
            }
        }
        openedPort = commPortIdentifier;
    }