Table of Contents

Class Pn532

Namespace
Iot.Device.Pn532
Assembly
Iot.Device.Pn532.dll

PN532 RFID/NFC reader

public class Pn532 : CardTransceiver
Inheritance
Pn532

Constructors

Pn532(I2cDevice)

Create a PN532 using I2C

public Pn532(I2cDevice i2cDevice)

Parameters

i2cDevice I2cDevice

The I2C device

Pn532(SpiDevice, int, GpioController?, bool)

Create a PN532 using SPI

public Pn532(SpiDevice spiDevice, int pinChipSelect, GpioController? controller = null, bool shouldDispose = false)

Parameters

spiDevice SpiDevice

The SPI Device

pinChipSelect int

The GPIO pin number for the chip select

controller GpioController

A GPIO controller

shouldDispose bool

Dispose the GPIO Controller at the end

Pn532(string)

Create a PN532 using Serial Port

public Pn532(string portName)

Parameters

portName string

The port name

Fields

I2cDefaultAddress

The default I2C address

public const byte I2cDefaultAddress = 36

Field Value

byte

SpiClockFrequency

PN532 SPI Clock Frequency

public const int SpiClockFrequency = 2000000

Field Value

int

SpiMode

Only SPI Mode supported is Mode0

public const SpiMode SpiMode = Mode0

Field Value

SpiMode

Properties

FirmwareVersion

Firmware version information

public FirmwareVersion? FirmwareVersion { get; }

Property Value

FirmwareVersion

ParametersFlags

Get or set the Security Access Module parameters

public ParametersFlags ParametersFlags { get; set; }

Property Value

ParametersFlags

ReadTimeOut

Set or get the read timeout for I2C and SPI Please refer to the documentation to set the right timeout value depending on the communication mode you are using

public int ReadTimeOut { get; set; }

Property Value

int

SecurityAccessModuleMode

Get or set the Security Access Module Mode

public SecurityAccessModuleMode SecurityAccessModuleMode { get; set; }

Property Value

SecurityAccessModuleMode

VirtualCardTimeout

Get or set the timeout when PN532 is in virtual card mode

public uint VirtualCardTimeout { get; set; }

Property Value

uint

Methods

AutoPoll(byte, ushort, PollingType[])

Automatically poll specific types of devices

public byte[] AutoPoll(byte numberPolling, ushort periodMilliSecond, PollingType[] pollingType)

Parameters

numberPolling byte

The number of polling before accepting a card

periodMilliSecond ushort

The period of polling before accepting a card

pollingType PollingType[]

The type of cards to poll

Returns

byte[]

A raw byte array containing the number of cards, the card type and the raw data. Null if nothing has been polled

DeselectTarget(byte)

Deselect a specific target number card

public bool DeselectTarget(byte targetNumber)

Parameters

targetNumber byte

Target number card

Returns

bool

True if success

Dispose()

Dispose

public void Dispose()

InitAsTarget(TargetModeInitialization, TargetMifareParameters, TargetFeliCaParameters, TargetPiccParameters)

Set the PN532 as a target, so as a card

public AsTargetInitialized InitAsTarget(TargetModeInitialization mode, TargetMifareParameters mifare, TargetFeliCaParameters feliCa, TargetPiccParameters picc)

Parameters

mode TargetModeInitialization
mifare TargetMifareParameters
feliCa TargetFeliCaParameters
picc TargetPiccParameters

Returns

AsTargetInitialized

ListPassiveTarget(MaxTarget, TargetBaudRate)

List all targets cards in range When using this function, you can't determine which target you've read So you'll need to use the Decode functions to try to get a card type So use this function only with a specific card type. Prefer the AutoPoll function As the type identified is returned

public byte[] ListPassiveTarget(MaxTarget maxTarget, TargetBaudRate targetBaudRate)

Parameters

maxTarget MaxTarget

The maximum number of targets

targetBaudRate TargetBaudRate

The baud rate to use

Returns

byte[]

A raw byte array with the data of the targets if any has been identified

ListPassiveTarget(MaxTarget, TargetBaudRate, SpanByte)

List all targets cards in range When using this function, you can't determine which target you've read So you'll need to use the Decode functions to try to get a card type So use this function only with a specific card type. Prefer the AutoPoll function As the type identified is returned

public byte[] ListPassiveTarget(MaxTarget maxTarget, TargetBaudRate targetBaudRate, SpanByte initiatorData)

Parameters

maxTarget MaxTarget

The maximum number of targets

targetBaudRate TargetBaudRate

The baud rate to use to find cards

initiatorData SpanByte

Specific initialization data

Returns

byte[]

A raw byte array with the data of the targets if any has been identified

PowerDown(WakeUpEnable)

Power down the PN532

public bool PowerDown(WakeUpEnable wakeUpEnable)

Parameters

wakeUpEnable WakeUpEnable

What can wake the PN532

Returns

bool

True if success

ReadDataAsTarget(SpanByte)

read data from the reader when PN532 is a target

public int ReadDataAsTarget(SpanByte receivedData)

Parameters

receivedData SpanByte

A Span byte array for the read data. Note the first byte contains the status

Returns

int

Number of byte read

ReadGpio(out Port3, out Port7, out OperatingMode)

Read the PN532 GPIO

public bool ReadGpio(out Port3 p3, out Port7 p7, out OperatingMode l0L1)

Parameters

p3 Port3

The P3 GPIO

p7 Port7

The P7 GPIO

l0L1 OperatingMode

The specific operation mode register

Returns

bool

True if success

ReadRegister(ushort, out byte)

Read a single register

public bool ReadRegister(ushort register, out byte registerValue)

Parameters

register ushort

The register to read

registerValue byte

The value of the register

Returns

bool

True if success

ReadRegister(ushort[], SpanByte)

Read any register from the XRAM

public bool ReadRegister(ushort[] registers, SpanByte registerValues)

Parameters

registers ushort[]

Array of register to read

registerValues SpanByte

Register read values

Returns

bool

True if success

ReadRegisterSfr(SfrRegister[], SpanByte)

Read an array of SFR registers

public bool ReadRegisterSfr(SfrRegister[] registers, SpanByte registerValues)

Parameters

registers SfrRegister[]

Array of register to read

registerValues SpanByte

Register read values

Returns

bool

True if success

ReleaseTarget(byte)

Release a specific target number card

public bool ReleaseTarget(byte targetNumber)

Parameters

targetNumber byte

Target number card

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

RunSelfTest(DiagnoseMode)

Run self tests Note: some self tests are not implemented yet

public bool RunSelfTest(DiagnoseMode diagnoseMode)

Parameters

diagnoseMode DiagnoseMode

The self test to run

Returns

bool

True when success

SelectTarget(byte)

Select a specific target number card

public bool SelectTarget(byte targetNumber)

Parameters

targetNumber byte

Target number card

Returns

bool

True if success

SetAnalog106kbpsTypeA(Analog106kbpsTypeAMode)

Set the specific 106 kbps card Type A modes

public bool SetAnalog106kbpsTypeA(Analog106kbpsTypeAMode analog106Kbps)

Parameters

analog106Kbps Analog106kbpsTypeAMode

The mode settings

Returns

bool

True is success

SetAnalog212_424Kbps(Analog212_424kbpsMode)

Set the specific 212 424 kbps card modes

public bool SetAnalog212_424Kbps(Analog212_424kbpsMode analog212_424)

Parameters

analog212_424 Analog212_424kbpsMode

The mode settings

Returns

bool

True is success

SetAnalog212_424_848kbps(Analog212_424_848kbpsMode)

Configure analog mode

public bool SetAnalog212_424_848kbps(Analog212_424_848kbpsMode analog212_424_848Kbps)

Parameters

analog212_424_848Kbps Analog212_424_848kbpsMode

Settings

Returns

bool

True is success

SetAnalogTypeB(AnalogSettingsTypeBMode)

Set the specific 106 kbps card Type B modes

public bool SetAnalogTypeB(AnalogSettingsTypeBMode analogSettings)

Parameters

analogSettings AnalogSettingsTypeBMode

The mode settings

Returns

bool

True is success

SetMaxRetriesInitialization(MaxRetriesMode)

Set the MAximu Retries during the various initialization modes

public bool SetMaxRetriesInitialization(MaxRetriesMode maxRetriesMode)

Parameters

maxRetriesMode MaxRetriesMode

Retry modes

Returns

bool

True is success

SetMaxRetryWriteRead(byte)

Set the Maximum Retry in the 2 WriteRead modes

public bool SetMaxRetryWriteRead(byte numberRetries = 0)

Parameters

numberRetries byte

The number of retries

Returns

bool

True is success

SetRfField(RfFieldMode)

Set the Radio Frequency Field Mode

public bool SetRfField(RfFieldMode rfFieldMode)

Parameters

rfFieldMode RfFieldMode

Radio Frequency Field Mode

Returns

bool

True is success

SetSerialBaudRate(BaudRate)

Setup the baud rate communication when using the HSU Serial Port mode

public bool SetSerialBaudRate(BaudRate baudRate)

Parameters

baudRate BaudRate

Baud rate

Returns

bool

True if success

SetVariousTimings(VariousTimingsMode)

Set the Various Timing Mode

public bool SetVariousTimings(VariousTimingsMode variousTimingsMode)

Parameters

variousTimingsMode VariousTimingsMode

Various Timing Mode

Returns

bool

True is success

Transceive(byte, SpanByte, SpanByte)

Write data to a card and read what the card responses

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

Parameters

targetNumber byte

The card target number

dataToSend SpanByte

The data to write to the card

dataFromCard SpanByte

The potential data to receive

Returns

int

The number of bytes read

TransceiveAdvance(byte, SpanByte, SpanByte)

Use the build in feature to transceive the data to the card. This add specific logic for some cards.

public int TransceiveAdvance(byte targetNumber, SpanByte dataToSend, SpanByte dataFromCard)

Parameters

targetNumber byte

The card target number

dataToSend SpanByte

The data to write to the card

dataFromCard SpanByte

The potential data to receive

Returns

int

The number of bytes read

TryDecode106kbpsTypeA(SpanByte)

Try to decode a raw byte array containing target information to a 106 kbps Type A card

public Data106kbpsTypeA TryDecode106kbpsTypeA(SpanByte toDecode)

Parameters

toDecode SpanByte

The raw byte array

Returns

Data106kbpsTypeA

A decoded card of null if it can't

TryDecodeData106kbpsInnovisionJewel(SpanByte)

Try to decode a raw byte array containing target information to a 106 kbps Innovision Jewel card

public Data106kbpsInnovisionJewel TryDecodeData106kbpsInnovisionJewel(SpanByte toDecode)

Parameters

toDecode SpanByte

The raw byte array

Returns

Data106kbpsInnovisionJewel

A decoded card of null if it can't

TryDecodeData106kbpsTypeB(SpanByte)

Try to decode a raw byte array containing target information to a 106 kbps Type B card

public Data106kbpsTypeB TryDecodeData106kbpsTypeB(SpanByte toDecode)

Parameters

toDecode SpanByte

The raw byte array

Returns

Data106kbpsTypeB

A decoded card of null if it can't

TryDecodeData212_424Kbps(SpanByte)

Try to decode a raw byte array containing target information to a 212 424 kbps card

public Data212_424kbps TryDecodeData212_424Kbps(SpanByte toDecode)

Parameters

toDecode SpanByte

The raw byte array

Returns

Data212_424kbps

A decoded card of null if it can't

WakeUp()

Wake Up the PN532

public void WakeUp()

WriteDataAsTarget(SpanByte)

Write data to the reader when PN532 is a target

public bool WriteDataAsTarget(SpanByte dataToSend)

Parameters

dataToSend SpanByte

The data to send

Returns

bool

True if success

WriteGpio(Port3)

Write the PN532 GPIO port 3 leaving port 7 in it's current state

public bool WriteGpio(Port3 p3)

Parameters

p3 Port3

The P3 GPIO

Returns

bool

True if success

WriteGpio(Port7)

Write the PN532 GPIO port 7 leaving port 3 in it's current state

public bool WriteGpio(Port7 p7)

Parameters

p7 Port7

The P7 GPIO

Returns

bool

True if success

WriteGpio(Port7, Port3)

Write the PN532 GPIO ports 3 and 7

public bool WriteGpio(Port7 p7, Port3 p3)

Parameters

p7 Port7

The P7 GPIO

p3 Port3

The P3 GPIO

Returns

bool

True if success

WriteReadDirect(SpanByte, SpanByte)

Write an array of data directly to the card without adding anything from the PN532 and read the raw data

public int WriteReadDirect(SpanByte dataToSend, SpanByte dataFromCard)

Parameters

dataToSend SpanByte

The data to write to the card

dataFromCard SpanByte

The potential data to receive

Returns

int

The number of bytes read

WriteRegister(ushort, byte)

Write a single register

public bool WriteRegister(ushort register, byte registerValue)

Parameters

register ushort

The register to write

registerValue byte

The value of the register

Returns

bool

True if success

WriteRegister(ushort[], SpanByte)

Write an array of register

public bool WriteRegister(ushort[] registers, SpanByte registerValue)

Parameters

registers ushort[]

Array of register to write

registerValue SpanByte

Register values to write

Returns

bool

WriteRegisterSfr(SfrRegister[], SpanByte)

Write an array of SFR registers

public bool WriteRegisterSfr(SfrRegister[] registers, SpanByte registerValue)

Parameters

registers SfrRegister[]

Array of register to write

registerValue SpanByte

Register values to write

Returns

bool

True if success