public Boolean connect()
    {
         try {
			selectedPortIdentifier = CommPortIdentifier.getPortIdentifier( portname);
		} catch (NoSuchPortException e1) {
			setConnected(false);
			error = "Port <"+portname+"> not found !";
			trytolog(error);
			return false;
		}
		
        //Required port found in system : We can think Ultra meter is plugged on system !
        CommPort commPort = null;

        try
        {
    
            //the method below returns an object of type CommPort
        	commPort = selectedPortIdentifier.open("GlucoMeter", TIMEOUT);
            //the CommPort object can be casted to a SerialPort object
            serialPort = (SerialPort)commPort;
            if(this.mode == 0) {
            	serialPort.setSerialPortParams(9600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
            	serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
            } else {
            	System.out.println("Setting for CP2103");
            	serialPort.setSerialPortParams(9600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
            	//serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
            	//serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN | SerialPort.FLOWCONTROL_RTSCTS_OUT);
            	serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_XONXOFF_IN + SerialPort.FLOWCONTROL_XONXOFF_OUT);

            }
            
            //for controlling GUI elements
            setConnected(true);
            //logging
            error = "Port <"+portname+"> opened successfully\n";
			trytolog(error);
			currbuf = new byte[256];
            return true;
            
        } catch (PortInUseException e) {
            error = portname + " is in use. (" + e.toString() + ")\n";
            trytolog(error);
        } catch (Exception e) {
        	e.printStackTrace();
            logText = "Failed to open " + portname + "(" + e.toString() + ")";
            trytolog(logText);
        }
        return false;
    }