Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read memory blocks from non-NDEF tags #32

Open
JochenAuinger opened this issue Nov 14, 2018 · 4 comments
Open

Read memory blocks from non-NDEF tags #32

JochenAuinger opened this issue Nov 14, 2018 · 4 comments

Comments

@JochenAuinger
Copy link

Hi,

is there a possibility to read the data of the memory of a non-NDEF tag?

Best regards
Jochen

@edwito86
Copy link

edwito86 commented Aug 7, 2019

tengo el mismo problema, encontraste alguna solución?

Gracias
Edwin Castañeda

@JochenAuinger
Copy link
Author

tengo el mismo problema, encontraste alguna solución?

I´ll be back in the office on 26.8. As far as I recall I have solved the problem.

Best regards
Jochen

@edwito86
Copy link

tengo el mismo problema, encontraste alguna solución?

I´ll be back in the office on 26.8. As far as I recall I have solved the problem.

Best regards
Jochen

Gracias @JochenAuinger , espero.

saludos.

@JochenAuinger
Copy link
Author

Hi,

I hope I have found everything you need ;-)
My code works with a Bluebird device with the RFR900 RFID slide.

Below you find the usage, but of course you need the device drivers from the producers (Bluebird in my case). Then you maybe find the attached RFIDManager useful: https://www.ngs.at/downloads/RFID.zip
FYI: I will remove the file from the server at the end of the week.

Best regards
Jochen

`private IRFIDManager rfidManager = null;
private bool rfidScanRunning = false;
private string _nfcTagID = null;
private ObservableCollection<KeyValuePair<string, string>> _nfcTagInfo = null;
private readonly INfcForms nfcDevice;
private bool _isNfcWriteable = false;
private bool _isNfcConnected = false;
private bool _isNfcNDEFSupported = false;
private Hashtable htNfcTagIDs = new Hashtable();

#region RFID events & functions
void Device_NfcTagDisconnected(object sender, NfcFormsTag e)
{
IsNfcConnected = false;
}
void Device_NfcTagConnected(object sender, NfcFormsTag e)
{
IsNfcConnected = true;
}
#pragma warning disable IDE0051 // Nicht verwendete private Member entfernen
private ObservableCollection ReadNfcNDEFMEssage(NdefMessage message)
#pragma warning restore IDE0051 // Nicht verwendete private Member entfernen
{
ObservableCollection collection = new ObservableCollection();

		if (message == null)
		{
			return collection;
		}

		foreach (NdefRecord record in message)
		{
			// Go through each record, check if it's a Smart Poster
			if (record.CheckSpecializedType(false) == typeof(NdefSpRecord))
			{
				// Convert and extract Smart Poster info
				var spRecord = new NdefSpRecord(record);
				collection.Add("URI: " + spRecord.Uri);
				collection.Add("Titles: " + spRecord.TitleCount());
				collection.Add("1. Title: " + spRecord.Titles[0].Text);
				collection.Add("Action set: " + spRecord.ActionInUse());
			}

			if (record.CheckSpecializedType(false) == typeof(NdefUriRecord))
			{
				// Convert and extract Smart Poster info
				var spRecord = new NdefUriRecord(record);
				collection.Add("Text: " + spRecord.Uri);
			}
		}
		return collection;
	}
	private string HexArrayToIdString(byte[] id)
	{
		if (id == null)
			return null;

		StringBuilder sb = new StringBuilder();

		for (int i = id.Length - 1; i >= 0; i--)
		{
			sb.Append(id[i].ToString("X2"));
		}

		return sb.ToString();
	}
	void HandleNewTag(object sender, NfcFormsTag e)
	{
		IsNfcWriteable = e.IsWriteable;
		IsNfcNDEFSupported = e.IsNdefSupported;

		//if (TechList != null)
		//	TechList.ItemsSource = e.TechList;

		//if (e.IsNdefSupported)
		//	NDEFMessage.ItemsSource = ReadNDEFMEssage(e.NdefMessage);

		// Sicherstellen, dass jeder Tag nur einmal gescannt wird
		this.NfcTagID = HexArrayToIdString(e.Id);
		if (htNfcTagIDs.Contains(this.NfcTagID))
			return;

		htNfcTagIDs.Add(this.NfcTagID, e.Payload);

		if (e.Payload != null)
		{
			string[] arr = e.Payload.Split(new string[] { ";" }, StringSplitOptions.None);
			List<KeyValuePair<string, string>> lst = new List<KeyValuePair<string, string>>();
			string key = string.Empty;
			for (int i = 0; i < arr.Length; i++)
			{
				if (i % 2 == 0)
				{
					key = arr[i];
				}
				else
				{
					lst.Add(new KeyValuePair<string, string>(key, arr[i]));
					key = null;
				}
			}
			if (!string.IsNullOrEmpty(key))
			{
				lst.Add(new KeyValuePair<string, string>(key, string.Empty));
			}
			if (lst != null)
			{
				this.NfcTagInfo = new ObservableCollection<KeyValuePair<string, string>>(lst);
			}
		}
		else
		{
			this.NfcTagInfo = null;
		}
		Console.WriteLine(string.Format("Payload: {0}", e.Payload ?? "<NULL>"));

		Entry ctrl = null;
		if (string.IsNullOrEmpty(this.Model.RFID1))
		{
			ctrl = this.Focus<EntryEx>("entryRFID1", 200) as Entry;
		}
		else
		{
			this.Focus<Button>("BackButton", 200);
		}

		if (ctrl != null)
		{
			ctrl.Text = this.NfcTagID;
			if (!string.IsNullOrEmpty(this.NfcTagID))
			{
				((Command)this.EntryReturnCommand)?.Execute(ctrl);
			}
		}
	}
	#endregion

	#region RFID Events
	private void RfidManager_TagFound(object sender, EventArgs e)
	{
		try
		{
			if (e is TagFoundEventArgs tfea)
			{
				ShowStatus(string.Format("Prüfe Tag {0}...", tfea.TagId));

				LoggingService.Debug(string.Format("RFIDOnlineCheckData({0})...", tfea.TagId));

				if (string.IsNullOrEmpty(this.Model.RFID1))
				{
					this.Model.RFID1 = tfea.TagId;
				}
			}
		}
		catch (System.Exception ex)
		{
			LoggingService.Error(ex.ToString());
		}
	}

	private void RfidManager_TriggerReleased(object sender, EventArgs e)
	{
		rfidScanRunning = false;
		this.IsStatusVisible = false;
	}

	private void RfidManager_TriggerPressed(object sender, EventArgs e)
	{
		ShowStatus(string.Empty);
		rfidScanRunning = true;
		this.Status = C_RFID_SEARCH;
		this.IsStatusVisible = true;
	}
	#endregion`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants