Beispiel #1
0
 /**
  * Set events mask. Required flags shall be sent to the input. Variables with prefix
  * <b>"MASK_"</b>, shall be used as flags, for example <b>"MASK_RXCHAR"</b>. Sent parameter "mask"
  * is additive value, so addition of flags is allowed. For example if messages about data receipt
  * and CTS and DSR status changing shall be received, it is required to set the mask -
  * <b>"MASK_RXCHAR | MASK_CTS | MASK_DSR"</b>
  *
  * @return If the operation is successfully completed, the method returns true, otherwise false
  * @throws SerialPortException
  */
 public boolean setEventsMask(int mask) throws SerialPortException {
   checkPortOpened("setEventsMask()");
   if (SerialNativeInterface.getOsType() == SerialNativeInterface.OS_LINUX
       || SerialNativeInterface.getOsType() == SerialNativeInterface.OS_SOLARIS
       || SerialNativeInterface.getOsType() == SerialNativeInterface.OS_MAC_OS_X) { // since 0.9.0
     linuxMask = mask;
     if (mask > 0) {
       maskAssigned = true;
     } else {
       maskAssigned = false;
     }
     return true;
   }
   boolean returnValue = serialInterface.setEventsMask(portHandle, mask);
   if (!returnValue) {
     throw new SerialPortException(
         portName, "setEventsMask()", SerialPortException.TYPE_CANT_SET_MASK);
   }
   if (mask > 0) {
     maskAssigned = true;
   } else {
     maskAssigned = false;
   }
   return returnValue;
 }
Beispiel #2
0
 /**
  * Create new EventListener Thread depending on the type of operating system
  *
  * @since 0.8
  */
 private EventThread getNewEventThread() {
   if (SerialNativeInterface.getOsType() == SerialNativeInterface.OS_LINUX
       || SerialNativeInterface.getOsType() == SerialNativeInterface.OS_SOLARIS
       || SerialNativeInterface.getOsType() == SerialNativeInterface.OS_MAC_OS_X) { // since 0.9.0
     return new LinuxEventThread();
   }
   return new EventThread();
 }
Beispiel #3
0
 /**
  * Getting events mask for the port
  *
  * @return Method returns events mask as int type variable. This variable is an additive value
  * @throws SerialPortException
  */
 public int getEventsMask() throws SerialPortException {
   checkPortOpened("getEventsMask()");
   if (SerialNativeInterface.getOsType() == SerialNativeInterface.OS_LINUX
       || SerialNativeInterface.getOsType() == SerialNativeInterface.OS_SOLARIS
       || SerialNativeInterface.getOsType() == SerialNativeInterface.OS_MAC_OS_X) { // since 0.9.0
     return linuxMask;
   }
   return serialInterface.getEventsMask(portHandle);
 }
Beispiel #4
0
 /**
  * Get state of RLSD line
  *
  * @return If line is active, method returns true, otherwise false
  * @throws SerialPortException
  */
 public boolean isRLSD() throws SerialPortException {
   checkPortOpened("isRLSD()");
   if (serialInterface.getLinesStatus(portHandle)[3] == 1) {
     return true;
   } else {
     return false;
   }
 }
Beispiel #5
0
 /**
  * Close port. This method deletes event listener first, then closes the port
  *
  * @return If the operation is successfully completed, the method returns true, otherwise false
  * @throws SerialPortException
  */
 public boolean closePort() throws SerialPortException {
   checkPortOpened("closePort()");
   if (eventListenerAdded) {
     removeEventListener();
   }
   boolean returnValue = serialInterface.closePort(portHandle);
   if (returnValue) {
     maskAssigned = false;
     portOpened = false;
   }
   return returnValue;
 }
Beispiel #6
0
 /**
  * Setting the parameters of port
  *
  * @param baudRate data transfer rate
  * @param dataBits number of data bits
  * @param stopBits number of stop bits
  * @param parity parity
  * @param setRTS initial state of RTS line(ON/OFF)
  * @param setDTR initial state of DTR line(ON/OFF)
  * @return If the operation is successfully completed, the method returns true, otherwise false
  * @throws SerialPortException
  * @since 0.8
  */
 public boolean setParams(
     int baudRate, int dataBits, int stopBits, int parity, boolean setRTS, boolean setDTR)
     throws SerialPortException {
   checkPortOpened("setParams()");
   if (stopBits == 1) {
     stopBits = 0;
   } else if (stopBits == 3) {
     stopBits = 1;
   }
   int flags = 0;
   if (System.getProperty(SerialNativeInterface.PROPERTY_JSSC_IGNPAR) != null
       || System.getProperty(SerialNativeInterface.PROPERTY_JSSC_IGNPAR.toLowerCase()) != null) {
     flags |= PARAMS_FLAG_IGNPAR;
   }
   if (System.getProperty(SerialNativeInterface.PROPERTY_JSSC_PARMRK) != null
       || System.getProperty(SerialNativeInterface.PROPERTY_JSSC_PARMRK.toLowerCase()) != null) {
     flags |= PARAMS_FLAG_PARMRK;
   }
   return serialInterface.setParams(
       portHandle, baudRate, dataBits, stopBits, parity, setRTS, setDTR, flags);
 }
Beispiel #7
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;
 }
Beispiel #8
0
 /**
  * Read byte array from port
  *
  * @param byteCount count of bytes for reading
  * @return byte array with "byteCount" length
  * @throws SerialPortException
  */
 public byte[] readBytes(int byteCount) throws SerialPortException {
   checkPortOpened("readBytes()");
   return serialInterface.readBytes(portHandle, byteCount);
 }
Beispiel #9
0
 /**
  * Getting lines status. Lines status is sent as 0 – OFF and 1 - ON
  *
  * @return Method returns the array containing information about lines in following order: <br>
  *     <b>element 0</b> - <b>CTS</b> line state</br> <br>
  *     <b>element 1</b> - <b>DSR</b> line state</br> <br>
  *     <b>element 2</b> - <b>RING</b> line state</br> <br>
  *     <b>element 3</b> - <b>RLSD</b> line state</br>
  * @throws SerialPortException
  */
 public int[] getLinesStatus() throws SerialPortException {
   checkPortOpened("getLinesStatus()");
   return serialInterface.getLinesStatus(portHandle);
 }
Beispiel #10
0
 private int[][] waitEvents() {
   return serialInterface.waitEvents(portHandle);
 }
Beispiel #11
0
 /**
  * Send Break singnal for setted duration
  *
  * @param duration duration of Break signal
  * @return If the operation is successfully completed, the method returns true, otherwise false
  * @throws SerialPortException
  * @since 0.8
  */
 public boolean sendBreak(int duration) throws SerialPortException {
   checkPortOpened("sendBreak()");
   return serialInterface.sendBreak(portHandle, duration);
 }
Beispiel #12
0
 /**
  * Get flow control mode
  *
  * @return Mask of setted flow control mode
  * @throws SerialPortException
  * @since 0.8
  */
 public int getFlowControlMode() throws SerialPortException {
   checkPortOpened("getFlowControlMode()");
   return serialInterface.getFlowControlMode(portHandle);
 }
Beispiel #13
0
 /**
  * Set flow control mode. For required mode use variables with prefix <b>"FLOWCONTROL_"</b>.
  * Example of hardware flow control mode(RTS/CTS): setFlowControlMode(FLOWCONTROL_RTSCTS_IN |
  * FLOWCONTROL_RTSCTS_OUT);
  *
  * @return If the operation is successfully completed, the method returns true, otherwise false
  * @throws SerialPortException
  * @since 0.8
  */
 public boolean setFlowControlMode(int mask) throws SerialPortException {
   checkPortOpened("setFlowControlMode()");
   return serialInterface.setFlowControlMode(portHandle, mask);
 }
Beispiel #14
0
 /**
  * Get count of bytes in output buffer
  *
  * @return Count of bytes in output buffer or -1 if error occured
  * @throws SerialPortException
  * @since 0.8
  */
 public int getOutputBufferBytesCount() throws SerialPortException {
   checkPortOpened("getOutputBufferBytesCount()");
   return serialInterface.getBuffersBytesCount(portHandle)[1];
 }
Beispiel #15
0
 /**
  * Write byte array to port
  *
  * @return If the operation is successfully completed, the method returns true, otherwise false
  * @throws SerialPortException
  */
 public boolean writeBytes(byte[] buffer) throws SerialPortException {
   checkPortOpened("writeBytes()");
   return serialInterface.writeBytes(portHandle, buffer);
 }
Beispiel #16
0
 /**
  * Change DTR line state. Set "true" for switching ON and "false" for switching OFF DTR line
  *
  * @return If the operation is successfully completed, the method returns true, otherwise false
  * @throws SerialPortException
  */
 public boolean setDTR(boolean enabled) throws SerialPortException {
   checkPortOpened("setDTR()");
   return serialInterface.setDTR(portHandle, enabled);
 }
Beispiel #17
0
 /**
  * Purge of input and output buffer. Required flags shall be sent to the input. Variables with
  * prefix <b>"PURGE_"</b>, for example <b>"PURGE_RXCLEAR"</b>. Sent parameter "flags" is additive
  * value, so addition of flags is allowed. For example, if input or output buffer shall be purged,
  * parameter <b>"PURGE_RXCLEAR | PURGE_TXCLEAR"</b>. <br>
  * <b>Note: </b>some devices or drivers may not support this function
  *
  * @return If the operation is successfully completed, the method returns true, otherwise false.
  * @throws SerialPortException
  */
 public boolean purgePort(int flags) throws SerialPortException {
   checkPortOpened("purgePort()");
   return serialInterface.purgePort(portHandle, flags);
 }