lejos.nxt.addon
Class RFIDSensor

java.lang.Object
  extended by lejos.nxt.I2CSensor
      extended by lejos.nxt.addon.RFIDSensor
All Implemented Interfaces:
SensorConstants

public class RFIDSensor
extends I2CSensor

Support for the Codatex RFID Sensor. See www.codatex,com for details. Notes this device requires delays between various commands for them to function correctly, it also enters a sleep mode and requires to be woken up. The methods in this class fall into two categories. Basic commands These pretty much match one to one with the device command set. They do not incorporate any delays, or wake up code. They can be used by user programs but if they are then appropriate delays etc. must be used. They are provided to allow more sophisticated user programs access to the low level device. High level commands These provide higher level access to the device and are often implemented via several i2c commands. They do include delays and wake up logic.

Author:
andy

Field Summary
 
Fields inherited from interface lejos.nxt.SensorConstants
MODE_ANGLESTEP, MODE_BOOLEAN, MODE_CELSIUS, MODE_FARENHEIT, MODE_PCTFULLSCALE, MODE_PERIODCOUNTER, MODE_RAW, MODE_TRANSITIONCNT, TYPE_ANGLE, TYPE_CUSTOM, TYPE_LIGHT_ACTIVE, TYPE_LIGHT_INACTIVE, TYPE_LOWSPEED, TYPE_LOWSPEED_9V, TYPE_NO_SENSOR, TYPE_REFLECTION, TYPE_SOUND_DB, TYPE_SOUND_DBA, TYPE_SWITCH, TYPE_TEMPERATURE
 
Constructor Summary
RFIDSensor(I2CPort port)
          Create a class to provide access to the device.
 
Method Summary
protected  String fetchString(int register)
          We over-ride the default implementation to ensure that the device is awake before we talk to it.
 byte[] getSerialNo()
          Obtain the serial number of the RFID Sensor NOTES: To obtain the serial number the device must be in boot loader mode.
 int getStatus()
          Read the status from the device.
 byte[] readTransponder(boolean continuous)
          Read a transponder id.
 long readTransponderAsLong(boolean continuous)
           
 void startBootLoader()
          Enter boot loader mode.
 int startContinuousRead()
          Start a single read from the device.
 void startFirmware()
          Start the firmware on the RFID device.
 int startSingleRead()
          Start a single read from the device.
 int stop()
          Send a stop command to the device.
 void wakeUp()
          The sensor will go into a power save mode after a short time.
 
Methods inherited from class lejos.nxt.I2CSensor
getData, getPort, getProductID, getSensorType, getVersion, sendData, sendData, setAddress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RFIDSensor

public RFIDSensor(I2CPort port)
Create a class to provide access to the device. Perform device initialization.

Parameters:
port - The sensor port to use for this device.
Method Detail

wakeUp

public void wakeUp()
The sensor will go into a power save mode after a short time. This means that we will need to wake it up before issuing commands. Includes the required delay.


fetchString

protected String fetchString(int register)
We over-ride the default implementation to ensure that the device is awake before we talk to it.

Overrides:
fetchString in class I2CSensor
Parameters:
register - The register to read the string from.
Returns:
The requested string.

startFirmware

public void startFirmware()
Start the firmware on the RFID device. NOTES: It seems that you need to issue this command (or some other firmware command), prior to attempting to read the version number etc. Does not wake up the device or contain any delays.


startBootLoader

public void startBootLoader()
Enter boot loader mode. Does not wake up the device or include any delays.


getSerialNo

public byte[] getSerialNo()
Obtain the serial number of the RFID Sensor NOTES: To obtain the serial number the device must be in boot loader mode. This function will switch into this mode and then return to normal mode on completion.

Returns:
the 12 byte serial number if ok or null if there is an error

getStatus

public int getStatus()
Read the status from the device. Does not wake up the device or include any delays.

Returns:
1 data available 0 no data < 0 error

startSingleRead

public int startSingleRead()
Start a single read from the device. Does not wake up the device or include any delays.

Returns:
< 0 i2c error code >= 0 no error

startContinuousRead

public int startContinuousRead()
Start a single read from the device. Does not wake up the device or include any delays.

Returns:
< 0 i2c error code >= 0 no error

stop

public int stop()
Send a stop command to the device. Places the device into sleep mode.

Returns:
< 0 i2c error code >= 0 no error

readTransponder

public byte[] readTransponder(boolean continuous)
Read a transponder id. Reads the transponder using either continuous or single shot mode. If using single shot mode the tag must me available now. If using continuous mode then after the first call, the tag can be presented at any time and a subsequent read will return the results.

Parameters:
continuous - Should we use continuous mode
Returns:
null if error or no data available, otherwise an array of id bytes

readTransponderAsLong

public long readTransponderAsLong(boolean continuous)