Problem whit Write Method in 1024_0 RFID

Supporting Visual Studio on Windows
Post Reply
Danelly
Phidgetsian
Posts: 6
Joined: Wed Dec 20, 2017 3:45 pm
Contact:

Problem whit Write Method in 1024_0 RFID

Post by Danelly »

Hi
This is my problem
I can't make the write method works and this is my code

Code: Select all

namespace Prueba
{
	class Program 
	{
		static void printError(ErrorCode number, String description)
		{
			Console.WriteLine("Error en llamar a la funcion "+number+" - "+description+"!");
		}
		// Aparte
		static void manager_Attach(object sender, ManagerAttachEventArgs e) {
			int serialNumber;
			String name;
		
			try
			{
				
				serialNumber = e.Channel.DeviceSerialNumber;
				name = e.Channel.DeviceName;
				Console.WriteLine("Hola dispositivo "+name+"' Con numero Serial: "+serialNumber );
			}
			catch (PhidgetException ex)
			{
				printError(ex.ErrorCode, ex.Description);
			}
		}
		

		static void manager_Detach(object sender, ManagerDetachEventArgs e) {
			int serialNumber;
			String name;
			try
			{
				name = e.Channel.DeviceName;
				serialNumber = e.Channel.DeviceSerialNumber;
				
				Console.WriteLine("Adios dispositivo " + name + ", con numero serial: "+serialNumber);
			}
			catch(PhidgetException ex) {
				printError(ex.ErrorCode, ex.Description);
			}
			

		}
	



		static void RfidTag(object sender, RFIDTagEventArgs e)
		{
			try
			{
				Console.WriteLine("Tag: " + e.Tag+ " "+e.Protocol);
				
			}
			catch (PhidgetException ex)
			{
				printError(ex.ErrorCode, ex.Description);
			}
		}

		static void TagLost(object sender, RFIDTagLostEventArgs e) {

			try
			{
				Console.WriteLine("Se ingreso Tag: " + e.Tag + " con protocolo " + e.Protocol);
			}
			catch (PhidgetException ex)
			{
				printError(ex.ErrorCode, ex.Description);
			}
		}



		static void RfidWrite(object sender, EventArgs re) {
			RFID holas = new RFID();
			try
			{
				holas.Write("Cheves y desmadre", RFIDProtocol.PhidgetTAG, false);	
				
			}
			catch (PhidgetException ex)
			{
				printError(ex.ErrorCode, ex.Description);
			}
		}




		static void Main(string[] args)
		{
			
			Manager manager = new Manager();
			RFID holas = new RFID();
			RFID Guardar = new RFID();
			RFID demiLobato = new RFID();
			int var;
			String tagText = "I CAN FLAY";
			RFIDProtocol protocol = RFIDProtocol.PhidgetTAG;
			bool f = false;
			try
			{
				
				
				holas.Tag += new RFIDTagEventHandler(RfidTag);
				holas.Write(tagText,protocol,f); // <--- this 
				
			}

			catch(PhidgetException ex)
			{
				printError(ex.ErrorCode, ex.Description);
			}
			try
			{
				holas.AntennaEnabled = false; //it doesn't work
			}
			catch (PhidgetException ex) { Console.WriteLine("Error enabling antenna: " + ex.Message); }
		
		holas.Open();

			

			try
			{
				holas.TagLost += new RFIDTagLostEventHandler(TagLost);
			}

			catch (PhidgetException ex)
			{
				printError(ex.ErrorCode, ex.Description);
			}
			
			


			
			try {
				manager.Attach += new ManagerAttachEventHandler(manager_Attach);
				manager.Detach += new ManagerDetachEventHandler(manager_Detach);
			}
			catch (PhidgetException ex)
			{
				printError(ex.ErrorCode,ex.Description);
			}
			try
			{
										
			}

			catch (PhidgetException ex)
			{
				printError(ex.ErrorCode, ex.Description);
			}
			manager.Open();

			Console.WriteLine("Phidget Simple Playground (plug and unplug devices)");
			Console.WriteLine("Press Enter to end anytime");


			Console.ReadLine();
	

			Console.WriteLine("Closing....");

			try
			{
				manager.Attach -= new ManagerAttachEventHandler(manager_Attach);
				manager.Detach -= new ManagerDetachEventHandler(manager_Detach);
				manager.Close();
			}
			catch (PhidgetException ex)
			{
				printError(ex.ErrorCode, ex.Description);
			}
			
			
			manager = null;

		}

		
	}
}
Thanks for advise...
User avatar
mparadis
Site Admin
Posts: 660
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Problem whit Write Method in 1024_0 RFID

Post by mparadis »

You have to do holas.Open() before attempting to write to a tag or set the antenna. I recommend doing holas.Open(1000) so that it waits for a second for the device to attach.

Also, make sure the tag you're writing to is a writable tag. You'll get a timeout error if the tag is out of range or is not writable (or used to be writable but was locked). I recommend using the Phidget Control Panel to test your tags in this case to make sure they are writable.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 0 guests