00001 00002 /* 00003 * Copyright 2006 Phidgets Inc. All rights reserved. 00004 */ 00005 00006 package com.phidgets; 00007 import java.util.Iterator; 00008 import java.util.LinkedList; 00009 import com.phidgets.event.*; 00019 public final class RFIDPhidget extends Phidget 00020 { 00021 public RFIDPhidget () throws PhidgetException 00022 { 00023 super (create ()); 00024 } 00025 private static native long create () throws PhidgetException; 00026 00030 public static final int PHIDGET_RFID_PROTOCOL_EM4100 = 1; 00034 public static final int PHIDGET_RFID_PROTOCOL_ISO11785_FDX_B = 2; 00038 public static final int PHIDGET_RFID_PROTOCOL_PHIDGETS = 3; 00039 00047 public native int getOutputCount () throws PhidgetException; 00055 public native boolean getOutputState (int index) throws PhidgetException; 00063 public native void setOutputState (int index, boolean state) throws PhidgetException; 00070 public native boolean getAntennaOn () throws PhidgetException; 00080 public native void setAntennaOn (boolean state) throws PhidgetException; 00087 public native boolean getLEDOn () throws PhidgetException; 00094 public native void setLEDOn (boolean state) throws PhidgetException; 00102 public native String getLastTag () throws PhidgetException; 00110 public native int getLastTagProtocol () throws PhidgetException; 00118 public native boolean getTagStatus () throws PhidgetException; 00127 public native void write (String tag, int protocol, boolean lock) throws PhidgetException; 00128 00129 private final void enableDeviceSpecificEvents (boolean b) 00130 { 00131 enableTagGainEvents (b && tagGainListeners.size () > 0); 00132 enableTagLossEvents (b && tagLossListeners.size () > 0); 00133 enableOutputChangeEvents (b && outputChangeListeners.size () > 0); 00134 } 00144 public final void addTagGainListener (TagGainListener l) 00145 { 00146 synchronized (tagGainListeners) 00147 { 00148 tagGainListeners.add (l); 00149 enableTagGainEvents (true); 00150 }} private LinkedList tagGainListeners = new LinkedList (); 00151 private long nativeTagGainHandler = 0; 00152 public final void removeTagGainListener (TagGainListener l) 00153 { 00154 synchronized (tagGainListeners) 00155 { 00156 tagGainListeners.remove (l); 00157 enableTagGainEvents (tagGainListeners.size () > 0); 00158 }} private void fireTagGain (TagGainEvent e) 00159 { 00160 synchronized (tagGainListeners) 00161 { 00162 for (Iterator it = tagGainListeners.iterator (); it.hasNext ();) 00163 ((TagGainListener) it.next ()).tagGained (e); 00164 } 00165 } 00166 private native void enableTagGainEvents (boolean b); 00175 public final void addTagLossListener (TagLossListener l) 00176 { 00177 synchronized (tagLossListeners) 00178 { 00179 tagLossListeners.add (l); 00180 enableTagLossEvents (true); 00181 }} private LinkedList tagLossListeners = new LinkedList (); 00182 private long nativeTagLossHandler = 0; 00183 public final void removeTagLossListener (TagLossListener l) 00184 { 00185 synchronized (tagLossListeners) 00186 { 00187 tagLossListeners.remove (l); 00188 enableTagLossEvents (tagLossListeners.size () > 0); 00189 }} private void fireTagLoss (TagLossEvent e) 00190 { 00191 synchronized (tagLossListeners) 00192 { 00193 for (Iterator it = tagLossListeners.iterator (); it.hasNext ();) 00194 ((TagLossListener) it.next ()).tagLost (e); 00195 } 00196 } 00197 private native void enableTagLossEvents (boolean b); 00205 public final void addOutputChangeListener (OutputChangeListener l) 00206 { 00207 synchronized (outputChangeListeners) 00208 { 00209 outputChangeListeners.add (l); 00210 enableOutputChangeEvents (true); 00211 }} private LinkedList outputChangeListeners = new LinkedList (); 00212 private long nativeOutputChangeHandler = 0; 00213 public final void removeOutputChangeListener (OutputChangeListener l) 00214 { 00215 synchronized (outputChangeListeners) 00216 { 00217 outputChangeListeners.remove (l); 00218 enableOutputChangeEvents (outputChangeListeners.size () > 0); 00219 }} private void fireOutputChange (OutputChangeEvent e) 00220 { 00221 synchronized (outputChangeListeners) 00222 { 00223 for (Iterator it = outputChangeListeners.iterator (); it.hasNext ();) 00224 ((OutputChangeListener) it.next ()).outputChanged (e); 00225 } 00226 } 00227 private native void enableOutputChangeEvents (boolean b); 00228 }