//setting connection parameters
try {
serialPort.setSerialPortParams(PORT_BAUDRATE, PORT_DATABITS, PORT_STOPBITS, PORT_PARITY);
serialPort.enableReceiveTimeout(PORT_IN_TIMEOUT);
serialPort.enableReceiveThreshold(PORT_IN_THRESHOLD);
} catch (UnsupportedCommOperationException e) {
System.out.println("Parameters not allowed for port \"" + port.getName() + "\".");
serialPort.close();
return null;
}