//This simple file will suffice for our Java documentation for now.
//We will write full tutorials later.  In this file, I explain the rfidex1.java example.

// This brings in the Phidgets java package.  I distribute this with the examples, it's in the 
// Phidgets subdirectory.  It's important that the Phidgets java package is kept up to date 
// with the phidget20 dll, which it interfaces to.  You need both to use Phidgets with Java.
// The Phidget20 dll is installed by the PHIDGET.msi installation script.
import Phidgets.*;

public class rfidex1 extends _IPhidgetRFIDEventsAdapter
{
	// extending _IPhidgetRFIDEventsAdapter allows your class to pick and choose which Phidget
	// events you want to implement.  
        public void OnTag(_IPhidgetRFIDEvents_OnTagEvent ke) {
		System.out.println("Tag Found: " + ke.get_TagNumber());
        }

	// Unfortunately, due to a serious incompatibility between JNI and the Phidget20 library,
	// we will not be using the OnDetach event.

	public static void main(String[] args) {
		new rfidex1();
	}
	public rfidex1()
	{
            

		PhidgetRFID phid = new PhidgetRFID();
		phid.add_IPhidgetRFIDEventsListener(this);
		// By adding the EventListener, we tell the PhidgetRFID where it can throw the events
		// to.

		// We need to open the device.  
		if (phid.Open(false) == false) 
		{
			System.out.println("Could not find a PhidgetRFID");
			return;
		}
		System.out.println(phid.GetDeviceType());
		System.out.println("Serial Number " + phid.GetSerialNumber());
		System.out.println("Device Version " + phid.GetDeviceVersion());
		System.out.println("Attached " + phid.GetIsAttached());

		// the .run method starts an infinite loop, polling the device for data.
		// If you call .start instead - phid.start() - the infinite loop will
		// run in a separate thread, allowing your program to proceed.
		// In this example, if we called .start, the program immediately finishes.
		phid.run();
	}
}
