Serialio
Class SerInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended bySerialio.SerInputStream

public class SerInputStream
extends java.io.InputStream

Create an input stream on the serial port object.

  • Copyright (c) 1997-2004 Serialio.com, All Rights Reserved.


    Field Summary
    protected  SerialPort sp
               
     
    Constructor Summary
    SerInputStream(SerialPort sp)
              Create a serial port input stream.
     
    Method Summary
     void abort()
              Abort the current read
     int available()
              Indicates the number of bytes ready for reading
     void close()
              Closes this input stream
     int getNapTime()
               
     boolean getNativeBlock()
               
     int getRcvFrameChar()
               
     int getRcvThreshold()
               
     int getRcvTimeout()
               
     int read()
              Reads data from the input stream.
     int read(byte[] buf)
              Reads data from the input stream NOTE: framing is ignored by this method, use read() for framing NOTE: if threshold & timeout are enabled, and timeout occurs before threshold is reached, method will return available data.
     int read(byte[] buf, int off, int len)
              Reads data from the input stream NOTE: framing is ignored by this method, use read() for framing NOTE: if threshold & timeout are enabled, and timeout occurs before threshold is reached, method will return available data.
     void setNapTime(int time)
              Set the nap time used when the method sleeps
     void setNativeBlock(boolean onOff)
              Control if block is done in Java or native code when more bytes are requested than are available.
     void setRcvFrameChar(int data)
              Set to -1 to disable
     void setRcvThreshold(int thresh)
              Set thresh to 1 to 'disable'
     void setRcvTimeout(int timeout)
              Set receive timeout in milliseconds.
     
    Methods inherited from class java.io.InputStream
    mark, markSupported, reset, skip
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    sp

    protected SerialPort sp
    Constructor Detail

    SerInputStream

    public SerInputStream(SerialPort sp)
                   throws java.io.IOException
    Create a serial port input stream. The read timeout on the SerialPort object is set to 0 since WinNT does not multi-thread as nice as other OS's

    Parameters:
    sp - a valid open SerialPort object
    Method Detail

    read

    public int read()
             throws java.io.IOException
    Reads data from the input stream. IMPORTANT NOTE: behaviour is only identical to Java InputStream when timeout, threshold, & framing are default values (disabled)

    Returns:
    the next byte of data, or -1 if timeout
    Throws:
    java.io.IOException - if an I/O error occurs.

    read

    public int read(byte[] buf)
             throws java.io.IOException
    Reads data from the input stream NOTE: framing is ignored by this method, use read() for framing NOTE: if threshold & timeout are enabled, and timeout occurs before threshold is reached, method will return available data.

    Parameters:
    buf - the byte array buffer where data will be put when read
    Returns:
    the total number of bytes read into the buffer
    Throws:
    java.io.IOException - if an I/O error occurs.

    read

    public int read(byte[] buf,
                    int off,
                    int len)
             throws java.io.IOException
    Reads data from the input stream NOTE: framing is ignored by this method, use read() for framing NOTE: if threshold & timeout are enabled, and timeout occurs before threshold is reached, method will return available data. NOTE: if you wish to detect a timeout on the port, the preferred method is to use the read() as it will return -1 on timeout.

    Parameters:
    buf - the byte array buffer where data will be put when read
    off - the offset in the buffer where data will be put
    len - the length of data requested to be put in the buffer
    Returns:
    the total number of bytes read into the buffer
    Throws:
    java.io.IOException - if an error occurs.

    available

    public int available()
                  throws java.io.IOException
    Indicates the number of bytes ready for reading

    Returns:
    the number of bytes available for reading
    Throws:
    java.io.IOException - if an I/O error occurs.

    close

    public void close()
               throws java.io.IOException
    Closes this input stream

    Throws:
    java.io.IOException - if an I/O error occurs.

    abort

    public void abort()
    Abort the current read


    setRcvThreshold

    public void setRcvThreshold(int thresh)
    Set thresh to 1 to 'disable'


    getRcvThreshold

    public int getRcvThreshold()

    setRcvTimeout

    public void setRcvTimeout(int timeout)
    Set receive timeout in milliseconds. Use 0 to disable


    getRcvTimeout

    public int getRcvTimeout()

    setRcvFrameChar

    public void setRcvFrameChar(int data)
    Set to -1 to disable


    getRcvFrameChar

    public int getRcvFrameChar()

    setNapTime

    public void setNapTime(int time)
    Set the nap time used when the method sleeps


    getNapTime

    public int getNapTime()

    setNativeBlock

    public void setNativeBlock(boolean onOff)
    Control if block is done in Java or native code when more bytes are requested than are available. Using BufferedReader setNativeBlock(true).


    getNativeBlock

    public boolean getNativeBlock()