mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-12 14:51:44 +01:00
53 lines
1.3 KiB
C#
53 lines
1.3 KiB
C#
using PCSC;
|
|
using PCSC.Iso7816;
|
|
|
|
namespace NFC.Readers.PCSC
|
|
{
|
|
public class Card : ICard
|
|
{
|
|
private IsoReader _ISOReader;
|
|
private string _ReaderID;
|
|
|
|
public Card(IsoReader isoreader, string readerID)
|
|
{
|
|
_ISOReader = isoreader;
|
|
_ReaderID = readerID;
|
|
}
|
|
public void Connect()
|
|
{
|
|
_ISOReader.Connect(_ReaderID, SCardShareMode.Shared, SCardProtocol.Any);
|
|
}
|
|
|
|
public void Disconnect()
|
|
{
|
|
_ISOReader.Disconnect(SCardReaderDisposition.Eject);
|
|
}
|
|
|
|
public APDUResponse Transmit(APDUCommand apdu_cmd)
|
|
{
|
|
Response response = _ISOReader.Transmit(Convert(apdu_cmd));
|
|
return Convert(response);
|
|
}
|
|
|
|
public CommandApdu Convert(APDUCommand apdu_cmd)
|
|
{
|
|
CommandApdu apdu = (CommandApdu)apdu_cmd;
|
|
return apdu;
|
|
}
|
|
|
|
public APDUResponse Convert(Response response)
|
|
{
|
|
ResponseApdu responseApdu = response.Get(0);
|
|
|
|
APDUResponse apduResponse = new APDUResponse()
|
|
{
|
|
SW1 = responseApdu.SW1,
|
|
SW2 = responseApdu.SW2,
|
|
Body = responseApdu.GetData()
|
|
};
|
|
|
|
return apduResponse;
|
|
}
|
|
}
|
|
}
|