Serialio
Class SerLooker

java.lang.Object
  extended by Serialio.SerLooker

public class SerLooker
extends java.lang.Object

Looks for things to happen on the serial port object.

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


    Field Summary
    protected  SerialPort sp
               
     
    Constructor Summary
    SerLooker()
              Create a serial port 'looker'.
    SerLooker(SerialPort sp)
              Create a serial port 'looker'.
    SerLooker(SerialPort sp, int bufSize)
              Create a serial port 'looker' with a specific save data buffer.
     
    Method Summary
     void abort()
              Aborts a waitFor operation in progress.
     int getAbortCheck()
              Deprecated. The method is no longer required
     byte[] getData()
              Returns the data received while the port was waiting for specific data.
     byte[] getDataItemSighted()
              Returns the data item that was sighted.
     int getNapTime()
              Get the sleep interval used when waiting for data
     int getRcvCount()
              Returns the number of bytes received while the port was waiting for specific data.
     boolean getSaveReset()
              Get the saveReset flag.
     SerialPort getSerialPort(SerialPort sp)
              Gets the serial port object
     void setAbortCheck(int per)
              Deprecated. The method is no longer required since the port timout (setTimeoutRx) value is always 0.
     void setNapTime(int napTime)
              Set the sleep interval used when waiting for data Note: SerialPort.setTimeoutRx is not used to allow quick aborts on some platforms (esp WinNT) where some threading behaviour is not well behaved.
     void setSaveData(int bufSize)
              Controls if the object saves data when waiting for a specific response.
     void setSaveDataBeforeMatch(boolean onOff)
              Sets the object to save data before the match.
     void setSaveReset(boolean onOff)
              Set the saveReset flag.
     void setSerialPort(SerialPort sp)
              Sets the serial port object
     void setShowBytesAsReceived(boolean onOff)
              Sets the object to show each byte to the console as received Setting this true can be handy for debugging & sanity checks.
     boolean waitFor(byte[] snd, byte[] rcv, int tmo)
              Send data (optional) and wait for a specific response.
     boolean waitFor(byte[] snd, int waitForCount, int tmo)
              Send data (optional) and wait for count bytes in the input queue.
     boolean waitFor(byte[] snd, java.util.Vector lookForList, int tmo)
              Send data (optional) and wait for any of a list of responses.
     boolean waitFor(java.lang.String Ssnd, java.lang.String Srcv, int tmo)
              Send data (optional) and wait for a specific response.
     boolean waitFor(java.lang.String Ssnd, java.util.Vector lookForList, int tmo)
              Send data (optional) and wait for any of a list of responses.
     
    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

    SerLooker

    public SerLooker()
    Create a serial port 'looker'. This empty constructor is for Bean friendlyness


    SerLooker

    public SerLooker(SerialPort sp)
    Create a serial port 'looker'. Data received when looking for a response is discarded by default.

    Parameters:
    sp - a valid SerialPort object

    SerLooker

    public SerLooker(SerialPort sp,
                     int bufSize)
    Create a serial port 'looker' with a specific save data buffer. If bufSize is greater than 0 then data received when looking for a response will be saved to the buffer.

    Parameters:
    sp - a valid SerialPort object
    bufSize - size of buffer used when looking for desired data
    Method Detail

    waitFor

    public boolean waitFor(byte[] snd,
                           int waitForCount,
                           int tmo)
                    throws java.io.IOException
    Send data (optional) and wait for count bytes in the input queue. Be sure no other threads access the port while this method runs.

    Parameters:
    snd - data to send (currently only UTF8 data is sent)
    wCnt - number of bytes to wait for
    tmo - timeout in milliseconds if cnt bytes not available within tmo
    Throws:
    java.io.IOException - if error

    waitFor

    public boolean waitFor(java.lang.String Ssnd,
                           java.lang.String Srcv,
                           int tmo)
                    throws java.io.IOException
    Send data (optional) and wait for a specific response. Be sure no other threads access the port while this method runs. Transmit functions return after this amount of time if all data has not been sent.

    Parameters:
    snd - data to send (currently only UTF8 data is sent)
    rcv - data to wait for send (currently UTF8 data is significant)
    tmo - timeout in milliseconds if Srcv string not found
    Throws:
    java.io.IOException - if error

    waitFor

    public boolean waitFor(byte[] snd,
                           byte[] rcv,
                           int tmo)
                    throws java.io.IOException
    Send data (optional) and wait for a specific response. Be sure no other threads access the port while this method runs. Transmit functions return after this amount of time if all data has not been sent.

    Parameters:
    Ssnd - string to send (currently only UTF8 data is sent)
    Srcv - string to wait for send (currently UTF8 data is significant)
    tmo - timeout in milliseconds if Srcv string not found
    Throws:
    java.io.IOException - if error

    waitFor

    public boolean waitFor(java.lang.String Ssnd,
                           java.util.Vector lookForList,
                           int tmo)
                    throws java.io.IOException
    Send data (optional) and wait for any of a list of responses. Be sure no other threads access the port while this method runs.

    Parameters:
    Ssnd - string to send (currently only UTF8 data is sent)
    Vector - vector of String and/or byte[] data patterns to search for
    tmo - timeout in milliseconds if none of the data patterns sighted
    Throws:
    java.io.IOException - if error

    waitFor

    public boolean waitFor(byte[] snd,
                           java.util.Vector lookForList,
                           int tmo)
                    throws java.io.IOException
    Send data (optional) and wait for any of a list of responses. Be sure no other threads access the port while this method runs.

    Parameters:
    snd - data to send (currently only UTF8 data is sent)
    Vector - vector of String and/or byte[] data patterns to search for
    tmo - timeout in milliseconds if none of the data patterns sighted
    Throws:
    java.io.IOException - if error Note: on some platforms (e.g. WinNT 4) using waitFor when setTimeoutRx(n) where n is greater than 0, AND there is data in the input queue, can cause data in the queue to be lost due to OS driver issues.

    setSaveData

    public void setSaveData(int bufSize)
    Controls if the object saves data when waiting for a specific response.

    Parameters:
    bufSize - Sets the size of the save buffer (0 turns saving off)

    setNapTime

    public void setNapTime(int napTime)
    Set the sleep interval used when waiting for data Note: SerialPort.setTimeoutRx is not used to allow quick aborts on some platforms (esp WinNT) where some threading behaviour is not well behaved.

    Parameters:
    napTime - The time to sleep between checks for data

    getNapTime

    public int getNapTime()
    Get the sleep interval used when waiting for data


    getRcvCount

    public int getRcvCount()
    Returns the number of bytes received while the port was waiting for specific data. Note: this count is affected by setSaveReset()


    abort

    public void abort()
    Aborts a waitFor operation in progress.


    setSerialPort

    public void setSerialPort(SerialPort sp)
    Sets the serial port object

    Parameters:
    sp - a valid SerialPort object

    getSerialPort

    public SerialPort getSerialPort(SerialPort sp)
    Gets the serial port object


    setAbortCheck

    public void setAbortCheck(int per)
    Deprecated. The method is no longer required since the port timout (setTimeoutRx) value is always 0.


    getAbortCheck

    public int getAbortCheck()
    Deprecated. The method is no longer required


    setSaveReset

    public void setSaveReset(boolean onOff)
    Set the saveReset flag. When true(default) save buffer is reset on each call to waitFor. When false, save buffer continues from previous waitFor state, allowing history to be saved between waitFor calls.

    Parameters:
    onOff - State for save buffer reset

    getSaveReset

    public boolean getSaveReset()
    Get the saveReset flag.


    getDataItemSighted

    public byte[] getDataItemSighted()
    Returns the data item that was sighted. Used when searching for multiple data items.


    setShowBytesAsReceived

    public void setShowBytesAsReceived(boolean onOff)
    Sets the object to show each byte to the console as received Setting this true can be handy for debugging & sanity checks.


    setSaveDataBeforeMatch

    public void setSaveDataBeforeMatch(boolean onOff)
    Sets the object to save data before the match. Depending on speed of the data stream, data following the match may be discarded. i.e. since the read from the port is block-based, the match may come mid-block, and data in the same read block following the match would be discarded. In this mode data up to and including the match will be returned by getData. Normal operation for this object is to discard data up to the match (when there is a match) and data following the match will then be intact, and can be fetched with getData.


    getData

    public byte[] getData()
    Returns the data received while the port was waiting for specific data. Note the ringBuf index is left pointing to the proper location to return the 'previous buffer full' of received data.