Class SerialService

  • All Implemented Interfaces:
    gnu.io.SerialPortEventListener, java.util.EventListener

    public class SerialService
    extends java.lang.Object
    implements gnu.io.SerialPortEventListener

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

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected SerialService​(java.lang.String strComPort)
      this constructor only for use in the static method: getSerialService(String)
    • Constructor Detail

      • SerialService

        protected SerialService​(java.lang.String strComPort)
        this constructor only for use in the static method: getSerialService(String)
    • Method Detail

      • CleanUpByThread

        public static void CleanUpByThread​(java.lang.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​(java.lang.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 java.io.IOException
        Throws:
        java.io.IOException
      • openPort

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

        public void setNotifyOnDataAvailable​(boolean notify)
      • getSerialPortIdentifiers

        public static java.util.Enumeration<java.lang.String> getSerialPortIdentifiers()
      • getPortName

        public java.lang.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 java.io.IOException
        Throws:
        java.io.IOException
      • closePort

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

        public void flush()
                   throws java.io.IOException
        Throws:
        java.io.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 java.io.IOException
        Throws:
        java.io.IOException
      • read

        public int read()
                 throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] buffer)
                 throws java.io.IOException
        Throws:
        java.io.IOException
      • read

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

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

        public char[] readWithTimeout​(int length)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • write

        public void write​(int data)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • write

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

        public void write​(byte[] data)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • write

        public void write​(java.lang.String data)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • write

        public void write​(char data)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • write

        public void write​(char[] data)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • write

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