Class SerialService

java.lang.Object
com.dalsemi.onewire.adapter.SerialService
All Implemented Interfaces:
gnu.io.SerialPortEventListener, EventListener

public class SerialService extends Object implements gnu.io.SerialPortEventListener

The SerialService class provides serial IO services to the USerialAdapter class.

  • Constructor Details

    • SerialService

      protected SerialService(String strComPort)
      this constructor only for use in the static method: getSerialService(String)
  • Method Details

    • CleanUpByThread

      public static void CleanUpByThread(Thread t)
      Cleans up the resources used by the thread argument. If another thread starts communicating with this port, and then goes away, there is no way to relinquish the port without stopping the process. This method allows other threads to clean up.
      Parameters:
      thread - that may have used a USerialAdapter
    • getSerialService

      public static SerialService getSerialService(String strComPort)
    • serialEvent

      public void serialEvent(gnu.io.SerialPortEvent spe)
      SerialPortEventListener method. This just calls the notify method on this object, so that all blocking methods are kicked awake whenever a serialEvent occurs.
      Specified by:
      serialEvent in interface gnu.io.SerialPortEventListener
    • openPort

      public void openPort() throws IOException
      Throws:
      IOException
    • openPort

      public void openPort(gnu.io.SerialPortEventListener spel) throws IOException
      Throws:
      IOException
    • setNotifyOnDataAvailable

      public void setNotifyOnDataAvailable(boolean notify)
    • getSerialPortIdentifiers

      public static Enumeration<String> getSerialPortIdentifiers()
    • getPortName

      public String getPortName()
    • isPortOpen

      public boolean isPortOpen()
    • isDTR

      public boolean isDTR()
    • setDTR

      public void setDTR(boolean newDTR)
    • isRTS

      public boolean isRTS()
    • setRTS

      public void setRTS(boolean newRTS)
    • sendBreak

      public void sendBreak(int duration)
      Send a break on this serial port
      Parameters:
      duration - - break duration in ms
    • getBaudRate

      public int getBaudRate()
    • setBaudRate

      public void setBaudRate(int baudRate) throws IOException
      Throws:
      IOException
    • closePort

      public void closePort() throws IOException
      Close this serial port.
      Throws:
      IOException - - if port is in use by another application
    • flush

      public void flush() throws IOException
      Throws:
      IOException
    • beginExclusive

      public boolean beginExclusive(boolean blocking)
      Gets exclusive use of the 1-Wire to communicate with an iButton or 1-Wire Device. This method should be used for critical sections of code where a sequence of commands must not be interrupted by communication of threads with other iButtons, and it is permissible to sustain a delay in the special case that another thread has already been granted exclusive access and this access has not yet been relinquished.

      Parameters:
      blocking - true if want to block waiting for exclusive access to the adapter
      Returns:
      true if blocking was false and a exclusive session with the adapter was acquired
    • endExclusive

      public void endExclusive()
      Relinquishes exclusive control of the 1-Wire Network. This command dynamically marks the end of a critical section and should be used when exclusive control is no longer needed.
    • haveExclusive

      public boolean haveExclusive()
      Check if this thread has exclusive control of the port.
    • available

      public int available() throws IOException
      Throws:
      IOException
    • read

      public int read() throws IOException
      Throws:
      IOException
    • read

      public int read(byte[] buffer) throws IOException
      Throws:
      IOException
    • read

      public int read(byte[] buffer, int offset, int length) throws IOException
      Throws:
      IOException
    • readWithTimeout

      public int readWithTimeout(byte[] buffer, int offset, int length) throws IOException
      Throws:
      IOException
    • readWithTimeout

      public char[] readWithTimeout(int length) throws IOException
      Throws:
      IOException
    • write

      public void write(int data) throws IOException
      Throws:
      IOException
    • write

      public void write(byte[] data, int offset, int length) throws IOException
      Throws:
      IOException
    • write

      public void write(byte[] data) throws IOException
      Throws:
      IOException
    • write

      public void write(String data) throws IOException
      Throws:
      IOException
    • write

      public void write(char data) throws IOException
      Throws:
      IOException
    • write

      public void write(char[] data) throws IOException
      Throws:
      IOException
    • write

      public void write(char[] data, int offset, int length) throws IOException
      Throws:
      IOException