mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-12 14:51:44 +01:00
52 lines
1.1 KiB
C#
52 lines
1.1 KiB
C#
using PCSC;
|
|
using PCSC.Iso7816;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace NFC.Readers.PCSC
|
|
{
|
|
|
|
public class Reader : IReader, IDisposable
|
|
{
|
|
private string _ReaderID;
|
|
private IContextFactory _ContextFactory;
|
|
private ISCardContext _SCardContext;
|
|
private IsoReader _ISOReader;
|
|
private ICard _Card;
|
|
|
|
public Reader(string readerID)
|
|
{
|
|
_ReaderID = readerID;
|
|
}
|
|
|
|
public event ReaderEventHandler CardDiscovered;
|
|
public event ReaderEventHandler CardLost;
|
|
|
|
public void Dispose()
|
|
{
|
|
Stop();
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
_ContextFactory = ContextFactory.Instance;
|
|
_SCardContext = _ContextFactory.Establish(SCardScope.System);
|
|
|
|
_ISOReader = new IsoReader(_SCardContext);
|
|
|
|
_Card = new Card(_ISOReader, _ReaderID);
|
|
|
|
CardDiscovered?.Invoke(this, _Card);
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
CardLost?.Invoke(this, _Card);
|
|
|
|
_ISOReader.Dispose();
|
|
_SCardContext.Dispose();
|
|
}
|
|
}
|
|
}
|