Class Pn5180
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
SpiDeviceThe SPI device
pinBusy
intThe pin for the busy line
pinNss
intThe 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
GpioControllerA GPIO controller, null will use a default one
shouldDispose
boolDispose 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
MaximumSpiClockFrequency
PN532 SPI Clock Frequency
public const int MaximumSpiClockFrequency = 7000000
Field Value
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
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
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
RadioFrequencyField
Get or set the radio frequency field. True for on, false for off
public bool RadioFrequencyField { get; set; }
Property Value
Methods
CalculateCrcA(SpanByte, SpanByte)
Provide a calculation of CRC for Type A cards
public void CalculateCrcA(SpanByte buffer, SpanByte crc)
Parameters
CalculateCrcB(SpanByte, SpanByte)
Provide a calculation of CRC for Type B cards
public void CalculateCrcB(SpanByte buffer, SpanByte crc)
Parameters
DeselectCardTypeB(Data106kbpsTypeB)
Deselect a 14443 Type B card
public bool DeselectCardTypeB(Data106kbpsTypeB card)
Parameters
card
Data106kbpsTypeBThe 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
SpanByteA 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
ReceiverRadioFrequencyConfigurationThe 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
TransmitterRadioFrequencyConfigurationThe 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
TransmitterRadioFrequencyConfigurationThe transmitter configuration, should be compatible with type A card
receiver
ReceiverRadioFrequencyConfigurationThe receiver configuration, should be compatible with type A card
card
Data106kbpsTypeAThe type A card once detected
timeoutPollingMilliseconds
intThe 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
TransmitterRadioFrequencyConfigurationThe transmitter configuration, should be compatible with type B card
receiver
ReceiverRadioFrequencyConfigurationThe receiver configuration, should be compatible with type A card
card
Data106kbpsTypeBThe type B card once detected
timeoutPollingMilliseconds
intThe 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
TransmitterRadioFrequencyConfigurationThe transmitter configuration
receiver
ReceiverRadioFrequencyConfigurationThe 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
SpanByteA 6 bytes key
mifareCommand
MifareCardCommandMifareCardCommand.AuthenticationA or MifareCardCommand.AuthenticationB
blockAddress
byteThe block address to authenticate
cardUid
SpanByteThe 4 bytes UUID of the card
Returns
- bool
True if success
ReadAllEeprom(SpanByte)
Read the full EEPROM
public bool ReadAllEeprom(SpanByte eeprom)
Parameters
eeprom
SpanByteAt 255 bytes buffer
Returns
- bool
True if success
ReadDataFromCard(SpanByte)
Read data from a card.
public bool ReadDataFromCard(SpanByte toRead)
Parameters
toRead
SpanByteThe 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
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
EepromAddressThe EEPROM address
eeprom
SpanByteA 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
byteThe 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
ReceiverRadioFrequencyConfigurationThe receiver configuration
configuration
SpanByteA 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
TransmitterRadioFrequencyConfigurationThe transmitter configuration
configuration
SpanByteA 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
SpanByteThe span of byte to send
numberValidBitsLastByte
intThe 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
byteSome readers have a notion of target number for the cards as they can read multiple ones
dataToSend
SpanByteA standardized raw buffer with the command at the position 0 in the array
dataFromCard
SpanByteIf 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
ReceiverRadioFrequencyConfigurationThe receiver configuration
configuration
SpanByteA 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
TransmitterRadioFrequencyConfigurationThe transmitter configuration
configuration
SpanByteA 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
SpanByteA 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
EepromAddressThe EEPROM address
eeprom
SpanByteA span of byte to write the EEPROM
Returns
- bool
True if success