Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
MifareUltralightInterface.cs
1using Android.Nfc;
2using Android.Nfc.Tech;
4
6{
12 public class MifareUltralightInterface(Tag Tag, MifareUltralight Technology)
13 : NfcInterface(Tag, Technology), IMifareUltralightInterface
14 {
15 private readonly MifareUltralight mifareUltralight = Technology;
16
20 public async Task<byte[]> ReadAllData()
21 {
22 MifareUltralightType Type = this.mifareUltralight.Type;
23 int TotalBytes = Type switch
24 {
25 MifareUltralightType.UltralightC => 192,
26 _ => 64,
27 };
28 int PageSize = MifareUltralight.PageSize;
29 byte[] Data = new byte[TotalBytes];
30 int Offset = 0;
31
32 while (Offset < TotalBytes)
33 {
34 byte[]? Pages = await this.mifareUltralight.ReadPagesAsync(Offset / PageSize) ?? throw UnableToReadDataFromDevice();
35 int i = Math.Min(Pages.Length, TotalBytes - Offset);
36 if (i <= 0)
37 throw UnableToReadDataFromDevice();
38
39 Array.Copy(Pages, 0, Data, Offset, i);
40 Offset += i;
41 }
42
43 return Data;
44 }
45 }
46}
Mifare Ultralight interface, for communication with an NFC Tag.