2020-09-15 15:27:01 +02:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using NFC;
|
|
|
|
|
using NFC.Readers.PCSC;
|
2020-09-17 16:07:58 +02:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using NFC.Mifare_DESFire;
|
2020-09-26 18:02:44 +02:00
|
|
|
|
using NFC.Mifare_DESFire.Enums;
|
2020-10-06 15:59:53 +02:00
|
|
|
|
using NFC.ISO7816_4;
|
2020-10-07 19:25:51 +02:00
|
|
|
|
using PCSC.Iso7816;
|
2020-09-15 15:27:01 +02:00
|
|
|
|
|
|
|
|
|
namespace NFC_Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture, Explicit]
|
|
|
|
|
public class REAL_Windows
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetReaders()
|
|
|
|
|
{
|
2020-09-17 16:07:58 +02:00
|
|
|
|
IHardware hardware = new Hardware();
|
2020-09-15 15:27:01 +02:00
|
|
|
|
string[] readers = hardware.GetReaders();
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Readers detected: {0}", readers.Length);
|
|
|
|
|
|
|
|
|
|
if(readers.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("List of ReaderIDs:");
|
|
|
|
|
foreach (string readerID in readers)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("{0}", readerID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 16:07:58 +02:00
|
|
|
|
[TestCase("ACS ACR122U PICC Interface 0")]
|
2020-09-15 15:27:01 +02:00
|
|
|
|
public void Connect(string readerID)
|
|
|
|
|
{
|
2020-09-17 16:07:58 +02:00
|
|
|
|
IHardware hardware = new Hardware();
|
|
|
|
|
IReader reader = hardware.OpenReader(readerID);
|
2020-09-15 15:27:01 +02:00
|
|
|
|
|
2020-09-17 16:07:58 +02:00
|
|
|
|
bool connected_successfully = false;
|
|
|
|
|
|
|
|
|
|
ReaderEventHandler handler = (sender, card) =>
|
|
|
|
|
{
|
|
|
|
|
card.Connect();
|
|
|
|
|
|
|
|
|
|
connected_successfully = true;
|
|
|
|
|
|
|
|
|
|
card.Disconnect();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
reader.CardDiscovered += handler;
|
|
|
|
|
reader.Start();
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(true, connected_successfully);
|
|
|
|
|
|
|
|
|
|
reader.Stop();
|
|
|
|
|
reader.CardDiscovered -= handler;
|
|
|
|
|
}
|
2020-09-15 15:27:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|