org.onsignal.rfid
Class RFIDReader

java.lang.Object
  extended by java.lang.Thread
      extended by org.onsignal.rfid.RFIDReader
All Implemented Interfaces:
java.lang.Runnable

public class RFIDReader
extends java.lang.Thread


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
RFIDReader()
          The basic constructor.
RFIDReader(RFIDListener listener)
          COnstructor without port name, no serial port will be opened, you'lll have it to do yourself using setPort() and open().
RFIDReader(java.lang.String portName)
          Constructor; pass in the name of the port the reader is connected to.
RFIDReader(java.lang.String portName, RFIDListener listener)
          Constructor using a port name and an instance of a listener object which will be notified on tag events.
 
Method Summary
 void addListener(RFIDListener l)
          Adds a listener for this reader
 void close()
          Shuts down the reader thread and closes the serial port.
 RFIDTag getCurrentTag()
          Returns the current tag, or null if there is no tag at the reader right now.
 boolean open()
          Opens the prot and starts the reader thread.
 void removeListener(RFIDListener l)
          Removes a listener
 void run()
          Do not call run() directly!
 void setPort(java.lang.String portName)
          Set or change the name of the port.
 void setTagRemoveTimeout(int timeout)
          Set the timeout for the removal of a tag, in milliseconds.
 void setVerbose(boolean verbose)
          Set the verbosity of this reader.
 java.lang.String toString()
          Represent this reader as a string for easy printing
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RFIDReader

public RFIDReader(java.lang.String portName)
           throws gnu.io.NoSuchPortException,
                  gnu.io.PortInUseException
Constructor; pass in the name of the port the reader is connected to. The port will be opened and the reader will be started.

Throws:
gnu.io.NoSuchPortException
gnu.io.PortInUseException

RFIDReader

public RFIDReader(java.lang.String portName,
                  RFIDListener listener)
           throws gnu.io.NoSuchPortException,
                  gnu.io.PortInUseException
Constructor using a port name and an instance of a listener object which will be notified on tag events.

Throws:
gnu.io.NoSuchPortException
gnu.io.PortInUseException

RFIDReader

public RFIDReader(RFIDListener listener)
COnstructor without port name, no serial port will be opened, you'lll have it to do yourself using setPort() and open(). You can pass in a listener object, though.


RFIDReader

public RFIDReader()
The basic constructor. Use RFIDReader(String portName) for more convenience.

Method Detail

setPort

public void setPort(java.lang.String portName)
             throws gnu.io.NoSuchPortException
Set or change the name of the port. If the reader is running, it will be shut down first. You'll have to call open() again to restart the reader on the new port.

Throws:
gnu.io.NoSuchPortException

getCurrentTag

public RFIDTag getCurrentTag()
Returns the current tag, or null if there is no tag at the reader right now.


open

public boolean open()
             throws gnu.io.PortInUseException
Opens the prot and starts the reader thread. If the reader was already running this function returns false, otherwise true.

Throws:
gnu.io.PortInUseException

close

public void close()
Shuts down the reader thread and closes the serial port.


setVerbose

public void setVerbose(boolean verbose)
Set the verbosity of this reader. By default, the reader is verbose, e.g., messages will be printed when a tag is read and removed. To mute the reader, call setVerbose(false).


addListener

public void addListener(RFIDListener l)
Adds a listener for this reader


removeListener

public void removeListener(RFIDListener l)
Removes a listener


setTagRemoveTimeout

public void setTagRemoveTimeout(int timeout)
Set the timeout for the removal of a tag, in milliseconds. Defaults to 500 ms. When -1 is passed, tags will never be marked as 'removed', e.g., getCurrentTag() will always return a value once a tag has been read.


toString

public java.lang.String toString()
Represent this reader as a string for easy printing

Overrides:
toString in class java.lang.Thread

run

public void run()
Do not call run() directly! It is called for you when open() was succesful.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread