Serialio
Class SnoopLoop

java.lang.Object
  extended bySerialio.SnoopLoop
All Implemented Interfaces:
java.util.EventListener, SnoopListener

public class SnoopLoop
extends java.lang.Object
implements SnoopListener

Used to look for data patterns in a SnoopInputStream. This is a 'convenience' class in that it does not require method caller to read the SnoopInputStream directly to 'make things happen' and provides a timeout.

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


    Field Summary
    protected  java.io.InputStream in
               
     
    Constructor Summary
    SnoopLoop()
              This empty constructor is for Bean friendlyness
    SnoopLoop(SnoopLoopListener lsnr, SnoopInputStream sis, int napTime)
              Create an input stream that allows 'snooping' for data patterns on incoming data
     
    Method Summary
     void abort()
              Abort this task
     boolean getDataDiscard(boolean onOff)
              Get the 'data discard' mode.
     int getNapTime()
              Get the nap time used when the method sleeps.
     byte[] getReadBuffer()
              Get the current read buffer.
     void setDataDiscard(boolean onOff)
              Set the 'data discard' mode.
     void setNapTime(int time)
              Set the nap time used when the method sleeps.
     void setReadBuffer(byte[] buf)
              Set the read buffer used when snooping for data
     void snoopEvent(byte[] data)
              This method is called by the SnoopInputStream when the data pattern is sighted.
     int waitFor(byte[] sData, int tmo)
              Wait for data pattern to occur on SnoopInputStream.
     int waitFor(int wCnt, int tmo)
              Wait for specified number of bytes to arrive on the stream.
     int waitFor(java.lang.String sData, int tmo)
              Wait for data pattern to occur on SnoopInputStream.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    in

    protected java.io.InputStream in
    Constructor Detail

    SnoopLoop

    public SnoopLoop()
    This empty constructor is for Bean friendlyness


    SnoopLoop

    public SnoopLoop(SnoopLoopListener lsnr,
                     SnoopInputStream sis,
                     int napTime)
    Create an input stream that allows 'snooping' for data patterns on incoming data

    Parameters:
    lsnr - The SnoopLoopListener that will be called when data is received on the stream.
    sis - The SnoopInputStream to look for data pattern.
    napTime - The timeout if the pattern is not seen.
    Method Detail

    waitFor

    public int waitFor(java.lang.String sData,
                       int tmo)
                throws java.io.IOException,
                       java.lang.InterruptedException
    Wait for data pattern to occur on SnoopInputStream. While snooping for pattern received data is passed to the SnoopLoopListener.

    Parameters:
    sData - The data pattern.
    tmo - The timeout if the pattern is not seen. Notes: - If other snoops exist for the given SnoopInputStream they may be called before this method completes. - If the data received is larger than the size of the save buffer the data at the start of the buffer will be overwritten. - For performance reasons the save buffer is not cleared between calls if you wish to clear the save buffer between calls use setReadBuffer.
    Throws:
    java.io.IOException
    java.lang.InterruptedException

    waitFor

    public int waitFor(byte[] sData,
                       int tmo)
                throws java.io.IOException,
                       java.lang.InterruptedException
    Wait for data pattern to occur on SnoopInputStream. While snooping for pattern received data is passed to the SnoopLoopListener.

    Parameters:
    sData - The data pattern.
    tmo - The timeout if the pattern is not seen. Notes: - If other snoops exist for the given SnoopInputStream they may be called before this method completes. - If the data received is larger than the size of the save buffer the data at the start of the buffer will be overwritten. - For performance reasons the save buffer is not cleared between calls if you wish to clear the save buffer between calls use setReadBuffer.
    Throws:
    java.io.IOException
    java.lang.InterruptedException

    waitFor

    public int waitFor(int wCnt,
                       int tmo)
                throws java.io.IOException,
                       java.lang.InterruptedException
    Wait for specified number of bytes to arrive on the stream. While snooping for pattern received data is passed to the SnoopLoopListener.

    Parameters:
    wCnt - The number of bytes to wait for.
    tmo - The timeout to wait for wCnt bytes. Notes: - If other snoops exist for the given SnoopInputStream they may be called before this method completes. - If the data received is larger than the size of the save buffer the data at the start of the buffer will be overwritten. - For performance reasons the save buffer is not cleared between calls if you wish to clear the save buffer between calls use setReadBuffer.
    Throws:
    java.io.IOException
    java.lang.InterruptedException

    snoopEvent

    public void snoopEvent(byte[] data)
    This method is called by the SnoopInputStream when the data pattern is sighted.

    Specified by:
    snoopEvent in interface SnoopListener

    setDataDiscard

    public void setDataDiscard(boolean onOff)
    Set the 'data discard' mode. When discard is enabled, no callbacks are done to the SnoopLoopListener when data is received.

    Parameters:
    onOff - Mode state

    getDataDiscard

    public boolean getDataDiscard(boolean onOff)
    Get the 'data discard' mode.

    Returns:
    onOff data discard mode state.

    setReadBuffer

    public void setReadBuffer(byte[] buf)
    Set the read buffer used when snooping for data

    Parameters:
    buf - The byte[] buffer

    getReadBuffer

    public byte[] getReadBuffer()
    Get the current read buffer.

    Returns:
    buf The byte[] buffer.

    setNapTime

    public void setNapTime(int time)
    Set the nap time used when the method sleeps. Port buffers should be large enough to handle the data rate when using long sleep values.

    Parameters:
    time - The time the thread sleeps between data checks.

    getNapTime

    public int getNapTime()
    Get the nap time used when the method sleeps.

    Returns:
    time The time the thread sleeps between data checks.

    abort

    public void abort()
    Abort this task