-
Notifications
You must be signed in to change notification settings - Fork 13
/
NFCDevice.cs
47 lines (40 loc) · 1.51 KB
/
NFCDevice.cs
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
using SharpNFC.PInvoke;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace SharpNFC
{
public class NFCDevice : IDisposable
{
//protected nfc_device device;
public readonly IntPtr DevicePointer;
protected internal NFCDevice(IntPtr devicePointer)
{
//var device = (nfc_device)Marshal.PtrToStructure(devicePointer, typeof(nfc_device));
this.DevicePointer = devicePointer;
}
public int Pool(List<nfc_modulation> modulation, byte poolCount, byte poolingInterval, out nfc_target nfc_target)
{
//var ptrArray = new IntPtr[modulation.Count];
//for (int i = 0; i < modulation.Count; i++)
//{
// IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(modulation[i]));
// Marshal.StructureToPtr(modulation[i], ptr, false);
// ptrArray[i] = ptr;
//}
var target = new nfc_target();
//var targetPtr = Marshal.AllocHGlobal(Marshal.SizeOf(target));
var modArr = modulation.ToArray();
var intResult = Functions.nfc_initiator_poll_target(DevicePointer, modArr, (uint)modArr.Length, poolCount, poolingInterval, out target);
nfc_target = target;
return intResult;
}
public void Dispose()
{
SharpNFC.PInvoke.Functions.nfc_close(DevicePointer);
}
}
}