Table of Contents

Class Pn5180

Namespace
Iot.Device.Pn5180
Assembly
Iot.Device.Pn5180.dll

A PN5180 class offering RFID and NFC functionalities. Implement the CardTransceiver class to allow Mifare, Credit Card support

public class Pn5180 : CardTransceiver
Inheritance
Pn5180

Constructors

Pn5180(SpiDevice, int, int, GpioController?, bool)

Create a PN5180 RFID/NFC reader

public Pn5180(SpiDevice spiDevice, int pinBusy, int pinNss, GpioController? gpioController = null, bool shouldDispose = true)

Parameters

spiDevice SpiDevice

The SPI device

pinBusy int

The pin for the busy line

pinNss int

The pin for the SPI select line. This has to be handle differently than thru the normal process as PN5180 has a specific way of working

gpioController GpioController

A GPIO controller, null will use a default one

shouldDispose bool

Dispose the SPI and the GPIO controller at the end if true

Fields

DefaultSpiMode

Only SPI Mode supported is Mode0

public const SpiMode DefaultSpiMode = Mode0

Field Value

SpiMode

MaximumSpiClockFrequency

PN532 SPI Clock Frequency

public const int MaximumSpiClockFrequency = 7000000

Field Value

int

RadioFrequencyConfigurationSize

A radio Frequency configuration element size is 5 bytes Byte 1 = Register Address next 4 bytes = data of the register

public const int RadioFrequencyConfigurationSize = 5

Field Value

int

Properties

CrcReceptionTransfer

Set on of off the CRC calculation for the Transfer and Reception Switch off is needed for anticollision operation on type A cards. Otherwise normal state is on

public bool CrcReceptionTransfer { get; set; }

Property Value

bool

RadioFrequencyCollision

True to disable the Radio Frequency collision avoidance according to ISO/IEC 18092 False to use Active Communication mode according to ISO/IEC 18092

public RadioFrequencyCollision RadioFrequencyCollision { get; set; }

Property Value

RadioFrequencyCollision

RadioFrequencyField

Get or set the radio frequency field. True for on, false for off

public bool RadioFrequencyField { get; set; }

Property Value

bool

Methods

CalculateCrcA(SpanByte, SpanByte)

Provide a calculation of CRC for Type A cards

public void CalculateCrcA(SpanByte buffer, SpanByte crc)

Parameters

buffer SpanByte

The buffer to process

crc SpanByte

The CRC, Must be a 2 bytes buffer

CalculateCrcB(SpanByte, SpanByte)

Provide a calculation of CRC for Type B cards

public void CalculateCrcB(SpanByte buffer, SpanByte crc)

Parameters

buffer SpanByte

The buffer to process

crc SpanByte

The CRC, Must be a 2 bytes buffer

DeselectCardTypeB(Data106kbpsTypeB)

Deselect a 14443 Type B card

public bool DeselectCardTypeB(Data106kbpsTypeB card)

Parameters

card Data106kbpsTypeB

The card to deselect

Returns

bool

True if success

Dispose()

Dispose

public void Dispose()

GetIdentifier(SpanByte)

Get the PN5180 identifier, this is a 16 byte long

public bool GetIdentifier(SpanByte outputIdentifier)

Parameters

outputIdentifier SpanByte

A 16 byte buffer

Returns

bool

True if success

GetNumberOfBytesReceivedAndValidBits()

Get the number of bytes to read and the valid number of bits in the last byte If the full byte is valid then the value of the valid bit is 0

public Doublet GetNumberOfBytesReceivedAndValidBits()

Returns

Doublet

A tuple whit the number of bytes to read and the number of valid bits in the last byte. If all bits are valid, then the value of valid bits is 0

GetRadioFrequencyConfigSize(ReceiverRadioFrequencyConfiguration)

Get the size of the configuration of a specific receiver configuration

public int GetRadioFrequencyConfigSize(ReceiverRadioFrequencyConfiguration receiver)

Parameters

receiver ReceiverRadioFrequencyConfiguration

The receiver configuration

Returns

int

True if success

GetRadioFrequencyConfigSize(TransmitterRadioFrequencyConfiguration)

Get the size of the configuration of a specific transmitter configuration

public int GetRadioFrequencyConfigSize(TransmitterRadioFrequencyConfiguration transmitter)

Parameters

transmitter TransmitterRadioFrequencyConfiguration

The transmitter configuration

Returns

int

True if success

GetRadioFrequencyStatus()

Get the radio frenquency status

public RadioFrequencyStatus GetRadioFrequencyStatus()

Returns

RadioFrequencyStatus

The radio frequence status

GetVersions()

Get the Product, Firmware and EEPROM versions of the PN8150

public TripletVersion GetVersions()

Returns

TripletVersion

A tuple with the Product, Firmware and EEPROM versions

IsRadioFrequencyFieldExternal()

Is the external field activated?

public bool IsRadioFrequencyFieldExternal()

Returns

bool

True if active, false if not

ListenToCardIso14443TypeA(TransmitterRadioFrequencyConfiguration, ReceiverRadioFrequencyConfiguration, out Data106kbpsTypeA?, int)

Listen to any 14443 Type A card

public bool ListenToCardIso14443TypeA(TransmitterRadioFrequencyConfiguration transmitter, ReceiverRadioFrequencyConfiguration receiver, out Data106kbpsTypeA? card, int timeoutPollingMilliseconds)

Parameters

transmitter TransmitterRadioFrequencyConfiguration

The transmitter configuration, should be compatible with type A card

receiver ReceiverRadioFrequencyConfiguration

The receiver configuration, should be compatible with type A card

card Data106kbpsTypeA

The type A card once detected

timeoutPollingMilliseconds int

The time to poll the card in milliseconds. Card detection will stop once the detection time will be over

Returns

bool

True if a 14443 Type A card has been detected

ListenToCardIso14443TypeB(TransmitterRadioFrequencyConfiguration, ReceiverRadioFrequencyConfiguration, out Data106kbpsTypeB?, int)

Listen to any 14443 Type B card

public bool ListenToCardIso14443TypeB(TransmitterRadioFrequencyConfiguration transmitter, ReceiverRadioFrequencyConfiguration receiver, out Data106kbpsTypeB? card, int timeoutPollingMilliseconds)

Parameters

transmitter TransmitterRadioFrequencyConfiguration

The transmitter configuration, should be compatible with type B card

receiver ReceiverRadioFrequencyConfiguration

The receiver configuration, should be compatible with type A card

card Data106kbpsTypeB

The type B card once detected

timeoutPollingMilliseconds int

The time to poll the card in milliseconds. Card detection will stop once the detection time will be over

Returns

bool

True if a 14443 Type B card has been detected

LoadRadioFrequencyConfiguration(TransmitterRadioFrequencyConfiguration, ReceiverRadioFrequencyConfiguration)

Load a specific radio frequency configuration

public bool LoadRadioFrequencyConfiguration(TransmitterRadioFrequencyConfiguration transmitter, ReceiverRadioFrequencyConfiguration receiver)

Parameters

transmitter TransmitterRadioFrequencyConfiguration

The transmitter configuration

receiver ReceiverRadioFrequencyConfiguration

The receiver configuration

Returns

bool

True if success

MifareAuthenticate(SpanByte, MifareCardCommand, byte, SpanByte)

Specific function to authenticate Mifare cards

public bool MifareAuthenticate(SpanByte key, MifareCardCommand mifareCommand, byte blockAddress, SpanByte cardUid)

Parameters

key SpanByte

A 6 bytes key

mifareCommand MifareCardCommand

MifareCardCommand.AuthenticationA or MifareCardCommand.AuthenticationB

blockAddress byte

The block address to authenticate

cardUid SpanByte

The 4 bytes UUID of the card

Returns

bool

True if success

ReadAllEeprom(SpanByte)

Read the full EEPROM

public bool ReadAllEeprom(SpanByte eeprom)

Parameters

eeprom SpanByte

At 255 bytes buffer

Returns

bool

True if success

ReadDataFromCard(SpanByte)

Read data from a card.

public bool ReadDataFromCard(SpanByte toRead)

Parameters

toRead SpanByte

The span of byte to read

Returns

bool

True if success

Remarks

Using this function you'll have to manage yourself the possible low level communication protocol. This function write directly to the card all the bytes. Please make sure you'll first load specific radio frequence settings, detect a card, select it and then send data

ReadDataFromCard(SpanByte, out int)

Read all the data from the card

public bool ReadDataFromCard(SpanByte toRead, out int bytesRead)

Parameters

toRead SpanByte

The span of byte to read

bytesRead int

number of bytes read

Returns

bool

A byte array with all the read elements, null if nothing can be read

Remarks

Using this function you'll have to manage yourself the possible low level communication protocol. This function write directly to the card all the bytes. Please make sure you'll first load specific radio frequence settings, detect a card, select it and then send data

ReadEeprom(EepromAddress, SpanByte)

Read a specific part of the EEPROM

public bool ReadEeprom(EepromAddress address, SpanByte eeprom)

Parameters

address EepromAddress

The EEPROM address

eeprom SpanByte

A span of byte to read the EEPROM

Returns

bool

True if success

ReselectTarget(byte)

Once you have an authentication operation failing with Mifare cards or a read/write, the card stop. TYhe only way to have it back is to send the unselect and anti collision. This function provides this feature

public override bool ReselectTarget(byte targetNumber)

Parameters

targetNumber byte

The target number to reselect

Returns

bool

True if success

RetrieveRadioFrequencyConfiguration(ReceiverRadioFrequencyConfiguration, SpanByte)

Retrieve the radio frequency configuration

public bool RetrieveRadioFrequencyConfiguration(ReceiverRadioFrequencyConfiguration receiver, SpanByte configuration)

Parameters

receiver ReceiverRadioFrequencyConfiguration

The receiver configuration

configuration SpanByte

A span of bytes for the configuration. Should be a multiple of 5 with the size of

Returns

bool

True if success

RetrieveRadioFrequencyConfiguration(TransmitterRadioFrequencyConfiguration, SpanByte)

Retrieve the radio frequency configuration

public bool RetrieveRadioFrequencyConfiguration(TransmitterRadioFrequencyConfiguration transmitter, SpanByte configuration)

Parameters

transmitter TransmitterRadioFrequencyConfiguration

The transmitter configuration

configuration SpanByte

A span of bytes for the configuration. Should be a multiple of 5 with the size of

Returns

bool

True if success

SendDataToCard(SpanByte, int)

Send data to a card.

public bool SendDataToCard(SpanByte toSend, int numberValidBitsLastByte = 8)

Parameters

toSend SpanByte

The span of byte to send

numberValidBitsLastByte int

The number of bits valid in the last byte, 8 is the default. If validBits == 3 then it's equivalent to apply a mask of 0b000_0111 to get the correct valid bits

Returns

bool

True if success

Remarks

Using this function you'll have to manage yourself the possible low level communication protocol. This function write directly to the card all the bytes. Please make sure you'll first load specific radio frequence settings, detect a card, select it and then send data

Transceive(byte, SpanByte, SpanByte)

This function has to be implemented by all NFC/RFID/Card readers. This function is used in exchange of data with the reader and the cards.

public override int Transceive(byte targetNumber, SpanByte dataToSend, SpanByte dataFromCard)

Parameters

targetNumber byte

Some readers have a notion of target number for the cards as they can read multiple ones

dataToSend SpanByte

A standardized raw buffer with the command at the position 0 in the array

dataFromCard SpanByte

If any data are read from the card, they will be put into this array

Returns

int

-1 in case of error, otherwise the number of bytes read and copied into the dataFromCard array

UpdateRadioFrequencyConfiguration(ReceiverRadioFrequencyConfiguration, SpanByte)

Update the radio frequency configuration

public bool UpdateRadioFrequencyConfiguration(ReceiverRadioFrequencyConfiguration receiver, SpanByte configuration)

Parameters

receiver ReceiverRadioFrequencyConfiguration

The receiver configuration

configuration SpanByte

A span of bytes for the configuration. Should be a multiple of 5 with the size of

Returns

bool

True if success

UpdateRadioFrequencyConfiguration(TransmitterRadioFrequencyConfiguration, SpanByte)

Update the radio frequency configuration

public bool UpdateRadioFrequencyConfiguration(TransmitterRadioFrequencyConfiguration transmitter, SpanByte configuration)

Parameters

transmitter TransmitterRadioFrequencyConfiguration

The transmitter configuration

configuration SpanByte

A span of bytes for the configuration. Should be a multiple of 5 with the size of

Returns

bool

True if success

WriteAllEeprom(SpanByte)

Write all the EEPROM

public bool WriteAllEeprom(SpanByte eeprom)

Parameters

eeprom SpanByte

A 255 bytes buffer

Returns

bool

True if success

WriteEeprom(EepromAddress, SpanByte)

Write the EEPROM at a specific address

public bool WriteEeprom(EepromAddress address, SpanByte eeprom)

Parameters

address EepromAddress

The EEPROM address

eeprom SpanByte

A span of byte to write the EEPROM

Returns

bool

True if success