Serialio
Class SerOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended bySerialio.SerOutputStream

public class SerOutputStream
extends java.io.OutputStream

Create an output stream on the serial port object.

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


    Field Summary
    protected  SerialPort sp
               
     
    Constructor Summary
    SerOutputStream(SerialPort sp)
              Create a serial port output stream.
     
    Method Summary
     void close()
              Close the port.
     void flush()
              Causes any buffered data on the output stream to be written.
     void flushAbort()
              Aborts flush.
     int getTxBlockSize()
               
     boolean getWriteDrain()
               
     int getWriteTimeout()
               
     void setTxBlockSize(int size)
              Sets the block size used to send data.
     void setWriteDrain(boolean onOff)
              Set txDrain mode for write().
     void setWriteTimeout(int tmo)
              Aborts flush based on timeout.
     void write(byte[] b)
              Writes the data on the output stream.
     void write(byte[] b, int off, int len)
              Writes the data on the output stream.
     void write(int b)
              Writes the byte on the output stream
     
    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

    SerOutputStream

    public SerOutputStream(SerialPort sp)
                    throws java.io.IOException
    Create a serial port output stream. The write timeout on the SerialPort object is set to the maximum value (about 24 days)

    Parameters:
    sp - a valid SerialPort object
    Method Detail

    write

    public void write(int b)
               throws java.io.IOException
    Writes the byte on the output stream

    Parameters:
    b - the data byte
    Throws:
    java.io.IOException - if an error occurs.

    write

    public void write(byte[] b)
               throws java.io.IOException
    Writes the data on the output stream. Java OutputStream writes all data using the write() call. We use a more efficient method.

    Parameters:
    b - the byte array of data
    Throws:
    java.io.IOException - if an I/O error occurs.

    write

    public void write(byte[] b,
                      int off,
                      int len)
               throws java.io.IOException
    Writes the data on the output stream.

    Parameters:
    b - 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.

    flush

    public void flush()
               throws java.io.IOException
    Causes any buffered data on the output stream to be written. Note: when using txDrain be advised that some OS's (like WinNT) do not provide a timeout on the OS level drain/flush call. In this case if handshake (flow control) is disabled from the far end your txDrain call will block until drain can complete. (i.e. until the handshake state changes). Because of this the default mechanism for flush is to watch the txBuffer. This will allow you to abort a stalled OutputStream since your code will not be locked up at the native level.

    Throws:
    java.io.IOException - if an error occurs.

    setWriteDrain

    public void setWriteDrain(boolean onOff)
    Set txDrain mode for write(). The default is enabled. When enabled, the write() method will drain the queue before it returns.


    getWriteDrain

    public boolean getWriteDrain()

    flushAbort

    public void flushAbort()
    Aborts flush.


    close

    public void close()
               throws java.io.IOException
    Close the port.

    Throws:
    java.io.IOException

    setWriteTimeout

    public void setWriteTimeout(int tmo)
                         throws java.io.IOException
    Aborts flush based on timeout.

    Throws:
    java.io.IOException

    getWriteTimeout

    public int getWriteTimeout()

    setTxBlockSize

    public void setTxBlockSize(int size)
    Sets the block size used to send data. Caveat: If the request to send data is larger than the transmit queue of the driver, this may cause a subsequent transmit call to fail.


    getTxBlockSize

    public int getTxBlockSize()