Beispiel #1
0
 /**
  * Port opening <br>
  * <br>
  * <b>Note: </b>If port busy <b>TYPE_PORT_BUSY</b> exception will be thrown. If port not found
  * <b>TYPE_PORT_NOT_FOUND</b> exception will be thrown.
  *
  * @return If the operation is successfully completed, the method returns true
  * @throws SerialPortException
  */
 public boolean openPort() throws SerialPortException {
   if (portOpened) {
     throw new SerialPortException(
         portName, "openPort()", SerialPortException.TYPE_PORT_ALREADY_OPENED);
   }
   if (portName != null) {
     boolean useTIOCEXCL =
         (System.getProperty(SerialNativeInterface.PROPERTY_JSSC_NO_TIOCEXCL) == null
             && System.getProperty(SerialNativeInterface.PROPERTY_JSSC_NO_TIOCEXCL.toLowerCase())
                 == null);
     portHandle =
         serialInterface.openPort(
             portName,
             useTIOCEXCL); // since 2.3.0 -> (if JSSC_NO_TIOCEXCL defined, exclusive lock for
                           // serial port will be disabled)
   } else {
     throw new SerialPortException(
         portName,
         "openPort()",
         SerialPortException.TYPE_NULL_NOT_PERMITTED); // since 2.1.0 -> NULL port name fix
   }
   if (portHandle == SerialNativeInterface.ERR_PORT_BUSY) {
     throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_PORT_BUSY);
   } else if (portHandle == SerialNativeInterface.ERR_PORT_NOT_FOUND) {
     throw new SerialPortException(
         portName, "openPort()", SerialPortException.TYPE_PORT_NOT_FOUND);
   } else if (portHandle == SerialNativeInterface.ERR_PERMISSION_DENIED) {
     throw new SerialPortException(
         portName, "openPort()", SerialPortException.TYPE_PERMISSION_DENIED);
   } else if (portHandle == SerialNativeInterface.ERR_INCORRECT_SERIAL_PORT) {
     throw new SerialPortException(
         portName, "openPort()", SerialPortException.TYPE_INCORRECT_SERIAL_PORT);
   }
   portOpened = true;
   return true;
 }