This is the description of the MATLAB/Octave 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 MATLAB/Octave API bindings is part of their general description.
The example code below is Public Domain (CC0 1.0).
Download (matlab_example_scan_for_tags.m)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | function matlab_example_scan_for_tags()
global nfc;
import com.tinkerforge.IPConnection;
import com.tinkerforge.BrickletNFC;
HOST = 'localhost';
PORT = 4223;
UID = 'XYZ'; % Change XYZ to the UID of your NFC Bricklet
ipcon = IPConnection(); % Create IP connection
nfc = handle(BrickletNFC(UID, ipcon), 'CallbackProperties'); % Create device object
ipcon.connect(HOST, PORT); % Connect to brickd
% Don't use device before ipcon is connected
% Register reader state changed callback to function cb_reader_state_changed
set(nfc, 'ReaderStateChangedCallback', @(h, e) cb_reader_state_changed(e));
% Enable reader mode
nfc.setMode(BrickletNFC.MODE_READER);
input('Press key to exit\n', 's');
ipcon.disconnect();
end
% Callback function for reader state changed callback
function cb_reader_state_changed(e)
import com.tinkerforge.BrickletNFC;
global nfc;
if e.state == BrickletNFC.READER_STATE_IDLE
nfc.readerRequestTagID();
elseif e.state == BrickletNFC.READER_STATE_REQUEST_TAG_ID_READY
tag = '';
ret = nfc.readerGetTagID();
for i = 1:length(ret.tagID)
tmp_tag = sprintf('0x%x', ret.tagID(i));
if i < length(ret.tagID)
tmp_tag = strcat(tmp_tag, " ");
end
tag = strcat(tag, tmp_tag);
end
fprintf('Found tag of type %d with ID [%s]\n', ret.tagType, tag);
elseif e.state == BrickletNFC.READER_STATE_REQUEST_TAG_ID_ERROR
disp('Request tag ID error');
end
end
|
Download (matlab_example_emulate_ndef.m)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | function matlab_example_emulate_ndef()
global nfc;
global NDEF_URI;
import com.tinkerforge.IPConnection;
import com.tinkerforge.BrickletNFC;
HOST = 'localhost';
PORT = 4223;
UID = 'XYZ'; % Change XYZ to the UID of your NFC Bricklet
NDEF_URI = 'www.tinkerforge.com';
ipcon = IPConnection(); % Create IP connection
nfc = handle(BrickletNFC(UID, ipcon), 'CallbackProperties'); % Create device object
ipcon.connect(HOST, PORT); % Connect to brickd
% Don't use device before ipcon is connected
% Register cardemu state changed callback to function cb_cardemu_state_changed
set(nfc, 'CardemuStateChangedCallback', @(h, e) cb_cardemu_state_changed(e));
% Enable cardemu mode
nfc.setMode(BrickletNFC.MODE_CARDEMU);
input('Press key to exit\n', 's');
ipcon.disconnect();
end
% Callback function for cardemu state changed callback
function cb_cardemu_state_changed(e)
import com.tinkerforge.BrickletNFC;
global nfc;
global NDEF_URI;
if e.state == BrickletNFC.CARDEMU_STATE_IDLE
ndef_record_uri = [];
% Only short records are supported
ndef_record_uri(1) = hex2dec('D1'); % MB/ME/CF/SR=1/IL/TNF
ndef_record_uri(2) = hex2dec('01'); % TYPE LENGTH
ndef_record_uri(3) = length(NDEF_URI) + 1; % Length
ndef_record_uri(4) = double('U'); % Type
ndef_record_uri(5) = hex2dec('04'); % Status
for i = 1:length(NDEF_URI)
ndef_record_uri(5 + i) = double(NDEF_URI(i));
end
nfc.cardemuWriteNDEF(ndef_record_uri);
nfc.cardemuStartDiscovery();
elseif e.state == BrickletNFC.CARDEMU_STATE_DISCOVER_READY
nfc.cardemuStartTransfer(BrickletNFC.CARDEMU_TRANSFER_WRITE);
elseif e.state == BrickletNFC.CARDEMU_STATE_DISCOVER_ERROR
disp('Discover error');
elseif e.state == BrickletNFC.CARDEMU_STATE_TRANSFER_NDEF_ERROR
disp('Transfer NDEF error');
end
end
|
Download (matlab_example_write_read_type2.m)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | function matlab_example_write_read_type2()
global nfc;
import com.tinkerforge.IPConnection;
import com.tinkerforge.BrickletNFC;
HOST = 'localhost';
PORT = 4223;
UID = 'XYZ'; % Change XYZ to the UID of your NFC Bricklet
ipcon = IPConnection(); % Create IP connection
nfc = handle(BrickletNFC(UID, ipcon), 'CallbackProperties'); % Create device object
ipcon.connect(HOST, PORT); % Connect to brickd
% Don't use device before ipcon is connected
% Register reader state changed callback to function cb_reader_state_changed
set(nfc, 'ReaderStateChangedCallback', @(h, e) cb_reader_state_changed(e));
% Enable reader mode
nfc.setMode(BrickletNFC.MODE_READER);
input('Press key to exit\n', 's');
ipcon.disconnect();
end
% Callback function for reader state changed callback
function cb_reader_state_changed(e)
import com.tinkerforge.BrickletNFC;
global nfc;
if e.state == BrickletNFC.READER_STATE_IDLE
nfc.readerRequestTagID();
elseif e.state == BrickletNFC.READER_STATE_REQUEST_TAG_ID_READY
ret = nfc.readerGetTagID();
if ret.tagType ~= BrickletNFC.TAG_TYPE_TYPE2
disp('Tag is not type-2');
return;
end
fprintf('Found tag of type %d with ID [0x%X 0x%X 0x%X 0x%X]\n', ...
ret.tagType, ...
ret.tagID(1), ...
ret.tagID(2), ...
ret.tagID(3), ...
ret.tagID(4));
nfc.readerRequestPage(1, 4);
elseif e.state == BrickletNFC.READER_STATE_REQUEST_TAG_ID_ERROR
disp('Request tag ID error');
elseif e.state == BrickletNFC.READER_STATE_REQUEST_PAGE_READY
page = nfc.readerReadPage();
fprintf('Page read: 0x%X 0x%X 0x%X 0x%X\n', ...
page(1), ...
page(2), ...
page(3), ...
page(4));
nfc.readerWritePage(1, page);
elseif e.state == BrickletNFC.READER_STATE_WRITE_PAGE_READY
disp('Write page ready');
elseif e.state == BrickletNFC.READER_STATE_REQUEST_PAGE_ERROR
disp('Request page error');
elseif e.state == BrickletNFC.READER_STATE_WRITE_PAGE_ERROR
disp('Write page error');
end
end
|
Download (octave_example_scan_for_tags.m)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | function octave_example_scan_for_tags()
more off;
global nfc;
HOST = "localhost";
PORT = 4223;
UID = "XYZ"; % Change XYZ to the UID of your NFC Bricklet
ipcon = javaObject("com.tinkerforge.IPConnection"); % Create IP connection
nfc = javaObject("com.tinkerforge.BrickletNFC", UID, ipcon); % Create device object
ipcon.connect(HOST, PORT); % Connect to brickd
% Don't use device before ipcon is connected
% Register reader state changed callback to function cb_reader_state_changed
nfc.addReaderStateChangedCallback(@cb_reader_state_changed);
% Enable reader mode
nfc.setMode(nfc.MODE_READER);
input("Press key to exit\n", "s");
ipcon.disconnect();
end
% Callback function for reader state changed callback
function cb_reader_state_changed(e)
global nfc;
if e.state == nfc.READER_STATE_IDLE
nfc.readerRequestTagID();
elseif e.state == nfc.READER_STATE_REQUEST_TAG_ID_READY
tag = "";
ret = nfc.readerGetTagID();
for i = 1:length(java_get(ret, "tagID"))
tmp_tag = sprintf("0x%X", java_get(ret, "tagID")(i));
if i < length(java_get(ret, "tagID"))
tmp_tag = cstrcat(tmp_tag, " ");
end
tag = cstrcat(tag, tmp_tag);
end
fprintf("Found tag of type %d with ID [%s]\n", java_get(ret, "tagType"), tag);
elseif e.state == nfc.READER_STATE_REQUEST_TAG_ID_ERROR
disp("Request tag ID error");
end
end
|
Download (octave_example_emulate_ndef.m)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | function octave_example_emulate_ndef()
more off;
global nfc;
global NDEF_URI;
HOST = "localhost";
PORT = 4223;
UID = "XYZ"; % Change XYZ to the UID of your NFC Bricklet
NDEF_URI = "www.tinkerforge.com";
ipcon = javaObject("com.tinkerforge.IPConnection"); % Create IP connection
nfc = javaObject("com.tinkerforge.BrickletNFC", UID, ipcon); % Create device object
ipcon.connect(HOST, PORT); % Connect to brickd
% Don't use device before ipcon is connected
% Register cardemu state changed callback to function cb_cardemu_state_changed
nfc.addCardemuStateChangedCallback(@cb_cardemu_state_changed);
% Enable cardemu mode
nfc.setMode(nfc.MODE_CARDEMU);
input("Press key to exit\n", "s");
ipcon.disconnect();
end
% Callback function for cardemu state changed callback
function cb_cardemu_state_changed(e)
global nfc;
global NDEF_URI;
if e.state == nfc.CARDEMU_STATE_IDLE
ndef_record_uri = [];
% Only short records are supported
ndef_record_uri(1) = hex2dec('D1'); % MB/ME/CF/SR=1/IL/TNF
ndef_record_uri(2) = hex2dec('01'); % TYPE LENGTH
ndef_record_uri(3) = length(NDEF_URI) + 1; % Length
ndef_record_uri(4) = double('U'); % Type
ndef_record_uri(5) = hex2dec('04'); % Status
for i = 1:length(NDEF_URI)
ndef_record_uri(5 + i) = double(NDEF_URI(i));
end
nfc.cardemuWriteNDEF(ndef_record_uri);
nfc.cardemuStartDiscovery();
elseif e.state == nfc.CARDEMU_STATE_DISCOVER_READY
nfc.cardemuStartTransfer(nfc.CARDEMU_TRANSFER_WRITE);
elseif e.state == nfc.CARDEMU_STATE_DISCOVER_ERROR
disp("Discover error");
elseif e.state == nfc.CARDEMU_STATE_TRANSFER_NDEF_ERROR
disp("Transfer NDEF error");
end
end
|
Download (octave_example_write_read_type2.m)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | function octave_example_write_read_type2()
more off;
global nfc;
HOST = "localhost";
PORT = 4223;
UID = "XYZ"; % Change XYZ to the UID of your NFC Bricklet
ipcon = javaObject("com.tinkerforge.IPConnection"); % Create IP connection
nfc = javaObject("com.tinkerforge.BrickletNFC", UID, ipcon); % Create device object
ipcon.connect(HOST, PORT); % Connect to brickd
% Don't use device before ipcon is connected
% Register reader state changed callback to function cb_reader_state_changed
nfc.addReaderStateChangedCallback(@cb_reader_state_changed);
% Enable reader mode
nfc.setMode(nfc.MODE_READER);
input("Press key to exit\n", "s");
ipcon.disconnect();
end
% Callback function for reader state changed callback
function cb_reader_state_changed(e)
global nfc;
if e.state == nfc.READER_STATE_IDLE
nfc.readerRequestTagID();
elseif e.state == nfc.READER_STATE_REQUEST_TAG_ID_READY
ret = nfc.readerGetTagID();
if java_get(ret, "tagType") ~= nfc.TAG_TYPE_TYPE2
disp("Tag is not type-2");
return;
end
fprintf("Found tag of type %d with ID [0x%X 0x%X 0x%X 0x%X]\n", ...
java_get(ret, "tagType"), ...
java_get(ret, "tagID")(1), ...
java_get(ret, "tagID")(2), ...
java_get(ret, "tagID")(3), ...
java_get(ret, "tagID")(4));
nfc.readerRequestPage(1, 4);
elseif e.state == nfc.READER_STATE_REQUEST_TAG_ID_ERROR
disp("Request tag ID error");
elseif e.state == nfc.READER_STATE_REQUEST_PAGE_READY
page = nfc.readerReadPage();
fprintf("Page read: 0x%X 0x%X 0x%X 0x%X\n", ...
page(1), ...
page(2), ...
page(3), ...
page(4));
nfc.readerWritePage(1, page);
elseif e.state == nfc.READER_STATE_WRITE_PAGE_READY
disp("Write page ready");
elseif e.state == nfc.READER_STATE_REQUEST_PAGE_ERROR
disp("Request page error");
elseif e.state == nfc.READER_STATE_WRITE_PAGE_ERROR
disp("Write page error");
end
end
|
Generally, every method of the MATLAB bindings that returns a value can throw a TimeoutException. This exception gets thrown if the device did not respond. If a cable based connection is used, it is unlikely that this exception gets thrown (assuming nobody unplugs the device). However, if a wireless connection is used, timeouts will occur if the distance to the device gets too big.
Beside the TimeoutException there is also a NotConnectedException that is thrown if a method needs to communicate with the device while the IP Connection is not connected.
Since the MATLAB bindings are based on Java and Java does not support multiple return values and return by reference is not possible for primitive types, we use small classes that only consist of member variables. The member variables of the returned objects are described in the corresponding method descriptions.
The package for all Brick/Bricklet bindings and the IP Connection is com.tinkerforge.*
All methods listed below are thread-safe.
Parameters: |
|
---|---|
Returns: |
|
Creates an object with the unique device ID uid.
In MATLAB:
import com.tinkerforge.BrickletNFC;
nfc = BrickletNFC('YOUR_DEVICE_UID', ipcon);
In Octave:
nfc = java_new("com.tinkerforge.BrickletNFC", "YOUR_DEVICE_UID", ipcon);
This object can then be used after the IP Connection is connected (see examples above).
Parameters: |
|
---|
Sets the mode. The NFC Bricklet supports four modes:
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:
Returns: |
|
---|
Returns the mode as set by setMode().
The following constants are available for this function:
For mode:
To read or write a tag that is in proximity of the NFC Bricklet you first have to call this function with the expected tag type as parameter. It is no problem if you don't know the tag type. You can cycle through the available tag types until the tag answers the request.
Currently the following tag types are supported:
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 ReaderStateChangedCallback 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().
Return Object: |
|
---|
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:
The following constants are available for this function:
For tagType:
Return Object: |
|
---|
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:
Parameters: |
|
---|
Writes NDEF formated data.
This function currently supports NFC Forum Type 2 and 4.
The general approach for writing a NDEF message is as follows:
Reads NDEF formated data from a tag.
This function currently supports NFC Forum Type 1, 2, 3 and 4.
The general approach for reading a NDEF message is as follows:
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:
The authentication will always work for one whole sector (4 pages).
The following constants are available for this function:
For keyNumber:
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:
The general approach for writing to a tag is as follows:
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:
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:
The general approach for reading a tag is as follows:
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:
Returns: |
|
---|
Returns the page data from an internal buffer. To fill the buffer with specific pages you have to call readerRequestPage() beforehand.
Return Object: |
|
---|
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:
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 messages 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:
Return Object: |
|
---|
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:
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 messages 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:
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: |
|
---|
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:
Returns: |
|
---|
Returns the configuration as set by setDetectionLEDConfig()
The following constants are available for this function:
For config:
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.
New in version 2.0.1 (Plugin).
Returns: |
|
---|
Returns the timeout as set by setMaximumTimeout()
New in version 2.0.1 (Plugin).
Return Object: |
|
---|
Returns the error count for the communication between Brick and Bricklet.
The errors are divided into
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: |
|
---|---|
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:
For status:
Returns: |
|
---|
Returns the current bootloader mode, see setBootloaderMode().
The following constants are available for this function:
For mode:
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: |
|
---|
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:
Returns: |
|
---|
Returns the configuration as set by setStatusLEDConfig()
The following constants are available for this function:
For config:
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!
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.
Return Object: |
|
---|
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). The Raspberry Pi HAT (Zero) Brick is always at position 'i' and the Bricklet connected to an Isolator Bricklet is always as 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 with "set" function of MATLAB. The parameters consist of the IP Connection object, the callback name and the callback function. For example, it looks like this in MATLAB:
function my_callback(e)
fprintf('Parameter: %s\n', e.param);
end
set(device, 'ExampleCallback', @(h, e) my_callback(e));
Due to a difference in the Octave Java support the "set" function cannot be used in Octave. The registration is done with "add*Callback" functions of the device object. It looks like this in Octave:
function my_callback(e)
fprintf("Parameter: %s\n", e.param);
end
device.addExampleCallback(@my_callback);
It is possible to add several callbacks and to remove them with the corresponding "remove*Callback" function.
The parameters of the callback are passed to the callback function as fields of the structure e, which is derived from the java.util.EventObject class. The available callback names with corresponding structure fields 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.
Event Object: |
|
---|
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:
In MATLAB the set() function can be used to register a callback function to this callback.
In Octave a callback function can be added to this callback using the addReaderStateChangedCallback() function. An added callback function can be removed with the removeReaderStateChangedCallback() function.
Event Object: |
|
---|
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:
In MATLAB the set() function can be used to register a callback function to this callback.
In Octave a callback function can be added to this callback using the addCardemuStateChangedCallback() function. An added callback function can be removed with the removeCardemuStateChangedCallback() function.
Event Object: |
|
---|
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:
In MATLAB the set() function can be used to register a callback function to this callback.
In Octave a callback function can be added to this callback using the addP2PStateChangedCallback() function. An added callback function can be removed with the removeP2PStateChangedCallback() function.
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.
Return Object: |
|
---|
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 send and errors are silently ignored, because they cannot be detected.
The following constants are available for this function:
For functionId:
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 send and errors are silently ignored, because they cannot be detected.
The following constants are available for this function:
For functionId:
Parameters: |
|
---|
Changes the response expected flag for all setter and callback configuration functions of this device at once.
This constant is used to identify a NFC Bricklet.
The getIdentity() function and the IPConnection.EnumerateCallback 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.