This is the description of the Delphi/Lazarus API bindings for the NFC Bricklet. General information and technical specifications for the NFC Bricklet are summarized in its hardware description.
An installation guide for the Delphi/Lazarus API bindings is part of their general description.
The example code below is Public Domain (CC0 1.0).
Download (ExampleEmulateNDEF.pas)
1program ExampleEmulateNDEF;
2
3{$ifdef MSWINDOWS}{$apptype CONSOLE}{$endif}
4{$ifdef FPC}{$mode OBJFPC}{$H+}{$endif}
5
6uses
7 SysUtils, IPConnection, BrickletNFC;
8
9type
10 TExample = class
11 private
12 ipcon: TIPConnection;
13 nfc: TBrickletNFC;
14 public
15 procedure CardemuStateChangedCB(sender: TBrickletNFC; const state: byte;
16 const idle: boolean);
17 procedure Execute;
18 end;
19
20const
21 HOST = 'localhost';
22 PORT = 4223;
23 UID = 'XYZ'; { Change XYZ to the UID of your NFC Bricklet }
24 NDEF_URI = 'www.tinkerforge.com';
25
26var
27 e: TExample;
28
29{ Callback procedure for cardemu state changed callback }
30procedure TExample.CardemuStateChangedCB(sender: TBrickletNFC; const state: byte;
31 const idle: boolean);
32 var i: byte;
33 var ndefRecordURI: Array of Byte;
34begin
35 if state = BRICKLET_NFC_CARDEMU_STATE_IDLE then begin
36 { Only short records are supported }
37 SetLength(ndefRecordURI, Length(NDEF_URI) + 5);
38
39 ndefRecordURI[0] := $D1; { MB/ME/CF/SR=1/IL/TNF }
40 ndefRecordURI[1] := $01; { TYPE LENGTH }
41 ndefRecordURI[2] := Length(NDEF_URI) + 1; { Length }
42 ndefRecordURI[3] := ord('U'); { Type }
43 ndefRecordURI[4] := $04; { Status }
44
45 for i := 0 to (Length(NDEF_URI) + 1) do begin
46 ndefRecordURI[5 + i] := ord(NDEF_URI[i + 1]);
47 end;
48
49 nfc.CardemuWriteNDEF(ndefRecordURI);
50 nfc.CardemuStartDiscovery;
51 end
52 else if state = BRICKLET_NFC_CARDEMU_STATE_DISCOVER_READY then begin
53 sender.CardemuStartTransfer(BRICKLET_NFC_CARDEMU_TRANSFER_WRITE);
54 end
55 else if state = BRICKLET_NFC_CARDEMU_STATE_DISCOVER_ERROR then begin
56 WriteLn('Discover error');
57 end
58 else if state = BRICKLET_NFC_CARDEMU_STATE_TRANSFER_NDEF_ERROR then begin
59 WriteLn('Transfer NDEF error');
60 end;
61end;
62
63procedure TExample.Execute;
64begin
65 { Create IP connection }
66 ipcon := TIPConnection.Create;
67
68 { Create device object }
69 nfc := TBrickletNFC.Create(UID, ipcon);
70
71 { Connect to brickd }
72 ipcon.Connect(HOST, PORT);
73 { Don't use device before ipcon is connected }
74
75 { Register cardemu state changed callback to procedure CardemuStateChangedCB }
76 nfc.OnCardemuStateChanged := {$ifdef FPC}@{$endif}CardemuStateChangedCB;
77
78 { Enable cardemu mode }
79 nfc.SetMode(BRICKLET_NFC_MODE_CARDEMU);
80
81 WriteLn('Press key to exit');
82 ReadLn;
83 ipcon.Destroy; { Calls ipcon.Disconnect internally }
84end;
85
86begin
87 e := TExample.Create;
88 e.Execute;
89 e.Destroy;
90end.
Download (ExampleWriteReadType2.pas)
1program ExampleWriteReadType2;
2
3{$ifdef MSWINDOWS}{$apptype CONSOLE}{$endif}
4{$ifdef FPC}{$mode OBJFPC}{$H+}{$endif}
5
6uses
7 SysUtils, IPConnection, BrickletNFC;
8
9type
10 TExample = class
11 private
12 ipcon: TIPConnection;
13 nfc: TBrickletNFC;
14 public
15 procedure ReaderStateChangedCB(sender: TBrickletNFC; const state: byte;
16 const idle: boolean);
17 procedure Execute;
18 end;
19
20const
21 HOST = 'localhost';
22 PORT = 4223;
23 UID = 'XYZ'; { Change XYZ to the UID of your NFC Bricklet }
24
25var
26 e: TExample;
27
28{ Callback procedure for reader state changed callback }
29procedure TExample.ReaderStateChangedCB(sender: TBrickletNFC; const state: byte;
30 const idle: boolean);
31 var tagType: byte;
32 var page: TArrayOfUInt8;
33 var tagID: TArrayOfUInt8;
34begin
35 if state = BRICKLET_NFC_READER_STATE_IDLE then begin
36 sender.ReaderRequestTagID;
37 end
38 else if state = BRICKLET_NFC_READER_STATE_REQUEST_TAG_ID_READY then begin
39 sender.ReaderGetTagID(tagType, tagID);
40
41 if (tagType <> BRICKLET_NFC_TAG_TYPE_TYPE2) then begin
42 WriteLn('Tag is not type-2');
43 exit;
44 end;
45
46 WriteLn('Found tag of type ' + IntToStr(tagType) + ' with ID [' +
47 Format('0x%X', [tagID[0]]) + ' ' +
48 Format('0x%X', [tagID[1]]) + ' ' +
49 Format('0x%X', [tagID[2]]) + ' ' +
50 Format('0x%X', [tagID[3]]) + ']');
51 sender.readerRequestPage(1, 4);
52 end
53 else if state = BRICKLET_NFC_READER_STATE_REQUEST_TAG_ID_ERROR then begin
54 WriteLn('Request tag ID error');
55 end
56 else if state = BRICKLET_NFC_READER_STATE_REQUEST_PAGE_READY then begin
57 page := sender.ReaderReadPage;
58 WriteLn('Read page: ' +
59 Format('0x%X', [page[0]]) + ' ' +
60 Format('0x%X', [page[1]]) + ' ' +
61 Format('0x%X', [page[2]]) + ' ' +
62 Format('0x%X', [page[3]]));
63 sender.ReaderWritePage(1, page);
64 end
65 else if state = BRICKLET_NFC_READER_STATE_WRITE_PAGE_READY then begin
66 WriteLn('Write page ready');
67 end
68 else if state = BRICKLET_NFC_READER_STATE_REQUEST_PAGE_ERROR then begin
69 WriteLn('Request page error');
70 end
71 else if state = BRICKLET_NFC_READER_STATE_WRITE_PAGE_ERROR then begin
72 WriteLn('Write page error');
73 end;
74end;
75
76procedure TExample.Execute;
77begin
78 { Create IP connection }
79 ipcon := TIPConnection.Create;
80
81 { Create device object }
82 nfc := TBrickletNFC.Create(UID, ipcon);
83
84 { Connect to brickd }
85 ipcon.Connect(HOST, PORT);
86 { Don't use device before ipcon is connected }
87
88 { Register reader state changed callback to procedure ReaderStateChangedCB }
89 nfc.OnReaderStateChanged := {$ifdef FPC}@{$endif}ReaderStateChangedCB;
90
91 { Enable reader mode }
92 nfc.SetMode(BRICKLET_NFC_MODE_READER);
93
94 WriteLn('Press key to exit');
95 ReadLn;
96 ipcon.Destroy; { Calls ipcon.Disconnect internally }
97end;
98
99begin
100 e := TExample.Create;
101 e.Execute;
102 e.Destroy;
103end.
Since Delphi does not support multiple return values directly, we use the
out keyword to return multiple values from a function.
All functions and procedures listed below are thread-safe.
| Parameters: |
|
|---|---|
| Returns: |
|
Creates an object with the unique device ID uid:
nfc := TBrickletNFC.Create('YOUR_DEVICE_UID', ipcon);
This object can then be used after the IP Connection is connected.
| Parameters: |
|
|---|
Sets the mode. The NFC Bricklet supports four modes:
Off
Card Emulation (Cardemu): Emulates a tag for other readers
Peer to Peer (P2P): Exchange data with other readers
Reader: Reads and writes tags
Simple: Automatically reads tag IDs
If you change a mode, the Bricklet will reconfigure the hardware for this mode. Therefore, you can only use functions corresponding to the current mode. For example, in Reader mode you can only use Reader functions.
The following constants are available for this function:
For mode:
BRICKLET_NFC_MODE_OFF = 0
BRICKLET_NFC_MODE_CARDEMU = 1
BRICKLET_NFC_MODE_P2P = 2
BRICKLET_NFC_MODE_READER = 3
BRICKLET_NFC_MODE_SIMPLE = 4
| Returns: |
|
|---|
Returns the mode as set by SetMode.
The following constants are available for this function:
For mode:
BRICKLET_NFC_MODE_OFF = 0
BRICKLET_NFC_MODE_CARDEMU = 1
BRICKLET_NFC_MODE_P2P = 2
BRICKLET_NFC_MODE_READER = 3
BRICKLET_NFC_MODE_SIMPLE = 4
After you call ReaderRequestTagID the NFC Bricklet will try to read
the tag ID from the tag. After this process is done the state will change.
You can either register the OnReaderStateChanged callback or you can poll
ReaderGetState to find out about the state change.
If the state changes to ReaderRequestTagIDError it means that either there was
no tag present or that the tag has an incompatible type. If the state
changes to ReaderRequestTagIDReady it means that a compatible tag was found
and that the tag ID has been saved. You can now read out the tag ID by
calling ReaderGetTagID.
If two tags are in the proximity of the NFC Bricklet, this
function will cycle through the tags. To select a specific tag you have
to call ReaderRequestTagID until the correct tag ID is found.
In case of any ReaderError state the selection is lost and you have to
start again by calling ReaderRequestTagID.
| Output Parameters: |
|
|---|
Returns the tag type and the tag ID. This function can only be called if the
NFC Bricklet is currently in one of the ReaderReady states. The returned tag ID
is the tag ID that was saved through the last call of ReaderRequestTagID.
To get the tag ID of a tag the approach is as follows:
Call ReaderRequestTagID
Wait for state to change to ReaderRequestTagIDReady (see ReaderGetState or
OnReaderStateChanged callback)
Call ReaderGetTagID
The following constants are available for this function:
For tagType:
BRICKLET_NFC_TAG_TYPE_MIFARE_CLASSIC = 0
BRICKLET_NFC_TAG_TYPE_TYPE1 = 1
BRICKLET_NFC_TAG_TYPE_TYPE2 = 2
BRICKLET_NFC_TAG_TYPE_TYPE3 = 3
BRICKLET_NFC_TAG_TYPE_TYPE4 = 4
BRICKLET_NFC_TAG_TYPE_TYPE5 = 5
| Output Parameters: |
|
|---|
Returns the current reader state of the NFC Bricklet.
On startup the Bricklet will be in the ReaderInitialization state. The initialization will only take about 20ms. After that it changes to ReaderIdle.
The Bricklet is also reinitialized if the mode is changed, see SetMode.
The functions of this Bricklet can be called in the ReaderIdle state and all of the ReaderReady and ReaderError states.
Example: If you call ReaderRequestPage, the state will change to
ReaderRequestPage until the reading of the page is finished. Then it will change
to either ReaderRequestPageReady if it worked or to ReaderRequestPageError if it
didn't. If the request worked you can get the page by calling ReaderReadPage.
The same approach is used analogously for the other API functions.
The following constants are available for this function:
For state:
BRICKLET_NFC_READER_STATE_INITIALIZATION = 0
BRICKLET_NFC_READER_STATE_IDLE = 128
BRICKLET_NFC_READER_STATE_ERROR = 192
BRICKLET_NFC_READER_STATE_REQUEST_TAG_ID = 2
BRICKLET_NFC_READER_STATE_REQUEST_TAG_ID_READY = 130
BRICKLET_NFC_READER_STATE_REQUEST_TAG_ID_ERROR = 194
BRICKLET_NFC_READER_STATE_AUTHENTICATE_MIFARE_CLASSIC_PAGE = 3
BRICKLET_NFC_READER_STATE_AUTHENTICATE_MIFARE_CLASSIC_PAGE_READY = 131
BRICKLET_NFC_READER_STATE_AUTHENTICATE_MIFARE_CLASSIC_PAGE_ERROR = 195
BRICKLET_NFC_READER_STATE_WRITE_PAGE = 4
BRICKLET_NFC_READER_STATE_WRITE_PAGE_READY = 132
BRICKLET_NFC_READER_STATE_WRITE_PAGE_ERROR = 196
BRICKLET_NFC_READER_STATE_REQUEST_PAGE = 5
BRICKLET_NFC_READER_STATE_REQUEST_PAGE_READY = 133
BRICKLET_NFC_READER_STATE_REQUEST_PAGE_ERROR = 197
BRICKLET_NFC_READER_STATE_WRITE_NDEF = 6
BRICKLET_NFC_READER_STATE_WRITE_NDEF_READY = 134
BRICKLET_NFC_READER_STATE_WRITE_NDEF_ERROR = 198
BRICKLET_NFC_READER_STATE_REQUEST_NDEF = 7
BRICKLET_NFC_READER_STATE_REQUEST_NDEF_READY = 135
BRICKLET_NFC_READER_STATE_REQUEST_NDEF_ERROR = 199
| Parameters: |
|
|---|
Writes NDEF formated data.
This function currently supports NFC Forum Type 2, 4, 5 and Mifare Classic.
The general approach for writing a NDEF message is as follows:
Call ReaderRequestTagID
Wait for state to change to ReaderRequestTagIDReady (see
ReaderGetState or OnReaderStateChanged callback)
If looking for a specific tag then call ReaderGetTagID and check
if the expected tag was found, if it was not found got back to step 1
Call ReaderWriteNDEF with the NDEF message that you want to write
Wait for state to change to ReaderWriteNDEFReady (see ReaderGetState
or OnReaderStateChanged callback)
Reads NDEF formated data from a tag.
This function currently supports NFC Forum Type 1, 2, 3, 4, 5 and Mifare Classic.
The general approach for reading a NDEF message is as follows:
Call ReaderRequestTagID
Wait for state to change to RequestTagIDReady (see ReaderGetState
or OnReaderStateChanged callback)
If looking for a specific tag then call ReaderGetTagID and check if the
expected tag was found, if it was not found got back to step 1
Call ReaderRequestNDEF
Wait for state to change to ReaderRequestNDEFReady (see ReaderGetState
or OnReaderStateChanged callback)
Call ReaderReadNDEF to retrieve the NDEF message from the buffer
| Returns: |
|
|---|
Returns the NDEF data from an internal buffer. To fill the buffer
with a NDEF message you have to call ReaderRequestNDEF beforehand.
| Parameters: |
|
|---|
Mifare Classic tags use authentication. If you want to read from or write to
a Mifare Classic page you have to authenticate it beforehand.
Each page can be authenticated with two keys: A (key_number = 0) and B
(key_number = 1). A new Mifare Classic
tag that has not yet been written to can be accessed with key A
and the default key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF].
The approach to read or write a Mifare Classic page is as follows:
Call ReaderRequestTagID
Wait for state to change to ReaderRequestTagIDReady (see ReaderGetState
or OnReaderStateChanged callback)
If looking for a specific tag then call ReaderGetTagID and check if the
expected tag was found, if it was not found got back to step 1
Call ReaderAuthenticateMifareClassicPage with page and key for the page
Wait for state to change to ReaderAuthenticatingMifareClassicPageReady (see
ReaderGetState or OnReaderStateChanged callback)
Call ReaderRequestPage or ReaderWritePage to read/write page
The authentication will always work for one whole sector (4 pages).
The following constants are available for this function:
For keyNumber:
BRICKLET_NFC_KEY_A = 0
BRICKLET_NFC_KEY_B = 1
| Parameters: |
|
|---|
Writes a maximum of 8192 bytes starting from the given page. How many pages are written depends on the tag type. The page sizes are as follows:
Mifare Classic page size: 16 byte
NFC Forum Type 1 page size: 8 byte
NFC Forum Type 2 page size: 4 byte
NFC Forum Type 3 page size: 16 byte
NFC Forum Type 4: No pages, page = file selection (CC or NDEF, see below)
NFC Forum Type 5 page size: 4 byte
The general approach for writing to a tag is as follows:
Call ReaderRequestTagID
Wait for state to change to ReaderRequestTagIDReady (see ReaderGetState or
OnReaderStateChanged callback)
If looking for a specific tag then call ReaderGetTagID and check if the
expected tag was found, if it was not found got back to step 1
Call ReaderWritePage with page number and data
Wait for state to change to ReaderWritePageReady (see ReaderGetState or
OnReaderStateChanged callback)
If you use a Mifare Classic tag you have to authenticate a page before you
can write to it. See ReaderAuthenticateMifareClassicPage.
NFC Forum Type 4 tags are not organized into pages but different files. We currently support two files: Capability Container file (CC) and NDEF file.
Choose CC by setting page to 3 or NDEF by setting page to 4.
The following constants are available for this function:
For page:
BRICKLET_NFC_READER_WRITE_TYPE4_CAPABILITY_CONTAINER = 3
BRICKLET_NFC_READER_WRITE_TYPE4_NDEF = 4
| Parameters: |
|
|---|
Reads a maximum of 8192 bytes starting from the given page and stores them into a buffer.
The buffer can then be read out with ReaderReadPage.
How many pages are read depends on the tag type. The page sizes are
as follows:
Mifare Classic page size: 16 byte
NFC Forum Type 1 page size: 8 byte
NFC Forum Type 2 page size: 4 byte
NFC Forum Type 3 page size: 16 byte
NFC Forum Type 4: No pages, page = file selection (CC or NDEF, see below)
NFC Forum Type 5 page size: 4 byte
The general approach for reading a tag is as follows:
Call ReaderRequestTagID
Wait for state to change to RequestTagIDReady (see ReaderGetState
or OnReaderStateChanged callback)
If looking for a specific tag then call ReaderGetTagID and check if the
expected tag was found, if it was not found got back to step 1
Call ReaderRequestPage with page number
Wait for state to change to ReaderRequestPageReady (see ReaderGetState
or OnReaderStateChanged callback)
Call ReaderReadPage to retrieve the page from the buffer
If you use a Mifare Classic tag you have to authenticate a page before you
can read it. See ReaderAuthenticateMifareClassicPage.
NFC Forum Type 4 tags are not organized into pages but different files. We currently support two files: Capability Container file (CC) and NDEF file.
Choose CC by setting page to 3 or NDEF by setting page to 4.
The following constants are available for this function:
For page:
BRICKLET_NFC_READER_REQUEST_TYPE4_CAPABILITY_CONTAINER = 3
BRICKLET_NFC_READER_REQUEST_TYPE4_NDEF = 4
| Returns: |
|
|---|
Returns the page data from an internal buffer. To fill the buffer
with specific pages you have to call ReaderRequestPage beforehand.
| Output Parameters: |
|
|---|
Returns the current cardemu state of the NFC Bricklet.
On startup the Bricklet will be in the CardemuInitialization state. The initialization will only take about 20ms. After that it changes to CardemuIdle.
The Bricklet is also reinitialized if the mode is changed, see SetMode.
The functions of this Bricklet can be called in the CardemuIdle state and all of the CardemuReady and CardemuError states.
Example: If you call CardemuStartDiscovery, the state will change to
CardemuDiscover until the discovery is finished. Then it will change
to either CardemuDiscoverReady if it worked or to CardemuDiscoverError if it
didn't.
The same approach is used analogously for the other API functions.
The following constants are available for this function:
For state:
BRICKLET_NFC_CARDEMU_STATE_INITIALIZATION = 0
BRICKLET_NFC_CARDEMU_STATE_IDLE = 128
BRICKLET_NFC_CARDEMU_STATE_ERROR = 192
BRICKLET_NFC_CARDEMU_STATE_DISCOVER = 2
BRICKLET_NFC_CARDEMU_STATE_DISCOVER_READY = 130
BRICKLET_NFC_CARDEMU_STATE_DISCOVER_ERROR = 194
BRICKLET_NFC_CARDEMU_STATE_TRANSFER_NDEF = 3
BRICKLET_NFC_CARDEMU_STATE_TRANSFER_NDEF_READY = 131
BRICKLET_NFC_CARDEMU_STATE_TRANSFER_NDEF_ERROR = 195
Starts the discovery process. If you call this function while a NFC reader device is near to the NFC Bricklet the state will change from CardemuDiscovery to CardemuDiscoveryReady.
If no NFC reader device can be found or if there is an error during discovery the cardemu state will change to CardemuDiscoveryError. In this case you have to restart the discovery process.
If the cardemu state changes to CardemuDiscoveryReady you can start the NDEF message
transfer with CardemuWriteNDEF and CardemuStartTransfer.
| Parameters: |
|
|---|
Writes the NDEF message that is to be transferred to the NFC peer.
The maximum supported NDEF message size in Cardemu mode is 255 byte.
You can call this function at any time in Cardemu mode. The internal buffer will not be overwritten until you call this function again or change the mode.
| Parameters: |
|
|---|
You can start the transfer of a NDEF message if the cardemu state is CardemuDiscoveryReady.
Before you call this function to start a write transfer, the NDEF message that
is to be transferred has to be written via CardemuWriteNDEF first.
After you call this function the state will change to CardemuTransferNDEF. It will change to CardemuTransferNDEFReady if the transfer was successful or CardemuTransferNDEFError if it wasn't.
The following constants are available for this function:
For transfer:
BRICKLET_NFC_CARDEMU_TRANSFER_ABORT = 0
BRICKLET_NFC_CARDEMU_TRANSFER_WRITE = 1
| Output Parameters: |
|
|---|
Returns the current P2P state of the NFC Bricklet.
On startup the Bricklet will be in the P2PInitialization state. The initialization will only take about 20ms. After that it changes to P2PIdle.
The Bricklet is also reinitialized if the mode is changed, see SetMode.
The functions of this Bricklet can be called in the P2PIdle state and all of the P2PReady and P2PError states.
Example: If you call P2PStartDiscovery, the state will change to
P2PDiscover until the discovery is finished. Then it will change
to either P2PDiscoverReady* if it worked or to P2PDiscoverError if it
didn't.
The same approach is used analogously for the other API functions.
The following constants are available for this function:
For state:
BRICKLET_NFC_P2P_STATE_INITIALIZATION = 0
BRICKLET_NFC_P2P_STATE_IDLE = 128
BRICKLET_NFC_P2P_STATE_ERROR = 192
BRICKLET_NFC_P2P_STATE_DISCOVER = 2
BRICKLET_NFC_P2P_STATE_DISCOVER_READY = 130
BRICKLET_NFC_P2P_STATE_DISCOVER_ERROR = 194
BRICKLET_NFC_P2P_STATE_TRANSFER_NDEF = 3
BRICKLET_NFC_P2P_STATE_TRANSFER_NDEF_READY = 131
BRICKLET_NFC_P2P_STATE_TRANSFER_NDEF_ERROR = 195
Starts the discovery process. If you call this function while another NFC P2P enabled device is near to the NFC Bricklet the state will change from P2PDiscovery to P2PDiscoveryReady.
If no NFC P2P enabled device can be found or if there is an error during discovery the P2P state will change to P2PDiscoveryError. In this case you have to restart the discovery process.
If the P2P state changes to P2PDiscoveryReady you can start the NDEF message
transfer with P2PStartTransfer.
| Parameters: |
|
|---|
Writes the NDEF message that is to be transferred to the NFC peer.
The maximum supported NDEF message size for P2P transfer is 255 byte.
You can call this function at any time in P2P mode. The internal buffer will not be overwritten until you call this function again, change the mode or use P2P to read an NDEF messages.
| Parameters: |
|
|---|
You can start the transfer of a NDEF message if the P2P state is P2PDiscoveryReady.
Before you call this function to start a write transfer, the NDEF message that
is to be transferred has to be written via P2PWriteNDEF first.
After you call this function the P2P state will change to P2PTransferNDEF. It will change to P2PTransferNDEFReady if the transfer was successfull or P2PTransferNDEFError if it wasn't.
If you started a write transfer you are now done. If you started a read transfer
you can now use P2PReadNDEF to read the NDEF message that was written
by the NFC peer.
The following constants are available for this function:
For transfer:
BRICKLET_NFC_P2P_TRANSFER_ABORT = 0
BRICKLET_NFC_P2P_TRANSFER_WRITE = 1
BRICKLET_NFC_P2P_TRANSFER_READ = 2
| Returns: |
|
|---|
Returns the NDEF message that was written by a NFC peer in NFC P2P mode.
The NDEF message is ready if you called P2PStartTransfer with a
read transfer and the P2P state changed to P2PTransferNDEFReady.
| Parameters: |
|
|---|---|
| Output Parameters: |
|
Returns the tag type and tag ID from simple mode sorted by last seen time for a given index.
Up to eight tags are saved.
The following constants are available for this function:
For tagType:
BRICKLET_NFC_TAG_TYPE_MIFARE_CLASSIC = 0
BRICKLET_NFC_TAG_TYPE_TYPE1 = 1
BRICKLET_NFC_TAG_TYPE_TYPE2 = 2
BRICKLET_NFC_TAG_TYPE_TYPE3 = 3
BRICKLET_NFC_TAG_TYPE_TYPE4 = 4
BRICKLET_NFC_TAG_TYPE_TYPE5 = 5
Added in version 2.0.6$nbsp;(Plugin).
| Parameters: |
|
|---|
Sets the tag ID for cardemu mode. The tag ID can either have a length of 4 or 7.
Set a length of 0 for random tag ID (default)
Added in version 2.1.0$nbsp;(Plugin).
| Output Parameters: |
|
|---|
Returns the tag ID and length as set by CardemuSetTagID.
Added in version 2.1.0$nbsp;(Plugin).
| Parameters: |
|
|---|
Sets the detection LED configuration. By default the LED shows if a card/reader is detected.
You can also turn the LED permanently on/off or show a heartbeat.
If the Bricklet is in bootloader mode, the LED is off.
The following constants are available for this function:
For config:
BRICKLET_NFC_DETECTION_LED_CONFIG_OFF = 0
BRICKLET_NFC_DETECTION_LED_CONFIG_ON = 1
BRICKLET_NFC_DETECTION_LED_CONFIG_SHOW_HEARTBEAT = 2
BRICKLET_NFC_DETECTION_LED_CONFIG_SHOW_DETECTION = 3
| Returns: |
|
|---|
Returns the configuration as set by SetDetectionLEDConfig
The following constants are available for this function:
For config:
BRICKLET_NFC_DETECTION_LED_CONFIG_OFF = 0
BRICKLET_NFC_DETECTION_LED_CONFIG_ON = 1
BRICKLET_NFC_DETECTION_LED_CONFIG_SHOW_HEARTBEAT = 2
BRICKLET_NFC_DETECTION_LED_CONFIG_SHOW_DETECTION = 3
| Parameters: |
|
|---|
Sets the maximum timeout.
This is a global maximum used for all internal state timeouts. The timeouts depend heavily
on the used tags etc. For example: If you use a Type 2 tag and you want to detect if
it is present, you have to use ReaderRequestTagID and wait for the state
to change to either the error state or the ready state.
With the default configuration this takes 2-3 seconds. By setting the maximum timeout to 100ms you can reduce this time to ~150-200ms. For Type 2 this would also still work with a 20ms timeout (a Type 2 tag answers usually within 10ms). A type 4 tag can take up to 500ms in our tests.
If you need a fast response time to discover if a tag is present or not you can find a good timeout value by trial and error for your specific tag.
By default we use a very conservative timeout, to be sure that any tag can always answer in time.
Added in version 2.0.1$nbsp;(Plugin).
| Returns: |
|
|---|
Returns the timeout as set by SetMaximumTimeout
Added in version 2.0.1$nbsp;(Plugin).
| Output Parameters: |
|
|---|
Returns the error count for the communication between Brick and Bricklet.
The errors are divided into
ACK checksum errors,
message checksum errors,
framing errors and
overflow errors.
The errors counts are for errors that occur on the Bricklet side. All Bricks have a similar function that returns the errors on the Brick side.
| Parameters: |
|
|---|
Sets the status LED configuration. By default the LED shows communication traffic between Brick and Bricklet, it flickers once for every 10 received data packets.
You can also turn the LED permanently on/off or show a heartbeat.
If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
The following constants are available for this function:
For config:
BRICKLET_NFC_STATUS_LED_CONFIG_OFF = 0
BRICKLET_NFC_STATUS_LED_CONFIG_ON = 1
BRICKLET_NFC_STATUS_LED_CONFIG_SHOW_HEARTBEAT = 2
BRICKLET_NFC_STATUS_LED_CONFIG_SHOW_STATUS = 3
| Returns: |
|
|---|
Returns the configuration as set by SetStatusLEDConfig
The following constants are available for this function:
For config:
BRICKLET_NFC_STATUS_LED_CONFIG_OFF = 0
BRICKLET_NFC_STATUS_LED_CONFIG_ON = 1
BRICKLET_NFC_STATUS_LED_CONFIG_SHOW_HEARTBEAT = 2
BRICKLET_NFC_STATUS_LED_CONFIG_SHOW_STATUS = 3
| Returns: |
|
|---|
Returns the temperature as measured inside the microcontroller. The value returned is not the ambient temperature!
The temperature is only proportional to the real temperature and it has bad accuracy. Practically it is only useful as an indicator for temperature changes.
Calling this function will reset the Bricklet. All configurations will be lost.
After a reset you have to create new device objects, calling functions on the existing ones will result in undefined behavior!
| Output Parameters: |
|
|---|
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.
The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an Isolator Bricklet is always at position 'z'.
The device identifier numbers can be found here. There is also a constant for the device identifier of this Bricklet.
Callbacks can be registered to receive time critical or recurring data from the device. The registration is done by assigning a procedure to an callback property of the device object:
procedure TExample.MyCallback(sender: TBrickletNFC; const value: longint); begin WriteLn(Format('Value: %d', [value])); end; nfc.OnExample := {$ifdef FPC}@{$endif}example.MyCallback;
The available callback properties and their parameter types are described below.
Note
Using callbacks for recurring events is always preferred compared to using getters. It will use less USB bandwidth and the latency will be a lot better, since there is no round trip time.
procedure(sender: TBrickletNFC; const state: byte; const idle: boolean) of object;
| Callback Parameters: |
|
|---|
This callback is called if the reader state of the NFC Bricklet changes.
See ReaderGetState for more information about the possible states.
The following constants are available for this function:
For state:
BRICKLET_NFC_READER_STATE_INITIALIZATION = 0
BRICKLET_NFC_READER_STATE_IDLE = 128
BRICKLET_NFC_READER_STATE_ERROR = 192
BRICKLET_NFC_READER_STATE_REQUEST_TAG_ID = 2
BRICKLET_NFC_READER_STATE_REQUEST_TAG_ID_READY = 130
BRICKLET_NFC_READER_STATE_REQUEST_TAG_ID_ERROR = 194
BRICKLET_NFC_READER_STATE_AUTHENTICATE_MIFARE_CLASSIC_PAGE = 3
BRICKLET_NFC_READER_STATE_AUTHENTICATE_MIFARE_CLASSIC_PAGE_READY = 131
BRICKLET_NFC_READER_STATE_AUTHENTICATE_MIFARE_CLASSIC_PAGE_ERROR = 195
BRICKLET_NFC_READER_STATE_WRITE_PAGE = 4
BRICKLET_NFC_READER_STATE_WRITE_PAGE_READY = 132
BRICKLET_NFC_READER_STATE_WRITE_PAGE_ERROR = 196
BRICKLET_NFC_READER_STATE_REQUEST_PAGE = 5
BRICKLET_NFC_READER_STATE_REQUEST_PAGE_READY = 133
BRICKLET_NFC_READER_STATE_REQUEST_PAGE_ERROR = 197
BRICKLET_NFC_READER_STATE_WRITE_NDEF = 6
BRICKLET_NFC_READER_STATE_WRITE_NDEF_READY = 134
BRICKLET_NFC_READER_STATE_WRITE_NDEF_ERROR = 198
BRICKLET_NFC_READER_STATE_REQUEST_NDEF = 7
BRICKLET_NFC_READER_STATE_REQUEST_NDEF_READY = 135
BRICKLET_NFC_READER_STATE_REQUEST_NDEF_ERROR = 199
procedure(sender: TBrickletNFC; const state: byte; const idle: boolean) of object;
| Callback Parameters: |
|
|---|
This callback is called if the cardemu state of the NFC Bricklet changes.
See CardemuGetState for more information about the possible states.
The following constants are available for this function:
For state:
BRICKLET_NFC_CARDEMU_STATE_INITIALIZATION = 0
BRICKLET_NFC_CARDEMU_STATE_IDLE = 128
BRICKLET_NFC_CARDEMU_STATE_ERROR = 192
BRICKLET_NFC_CARDEMU_STATE_DISCOVER = 2
BRICKLET_NFC_CARDEMU_STATE_DISCOVER_READY = 130
BRICKLET_NFC_CARDEMU_STATE_DISCOVER_ERROR = 194
BRICKLET_NFC_CARDEMU_STATE_TRANSFER_NDEF = 3
BRICKLET_NFC_CARDEMU_STATE_TRANSFER_NDEF_READY = 131
BRICKLET_NFC_CARDEMU_STATE_TRANSFER_NDEF_ERROR = 195
procedure(sender: TBrickletNFC; const state: byte; const idle: boolean) of object;
| Callback Parameters: |
|
|---|
This callback is called if the P2P state of the NFC Bricklet changes.
See P2PGetState for more information about the possible states.
The following constants are available for this function:
For state:
BRICKLET_NFC_P2P_STATE_INITIALIZATION = 0
BRICKLET_NFC_P2P_STATE_IDLE = 128
BRICKLET_NFC_P2P_STATE_ERROR = 192
BRICKLET_NFC_P2P_STATE_DISCOVER = 2
BRICKLET_NFC_P2P_STATE_DISCOVER_READY = 130
BRICKLET_NFC_P2P_STATE_DISCOVER_ERROR = 194
BRICKLET_NFC_P2P_STATE_TRANSFER_NDEF = 3
BRICKLET_NFC_P2P_STATE_TRANSFER_NDEF_READY = 131
BRICKLET_NFC_P2P_STATE_TRANSFER_NDEF_ERROR = 195
Virtual functions don't communicate with the device itself, but operate only on the API bindings device object. They can be called without the corresponding IP Connection object being connected.
| Output Parameters: |
|
|---|
Returns the version of the API definition implemented by this API bindings. This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
| Parameters: |
|
|---|---|
| Returns: |
|
Returns the response expected flag for the function specified by the function ID parameter. It is true if the function is expected to send a response, false otherwise.
For getter functions this is enabled by default and cannot be disabled,
because those functions will always send a response. For callback configuration
functions it is enabled by default too, but can be disabled by
SetResponseExpected. For setter functions it is disabled by default
and can be enabled.
Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is sent and errors are silently ignored, because they cannot be detected.
The following constants are available for this function:
For functionId:
BRICKLET_NFC_FUNCTION_SET_MODE = 1
BRICKLET_NFC_FUNCTION_READER_REQUEST_TAG_ID = 3
BRICKLET_NFC_FUNCTION_READER_WRITE_NDEF = 6
BRICKLET_NFC_FUNCTION_READER_REQUEST_NDEF = 7
BRICKLET_NFC_FUNCTION_READER_AUTHENTICATE_MIFARE_CLASSIC_PAGE = 9
BRICKLET_NFC_FUNCTION_READER_WRITE_PAGE = 10
BRICKLET_NFC_FUNCTION_READER_REQUEST_PAGE = 11
BRICKLET_NFC_FUNCTION_CARDEMU_START_DISCOVERY = 15
BRICKLET_NFC_FUNCTION_CARDEMU_WRITE_NDEF = 16
BRICKLET_NFC_FUNCTION_CARDEMU_START_TRANSFER = 17
BRICKLET_NFC_FUNCTION_P2P_START_DISCOVERY = 20
BRICKLET_NFC_FUNCTION_P2P_WRITE_NDEF = 21
BRICKLET_NFC_FUNCTION_P2P_START_TRANSFER = 22
BRICKLET_NFC_FUNCTION_SET_DETECTION_LED_CONFIG = 25
BRICKLET_NFC_FUNCTION_SET_MAXIMUM_TIMEOUT = 27
BRICKLET_NFC_FUNCTION_CARDEMU_SET_TAG_ID = 30
BRICKLET_NFC_FUNCTION_SET_WRITE_FIRMWARE_POINTER = 237
BRICKLET_NFC_FUNCTION_SET_STATUS_LED_CONFIG = 239
BRICKLET_NFC_FUNCTION_RESET = 243
BRICKLET_NFC_FUNCTION_WRITE_UID = 248
| Parameters: |
|
|---|
Changes the response expected flag of the function specified by the function ID parameter. This flag can only be changed for setter (default value: false) and callback configuration functions (default value: true). For getter functions it is always enabled.
Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is sent and errors are silently ignored, because they cannot be detected.
The following constants are available for this function:
For functionId:
BRICKLET_NFC_FUNCTION_SET_MODE = 1
BRICKLET_NFC_FUNCTION_READER_REQUEST_TAG_ID = 3
BRICKLET_NFC_FUNCTION_READER_WRITE_NDEF = 6
BRICKLET_NFC_FUNCTION_READER_REQUEST_NDEF = 7
BRICKLET_NFC_FUNCTION_READER_AUTHENTICATE_MIFARE_CLASSIC_PAGE = 9
BRICKLET_NFC_FUNCTION_READER_WRITE_PAGE = 10
BRICKLET_NFC_FUNCTION_READER_REQUEST_PAGE = 11
BRICKLET_NFC_FUNCTION_CARDEMU_START_DISCOVERY = 15
BRICKLET_NFC_FUNCTION_CARDEMU_WRITE_NDEF = 16
BRICKLET_NFC_FUNCTION_CARDEMU_START_TRANSFER = 17
BRICKLET_NFC_FUNCTION_P2P_START_DISCOVERY = 20
BRICKLET_NFC_FUNCTION_P2P_WRITE_NDEF = 21
BRICKLET_NFC_FUNCTION_P2P_START_TRANSFER = 22
BRICKLET_NFC_FUNCTION_SET_DETECTION_LED_CONFIG = 25
BRICKLET_NFC_FUNCTION_SET_MAXIMUM_TIMEOUT = 27
BRICKLET_NFC_FUNCTION_CARDEMU_SET_TAG_ID = 30
BRICKLET_NFC_FUNCTION_SET_WRITE_FIRMWARE_POINTER = 237
BRICKLET_NFC_FUNCTION_SET_STATUS_LED_CONFIG = 239
BRICKLET_NFC_FUNCTION_RESET = 243
BRICKLET_NFC_FUNCTION_WRITE_UID = 248
| Parameters: |
|
|---|
Changes the response expected flag for all setter and callback configuration functions of this device at once.
Internal functions are used for maintenance tasks such as flashing a new firmware of changing the UID of a Bricklet. These task should be performed using Brick Viewer instead of using the internal functions directly.
| Parameters: |
|
|---|---|
| Returns: |
|
Sets the bootloader mode and returns the status after the requested mode change was instigated.
You can change from bootloader mode to firmware mode and vice versa. A change from bootloader mode to firmware mode will only take place if the entry function, device identifier and CRC are present and correct.
This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.
The following constants are available for this function:
For mode:
BRICKLET_NFC_BOOTLOADER_MODE_BOOTLOADER = 0
BRICKLET_NFC_BOOTLOADER_MODE_FIRMWARE = 1
BRICKLET_NFC_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT = 2
BRICKLET_NFC_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT = 3
BRICKLET_NFC_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT = 4
For status:
BRICKLET_NFC_BOOTLOADER_STATUS_OK = 0
BRICKLET_NFC_BOOTLOADER_STATUS_INVALID_MODE = 1
BRICKLET_NFC_BOOTLOADER_STATUS_NO_CHANGE = 2
BRICKLET_NFC_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT = 3
BRICKLET_NFC_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT = 4
BRICKLET_NFC_BOOTLOADER_STATUS_CRC_MISMATCH = 5
| Returns: |
|
|---|
Returns the current bootloader mode, see SetBootloaderMode.
The following constants are available for this function:
For mode:
BRICKLET_NFC_BOOTLOADER_MODE_BOOTLOADER = 0
BRICKLET_NFC_BOOTLOADER_MODE_FIRMWARE = 1
BRICKLET_NFC_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT = 2
BRICKLET_NFC_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT = 3
BRICKLET_NFC_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT = 4
| Parameters: |
|
|---|
Sets the firmware pointer for WriteFirmware. The pointer has
to be increased by chunks of size 64. The data is written to flash
every 4 chunks (which equals to one page of size 256).
This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.
| Parameters: |
|
|---|---|
| Returns: |
|
Writes 64 Bytes of firmware at the position as written by
SetWriteFirmwarePointer before. The firmware is written
to flash every 4 chunks.
You can only write firmware in bootloader mode.
This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.
| Parameters: |
|
|---|
Writes a new UID into flash. If you want to set a new UID you have to decode the Base58 encoded UID string into an integer first.
We recommend that you use Brick Viewer to change the UID.
| Returns: |
|
|---|
Returns the current UID as an integer. Encode as Base58 to get the usual string version.
This constant is used to identify a NFC Bricklet.
The GetIdentity function and the
TIPConnection.OnEnumerate
callback of the IP Connection have a deviceIdentifier parameter to specify
the Brick's or Bricklet's type.
This constant represents the human readable name of a NFC Bricklet.