-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFreeFareDevice.cs
More file actions
51 lines (44 loc) · 1.49 KB
/
FreeFareDevice.cs
File metadata and controls
51 lines (44 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using SharpNFC;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace SharpFreeFare
{
public class FreeFareDevice : NFCDevice //musi dziedziczyc po nfcDevice bo to jest nfcDevice tylko ze rozszezone
{
protected internal FreeFareDevice(IntPtr devicePointer)
: base(devicePointer)
{
}
public List<MifareTag> GetTags()
{
IntPtr unmanaged_mifare_tag_array_pointer;
try
{
unmanaged_mifare_tag_array_pointer = Functions.freefare_get_tags(base.DevicePointer);
if (unmanaged_mifare_tag_array_pointer == IntPtr.Zero)
{
throw new Exception();
}
}
catch (Exception)
{
throw new Exception("freefare_get_tags failed.");
}
var mifareTags = new List<MifareTag>();
for (int i = 0; ; i++)
{
IntPtr tagPtr = (IntPtr)Marshal.PtrToStructure(unmanaged_mifare_tag_array_pointer + i * Marshal.SizeOf(unmanaged_mifare_tag_array_pointer), typeof(IntPtr));
if (tagPtr == IntPtr.Zero)
{
break;
}
mifareTags.Add(new MifareTag(tagPtr));
}
return mifareTags;
}
}
}