Class: Tinkerforge::BrickletNFC
- Defined in:
- lib/tinkerforge/bricklet_nfc.rb
Overview
NFC tag read/write, NFC P2P and Card Emulation
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
286
- DEVICE_DISPLAY_NAME =
:nodoc:
'NFC Bricklet'
- CALLBACK_READER_STATE_CHANGED =
This callback is called if the reader state of the NFC Bricklet changes. See BrickletNFC#reader_get_state for more information about the possible states.
13
- CALLBACK_CARDEMU_STATE_CHANGED =
This callback is called if the cardemu state of the NFC Bricklet changes. See BrickletNFC#cardemu_get_state for more information about the possible states.
18
- CALLBACK_P2P_STATE_CHANGED =
This callback is called if the P2P state of the NFC Bricklet changes. See BrickletNFC#p2p_get_state for more information about the possible states.
24
- FUNCTION_SET_MODE =
:nodoc:
1
- FUNCTION_GET_MODE =
:nodoc:
2
- FUNCTION_READER_REQUEST_TAG_ID =
:nodoc:
3
- FUNCTION_READER_GET_TAG_ID_LOW_LEVEL =
:nodoc:
4
- FUNCTION_READER_GET_STATE =
:nodoc:
5
- FUNCTION_READER_WRITE_NDEF_LOW_LEVEL =
:nodoc:
6
- FUNCTION_READER_REQUEST_NDEF =
:nodoc:
7
- FUNCTION_READER_READ_NDEF_LOW_LEVEL =
:nodoc:
8
- FUNCTION_READER_AUTHENTICATE_MIFARE_CLASSIC_PAGE =
:nodoc:
9
- FUNCTION_READER_WRITE_PAGE_LOW_LEVEL =
:nodoc:
10
- FUNCTION_READER_REQUEST_PAGE =
:nodoc:
11
- FUNCTION_READER_READ_PAGE_LOW_LEVEL =
:nodoc:
12
- FUNCTION_CARDEMU_GET_STATE =
:nodoc:
14
- FUNCTION_CARDEMU_START_DISCOVERY =
:nodoc:
15
- FUNCTION_CARDEMU_WRITE_NDEF_LOW_LEVEL =
:nodoc:
16
- FUNCTION_CARDEMU_START_TRANSFER =
:nodoc:
17
- FUNCTION_P2P_GET_STATE =
:nodoc:
19
- FUNCTION_P2P_START_DISCOVERY =
:nodoc:
20
- FUNCTION_P2P_WRITE_NDEF_LOW_LEVEL =
:nodoc:
21
- FUNCTION_P2P_START_TRANSFER =
:nodoc:
22
- FUNCTION_P2P_READ_NDEF_LOW_LEVEL =
:nodoc:
23
- FUNCTION_SET_DETECTION_LED_CONFIG =
:nodoc:
25
- FUNCTION_GET_DETECTION_LED_CONFIG =
:nodoc:
26
- FUNCTION_SET_MAXIMUM_TIMEOUT =
:nodoc:
27
- FUNCTION_GET_MAXIMUM_TIMEOUT =
:nodoc:
28
- FUNCTION_GET_SPITFP_ERROR_COUNT =
:nodoc:
234
- FUNCTION_SET_BOOTLOADER_MODE =
:nodoc:
235
- FUNCTION_GET_BOOTLOADER_MODE =
:nodoc:
236
- FUNCTION_SET_WRITE_FIRMWARE_POINTER =
:nodoc:
237
- FUNCTION_WRITE_FIRMWARE =
:nodoc:
238
- FUNCTION_SET_STATUS_LED_CONFIG =
:nodoc:
239
- FUNCTION_GET_STATUS_LED_CONFIG =
:nodoc:
240
- FUNCTION_GET_CHIP_TEMPERATURE =
:nodoc:
242
- FUNCTION_RESET =
:nodoc:
243
- FUNCTION_WRITE_UID =
:nodoc:
248
- FUNCTION_READ_UID =
:nodoc:
249
- FUNCTION_GET_IDENTITY =
:nodoc:
255
- MODE_OFF =
:nodoc:
0
- MODE_CARDEMU =
:nodoc:
1
- MODE_P2P =
:nodoc:
2
- MODE_READER =
:nodoc:
3
- TAG_TYPE_MIFARE_CLASSIC =
:nodoc:
0
- TAG_TYPE_TYPE1 =
:nodoc:
1
- TAG_TYPE_TYPE2 =
:nodoc:
2
- TAG_TYPE_TYPE3 =
:nodoc:
3
- TAG_TYPE_TYPE4 =
:nodoc:
4
- READER_STATE_INITIALIZATION =
:nodoc:
0
- READER_STATE_IDLE =
:nodoc:
128
- READER_STATE_ERROR =
:nodoc:
192
- READER_STATE_REQUEST_TAG_ID =
:nodoc:
2
- READER_STATE_REQUEST_TAG_ID_READY =
:nodoc:
130
- READER_STATE_REQUEST_TAG_ID_ERROR =
:nodoc:
194
- READER_STATE_AUTHENTICATE_MIFARE_CLASSIC_PAGE =
:nodoc:
3
- READER_STATE_AUTHENTICATE_MIFARE_CLASSIC_PAGE_READY =
:nodoc:
131
- READER_STATE_AUTHENTICATE_MIFARE_CLASSIC_PAGE_ERROR =
:nodoc:
195
- READER_STATE_WRITE_PAGE =
:nodoc:
4
- READER_STATE_WRITE_PAGE_READY =
:nodoc:
132
- READER_STATE_WRITE_PAGE_ERROR =
:nodoc:
196
- READER_STATE_REQUEST_PAGE =
:nodoc:
5
- READER_STATE_REQUEST_PAGE_READY =
:nodoc:
133
- READER_STATE_REQUEST_PAGE_ERROR =
:nodoc:
197
- READER_STATE_WRITE_NDEF =
:nodoc:
6
- READER_STATE_WRITE_NDEF_READY =
:nodoc:
134
- READER_STATE_WRITE_NDEF_ERROR =
:nodoc:
198
- READER_STATE_REQUEST_NDEF =
:nodoc:
7
- READER_STATE_REQUEST_NDEF_READY =
:nodoc:
135
- READER_STATE_REQUEST_NDEF_ERROR =
:nodoc:
199
- KEY_A =
:nodoc:
0
- KEY_B =
:nodoc:
1
- READER_WRITE_TYPE4_CAPABILITY_CONTAINER =
:nodoc:
3
- READER_WRITE_TYPE4_NDEF =
:nodoc:
4
- READER_REQUEST_TYPE4_CAPABILITY_CONTAINER =
:nodoc:
3
- READER_REQUEST_TYPE4_NDEF =
:nodoc:
4
- CARDEMU_STATE_INITIALIZATION =
:nodoc:
0
- CARDEMU_STATE_IDLE =
:nodoc:
128
- CARDEMU_STATE_ERROR =
:nodoc:
192
- CARDEMU_STATE_DISCOVER =
:nodoc:
2
- CARDEMU_STATE_DISCOVER_READY =
:nodoc:
130
- CARDEMU_STATE_DISCOVER_ERROR =
:nodoc:
194
- CARDEMU_STATE_TRANSFER_NDEF =
:nodoc:
3
- CARDEMU_STATE_TRANSFER_NDEF_READY =
:nodoc:
131
- CARDEMU_STATE_TRANSFER_NDEF_ERROR =
:nodoc:
195
- CARDEMU_TRANSFER_ABORT =
:nodoc:
0
- CARDEMU_TRANSFER_WRITE =
:nodoc:
1
- P2P_STATE_INITIALIZATION =
:nodoc:
0
- P2P_STATE_IDLE =
:nodoc:
128
- P2P_STATE_ERROR =
:nodoc:
192
- P2P_STATE_DISCOVER =
:nodoc:
2
- P2P_STATE_DISCOVER_READY =
:nodoc:
130
- P2P_STATE_DISCOVER_ERROR =
:nodoc:
194
- P2P_STATE_TRANSFER_NDEF =
:nodoc:
3
- P2P_STATE_TRANSFER_NDEF_READY =
:nodoc:
131
- P2P_STATE_TRANSFER_NDEF_ERROR =
:nodoc:
195
- P2P_TRANSFER_ABORT =
:nodoc:
0
- P2P_TRANSFER_WRITE =
:nodoc:
1
- P2P_TRANSFER_READ =
:nodoc:
2
- DETECTION_LED_CONFIG_OFF =
:nodoc:
0
- DETECTION_LED_CONFIG_ON =
:nodoc:
1
- DETECTION_LED_CONFIG_SHOW_HEARTBEAT =
:nodoc:
2
- DETECTION_LED_CONFIG_SHOW_DETECTION =
:nodoc:
3
- BOOTLOADER_MODE_BOOTLOADER =
:nodoc:
0
- BOOTLOADER_MODE_FIRMWARE =
:nodoc:
1
- BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT =
:nodoc:
2
- BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT =
:nodoc:
3
- BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT =
:nodoc:
4
- BOOTLOADER_STATUS_OK =
:nodoc:
0
- BOOTLOADER_STATUS_INVALID_MODE =
:nodoc:
1
- BOOTLOADER_STATUS_NO_CHANGE =
:nodoc:
2
- BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT =
:nodoc:
3
- BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT =
:nodoc:
4
- BOOTLOADER_STATUS_CRC_MISMATCH =
:nodoc:
5
- STATUS_LED_CONFIG_OFF =
:nodoc:
0
- STATUS_LED_CONFIG_ON =
:nodoc:
1
- STATUS_LED_CONFIG_SHOW_HEARTBEAT =
:nodoc:
2
- STATUS_LED_CONFIG_SHOW_STATUS =
:nodoc:
3
Constants inherited from Device
Device::DEVICE_IDENTIFIER_CHECK_MATCH, Device::DEVICE_IDENTIFIER_CHECK_MISMATCH, Device::DEVICE_IDENTIFIER_CHECK_PENDING, Device::RESPONSE_EXPECTED_ALWAYS_TRUE, Device::RESPONSE_EXPECTED_FALSE, Device::RESPONSE_EXPECTED_INVALID_FUNCTION_ID, Device::RESPONSE_EXPECTED_TRUE
Instance Attribute Summary
Attributes inherited from Device
#callback_formats, #expected_response_function_id, #expected_response_sequence_number, #high_level_callbacks, #registered_callbacks, #replaced, #uid
Instance Method Summary collapse
-
#cardemu_get_state ⇒ Object
Returns the current cardemu state of the NFC Bricklet.
-
#cardemu_start_discovery ⇒ Object
Starts the discovery process.
-
#cardemu_start_transfer(transfer) ⇒ Object
You can start the transfer of a NDEF message if the cardemu state is CardemuDiscoveryReady.
-
#cardemu_write_ndef(ndef) ⇒ Object
Writes the NDEF message that is to be transferred to the NFC peer.
-
#cardemu_write_ndef_low_level(ndef_length, ndef_chunk_offset, ndef_chunk_data) ⇒ Object
Writes the NDEF message that is to be transferred to the NFC peer.
-
#get_bootloader_mode ⇒ Object
Returns the current bootloader mode, see BrickletNFC#set_bootloader_mode.
-
#get_chip_temperature ⇒ Object
Returns the temperature as measured inside the microcontroller.
-
#get_detection_led_config ⇒ Object
Returns the configuration as set by BrickletNFC#set_detection_led_config.
-
#get_identity ⇒ 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.
-
#get_maximum_timeout ⇒ Object
Returns the timeout as set by BrickletNFC#set_maximum_timeout.
-
#get_mode ⇒ Object
Returns the mode as set by BrickletNFC#set_mode.
-
#get_spitfp_error_count ⇒ Object
Returns the error count for the communication between Brick and Bricklet.
-
#get_status_led_config ⇒ Object
Returns the configuration as set by BrickletNFC#set_status_led_config.
-
#initialize(uid, ipcon) ⇒ BrickletNFC
constructor
Creates an object with the unique device ID
uid
and adds it to the IP Connectionipcon
. -
#p2p_get_state ⇒ Object
Returns the current P2P state of the NFC Bricklet.
-
#p2p_read_ndef ⇒ Object
Returns the NDEF message that was written by a NFC peer in NFC P2P mode.
-
#p2p_read_ndef_low_level ⇒ Object
Returns the NDEF message that was written by a NFC peer in NFC P2P mode.
-
#p2p_start_discovery ⇒ Object
Starts the discovery process.
-
#p2p_start_transfer(transfer) ⇒ Object
You can start the transfer of a NDEF message if the P2P state is P2PDiscoveryReady.
-
#p2p_write_ndef(ndef) ⇒ Object
Writes the NDEF message that is to be transferred to the NFC peer.
-
#p2p_write_ndef_low_level(ndef_length, ndef_chunk_offset, ndef_chunk_data) ⇒ Object
Writes the NDEF message that is to be transferred to the NFC peer.
-
#read_uid ⇒ Object
Returns the current UID as an integer.
-
#reader_authenticate_mifare_classic_page(page, key_number, key) ⇒ Object
Mifare Classic tags use authentication.
-
#reader_get_state ⇒ Object
Returns the current reader state of the NFC Bricklet.
-
#reader_get_tag_id ⇒ Object
Returns the tag type and the tag ID.
-
#reader_get_tag_id_low_level ⇒ Object
Returns the tag type and the tag ID.
-
#reader_read_ndef ⇒ Object
Returns the NDEF data from an internal buffer.
-
#reader_read_ndef_low_level ⇒ Object
Returns the NDEF data from an internal buffer.
-
#reader_read_page ⇒ Object
Returns the page data from an internal buffer.
-
#reader_read_page_low_level ⇒ Object
Returns the page data from an internal buffer.
-
#reader_request_ndef ⇒ Object
Reads NDEF formated data from a tag.
-
#reader_request_page(page, length) ⇒ Object
Reads a maximum of 8192 bytes starting from the given page and stores them into a buffer.
-
#reader_request_tag_id ⇒ Object
After you call BrickletNFC#reader_request_tag_id the NFC Bricklet will try to read the tag ID from the tag.
-
#reader_write_ndef(ndef) ⇒ Object
Writes NDEF formated data.
-
#reader_write_ndef_low_level(ndef_length, ndef_chunk_offset, ndef_chunk_data) ⇒ Object
Writes NDEF formated data.
-
#reader_write_page(page, data) ⇒ Object
Writes a maximum of 8192 bytes starting from the given page.
-
#reader_write_page_low_level(page, data_length, data_chunk_offset, data_chunk_data) ⇒ Object
Writes a maximum of 8192 bytes starting from the given page.
-
#register_callback(id, &block) ⇒ Object
Registers a callback with ID
id
to the blockblock
. -
#reset ⇒ Object
Calling this function will reset the Bricklet.
-
#set_bootloader_mode(mode) ⇒ Object
Sets the bootloader mode and returns the status after the requested mode change was instigated.
-
#set_detection_led_config(config) ⇒ Object
Sets the detection LED configuration.
-
#set_maximum_timeout(timeout) ⇒ Object
Sets the maximum timeout.
-
#set_mode(mode) ⇒ Object
Sets the mode.
-
#set_status_led_config(config) ⇒ Object
Sets the status LED configuration.
-
#set_write_firmware_pointer(pointer) ⇒ Object
Sets the firmware pointer for BrickletNFC#write_firmware.
-
#write_firmware(data) ⇒ Object
Writes 64 Bytes of firmware at the position as written by BrickletNFC#set_write_firmware_pointer before.
-
#write_uid(uid) ⇒ Object
Writes a new UID into flash.
Methods inherited from Device
#check_validity, #dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all
Constructor Details
#initialize(uid, ipcon) ⇒ BrickletNFC
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
Instance Method Details
#cardemu_get_state ⇒ 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 BrickletNFC#set_mode.
The functions of this Bricklet can be called in the CardemuIdle state and all of the CardemuReady and CardemuError states.
Example: If you call BrickletNFC#cardemu_start_discovery, 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.
453 454 455 456 457 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 453 def cardemu_get_state check_validity send_request FUNCTION_CARDEMU_GET_STATE, [], '', 10, 'C ?' end |
#cardemu_start_discovery ⇒ Object
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 BrickletNFC#cardemu_write_ndef and BrickletNFC#cardemu_start_transfer.
469 470 471 472 473 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 469 def cardemu_start_discovery check_validity send_request FUNCTION_CARDEMU_START_DISCOVERY, [], '', 8, '' end |
#cardemu_start_transfer(transfer) ⇒ Object
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 BrickletNFC#cardemu_write_ndef 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.
496 497 498 499 500 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 496 def cardemu_start_transfer(transfer) check_validity send_request FUNCTION_CARDEMU_START_TRANSFER, [transfer], 'C', 8, '' end |
#cardemu_write_ndef(ndef) ⇒ Object
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.
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 972 def cardemu_write_ndef(ndef) if ndef.length > 65535 raise ArgumentError, 'NDEF can be at most 65535 items long' end ndef_length = ndef.length ndef_chunk_offset = 0 if ndef_length == 0 ndef_chunk_data = [0] * 60 ret = cardemu_write_ndef_low_level ndef_length, ndef_chunk_offset, ndef_chunk_data else ret = nil # assigned in block @stream_mutex.synchronize { while ndef_chunk_offset < ndef_length ndef_chunk_data = ndef[ndef_chunk_offset, 60] if ndef_chunk_data.length < 60 ndef_chunk_data += [0] * (60 - ndef_chunk_data.length) end ret = cardemu_write_ndef_low_level ndef_length, ndef_chunk_offset, ndef_chunk_data ndef_chunk_offset += 60 end } end ret end |
#cardemu_write_ndef_low_level(ndef_length, ndef_chunk_offset, ndef_chunk_data) ⇒ Object
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.
482 483 484 485 486 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 482 def cardemu_write_ndef_low_level(ndef_length, ndef_chunk_offset, ndef_chunk_data) check_validity send_request FUNCTION_CARDEMU_WRITE_NDEF_LOW_LEVEL, [ndef_length, ndef_chunk_offset, ndef_chunk_data], 'S S C60', 8, '' end |
#get_bootloader_mode ⇒ Object
Returns the current bootloader mode, see BrickletNFC#set_bootloader_mode.
667 668 669 670 671 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 667 def get_bootloader_mode check_validity send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 9, 'C' end |
#get_chip_temperature ⇒ Object
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.
725 726 727 728 729 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 725 def get_chip_temperature check_validity send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's' end |
#get_detection_led_config ⇒ Object
Returns the configuration as set by BrickletNFC#set_detection_led_config
594 595 596 597 598 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 594 def get_detection_led_config check_validity send_request FUNCTION_GET_DETECTION_LED_CONFIG, [], '', 9, 'C' end |
#get_identity ⇒ 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). A Bricklet connected to an :ref:‘Isolator Bricklet <isolator_bricklet>` is always at position ’z’.
The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|
772 773 774 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 772 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end |
#get_maximum_timeout ⇒ Object
Returns the timeout as set by BrickletNFC#set_maximum_timeout
- .. versionadded
-
2.0.1$nbsp;(Plugin)
628 629 630 631 632 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 628 def get_maximum_timeout check_validity send_request FUNCTION_GET_MAXIMUM_TIMEOUT, [], '', 10, 'S' end |
#get_mode ⇒ Object
Returns the mode as set by BrickletNFC#set_mode.
218 219 220 221 222 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 218 def get_mode check_validity send_request FUNCTION_GET_MODE, [], '', 9, 'C' end |
#get_spitfp_error_count ⇒ Object
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.
645 646 647 648 649 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 645 def get_spitfp_error_count check_validity send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 24, 'L L L L' end |
#get_status_led_config ⇒ Object
Returns the configuration as set by BrickletNFC#set_status_led_config
713 714 715 716 717 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 713 def get_status_led_config check_validity send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C' end |
#p2p_get_state ⇒ 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 BrickletNFC#set_mode.
The functions of this Bricklet can be called in the P2PIdle state and all of the P2PReady and P2PError states.
Example: If you call BrickletNFC#p2p_start_discovery, 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.
518 519 520 521 522 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 518 def p2p_get_state check_validity send_request FUNCTION_P2P_GET_STATE, [], '', 10, 'C ?' end |
#p2p_read_ndef ⇒ Object
Returns the NDEF message that was written by a NFC peer in NFC P2P mode.
The NDEF message is ready if you called BrickletNFC#p2p_start_transfer with a read transfer and the P2P state changed to P2PTransferNDEFReady.
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 1045 def p2p_read_ndef ndef_length = nil # assigned in block ndef_data = nil # assigned in block @stream_mutex.synchronize { ret = p2p_read_ndef_low_level ndef_length = ret[0] ndef_chunk_offset = ret[1] ndef_out_of_sync = ndef_chunk_offset != 0 ndef_data = ret[2] while not ndef_out_of_sync and ndef_data.length < ndef_length ret = p2p_read_ndef_low_level ndef_length = ret[0] ndef_chunk_offset = ret[1] ndef_out_of_sync = ndef_chunk_offset != ndef_data.length ndef_data += ret[2] end if ndef_out_of_sync # discard remaining stream to bring it back in-sync while ndef_chunk_offset + 60 < ndef_length ret = p2p_read_ndef_low_level ndef_length = ret[0] ndef_chunk_offset = ret[1] end raise StreamOutOfSyncException, 'NDEF stream is out-of-sync' end } ndef_data[0, ndef_length] end |
#p2p_read_ndef_low_level ⇒ Object
Returns the NDEF message that was written by a NFC peer in NFC P2P mode.
The NDEF message is ready if you called BrickletNFC#p2p_start_transfer with a read transfer and the P2P state changed to P2PTransferNDEFReady.
575 576 577 578 579 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 575 def p2p_read_ndef_low_level check_validity send_request FUNCTION_P2P_READ_NDEF_LOW_LEVEL, [], '', 72, 'S S C60' end |
#p2p_start_discovery ⇒ Object
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 BrickletNFC#p2p_start_transfer.
534 535 536 537 538 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 534 def p2p_start_discovery check_validity send_request FUNCTION_P2P_START_DISCOVERY, [], '', 8, '' end |
#p2p_start_transfer(transfer) ⇒ Object
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 BrickletNFC#p2p_write_ndef 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 BrickletNFC#p2p_read_ndef to read the NDEF message that was written by the NFC peer.
565 566 567 568 569 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 565 def p2p_start_transfer(transfer) check_validity send_request FUNCTION_P2P_START_TRANSFER, [transfer], 'C', 8, '' end |
#p2p_write_ndef(ndef) ⇒ Object
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.
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 1010 def p2p_write_ndef(ndef) if ndef.length > 65535 raise ArgumentError, 'NDEF can be at most 65535 items long' end ndef_length = ndef.length ndef_chunk_offset = 0 if ndef_length == 0 ndef_chunk_data = [0] * 60 ret = p2p_write_ndef_low_level ndef_length, ndef_chunk_offset, ndef_chunk_data else ret = nil # assigned in block @stream_mutex.synchronize { while ndef_chunk_offset < ndef_length ndef_chunk_data = ndef[ndef_chunk_offset, 60] if ndef_chunk_data.length < 60 ndef_chunk_data += [0] * (60 - ndef_chunk_data.length) end ret = p2p_write_ndef_low_level ndef_length, ndef_chunk_offset, ndef_chunk_data ndef_chunk_offset += 60 end } end ret end |
#p2p_write_ndef_low_level(ndef_length, ndef_chunk_offset, ndef_chunk_data) ⇒ Object
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.
547 548 549 550 551 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 547 def p2p_write_ndef_low_level(ndef_length, ndef_chunk_offset, ndef_chunk_data) check_validity send_request FUNCTION_P2P_WRITE_NDEF_LOW_LEVEL, [ndef_length, ndef_chunk_offset, ndef_chunk_data], 'S S C60', 8, '' end |
#read_uid ⇒ Object
Returns the current UID as an integer. Encode as Base58 to get the usual string version.
756 757 758 759 760 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 756 def read_uid check_validity send_request FUNCTION_READ_UID, [], '', 12, 'L' end |
#reader_authenticate_mifare_classic_page(page, key_number, key) ⇒ Object
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 BrickletNFC#reader_request_tag_id
-
Wait for state to change to ReaderRequestTagIDReady (see BrickletNFC#reader_get_state or CALLBACK_READER_STATE_CHANGED callback)
-
If looking for a specific tag then call BrickletNFC#reader_get_tag_id and check if the expected tag was found, if it was not found got back to step 1
-
Call BrickletNFC#reader_authenticate_mifare_classic_page with page and key for the page
-
Wait for state to change to ReaderAuthenticatingMifareClassicPageReady (see BrickletNFC#reader_get_state or CALLBACK_READER_STATE_CHANGED callback)
-
Call BrickletNFC#reader_request_page or BrickletNFC#reader_write_page to read/write page
The authentication will always work for one whole sector (4 pages).
354 355 356 357 358 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 354 def reader_authenticate_mifare_classic_page(page, key_number, key) check_validity send_request FUNCTION_READER_AUTHENTICATE_MIFARE_CLASSIC_PAGE, [page, key_number, key], 'S C C6', 8, '' end |
#reader_get_state ⇒ 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 BrickletNFC#set_mode.
The functions of this Bricklet can be called in the ReaderIdle state and all of the ReaderReady and ReaderError states.
Example: If you call BrickletNFC#reader_request_page, 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 BrickletNFC#reader_read_page.
The same approach is used analogously for the other API functions.
279 280 281 282 283 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 279 def reader_get_state check_validity send_request FUNCTION_READER_GET_STATE, [], '', 10, 'C ?' end |
#reader_get_tag_id ⇒ 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 BrickletNFC#reader_request_tag_id.
To get the tag ID of a tag the approach is as follows:
-
Call BrickletNFC#reader_request_tag_id
-
Wait for state to change to ReaderRequestTagIDReady (see BrickletNFC#reader_get_state or CALLBACK_READER_STATE_CHANGED callback)
-
Call BrickletNFC#reader_get_tag_id
786 787 788 789 790 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 786 def reader_get_tag_id ret = reader_get_tag_id_low_level [ret[0], ret[2][0, ret[1]]] end |
#reader_get_tag_id_low_level ⇒ 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 BrickletNFC#reader_request_tag_id.
To get the tag ID of a tag the approach is as follows:
-
Call BrickletNFC#reader_request_tag_id
-
Wait for state to change to ReaderRequestTagIDReady (see BrickletNFC#reader_get_state or CALLBACK_READER_STATE_CHANGED callback)
-
Call BrickletNFC#reader_get_tag_id
257 258 259 260 261 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 257 def reader_get_tag_id_low_level check_validity send_request FUNCTION_READER_GET_TAG_ID_LOW_LEVEL, [], '', 42, 'C C C32' end |
#reader_read_ndef ⇒ Object
Returns the NDEF data from an internal buffer. To fill the buffer with a NDEF message you have to call BrickletNFC#reader_request_ndef beforehand.
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 839 def reader_read_ndef ndef_length = nil # assigned in block ndef_data = nil # assigned in block @stream_mutex.synchronize { ret = reader_read_ndef_low_level ndef_length = ret[0] ndef_chunk_offset = ret[1] ndef_out_of_sync = ndef_chunk_offset != 0 ndef_data = ret[2] while not ndef_out_of_sync and ndef_data.length < ndef_length ret = reader_read_ndef_low_level ndef_length = ret[0] ndef_chunk_offset = ret[1] ndef_out_of_sync = ndef_chunk_offset != ndef_data.length ndef_data += ret[2] end if ndef_out_of_sync # discard remaining stream to bring it back in-sync while ndef_chunk_offset + 60 < ndef_length ret = reader_read_ndef_low_level ndef_length = ret[0] ndef_chunk_offset = ret[1] end raise StreamOutOfSyncException, 'NDEF stream is out-of-sync' end } ndef_data[0, ndef_length] end |
#reader_read_ndef_low_level ⇒ Object
Returns the NDEF data from an internal buffer. To fill the buffer with a NDEF message you have to call BrickletNFC#reader_request_ndef beforehand.
328 329 330 331 332 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 328 def reader_read_ndef_low_level check_validity send_request FUNCTION_READER_READ_NDEF_LOW_LEVEL, [], '', 72, 'S S C60' end |
#reader_read_page ⇒ Object
Returns the page data from an internal buffer. To fill the buffer with specific pages you have to call BrickletNFC#reader_request_page beforehand.
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 932 def reader_read_page data_length = nil # assigned in block data_data = nil # assigned in block @stream_mutex.synchronize { ret = reader_read_page_low_level data_length = ret[0] data_chunk_offset = ret[1] data_out_of_sync = data_chunk_offset != 0 data_data = ret[2] while not data_out_of_sync and data_data.length < data_length ret = reader_read_page_low_level data_length = ret[0] data_chunk_offset = ret[1] data_out_of_sync = data_chunk_offset != data_data.length data_data += ret[2] end if data_out_of_sync # discard remaining stream to bring it back in-sync while data_chunk_offset + 60 < data_length ret = reader_read_page_low_level data_length = ret[0] data_chunk_offset = ret[1] end raise StreamOutOfSyncException, 'Data stream is out-of-sync' end } data_data[0, data_length] end |
#reader_read_page_low_level ⇒ Object
Returns the page data from an internal buffer. To fill the buffer with specific pages you have to call BrickletNFC#reader_request_page beforehand.
431 432 433 434 435 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 431 def reader_read_page_low_level check_validity send_request FUNCTION_READER_READ_PAGE_LOW_LEVEL, [], '', 72, 'S S C60' end |
#reader_request_ndef ⇒ Object
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:
-
Call BrickletNFC#reader_request_tag_id
-
Wait for state to change to RequestTagIDReady (see BrickletNFC#reader_get_state or CALLBACK_READER_STATE_CHANGED callback)
-
If looking for a specific tag then call BrickletNFC#reader_get_tag_id and check if the expected tag was found, if it was not found got back to step 1
-
Call BrickletNFC#reader_request_ndef
-
Wait for state to change to ReaderRequestNDEFReady (see BrickletNFC#reader_get_state or CALLBACK_READER_STATE_CHANGED callback)
-
Call BrickletNFC#reader_read_ndef to retrieve the NDEF message from the buffer
320 321 322 323 324 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 320 def reader_request_ndef check_validity send_request FUNCTION_READER_REQUEST_NDEF, [], '', 8, '' end |
#reader_request_page(page, length) ⇒ Object
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 BrickletNFC#reader_read_page. 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)
The general approach for reading a tag is as follows:
-
Call BrickletNFC#reader_request_tag_id
-
Wait for state to change to RequestTagIDReady (see BrickletNFC#reader_get_state or CALLBACK_READER_STATE_CHANGED callback)
-
If looking for a specific tag then call BrickletNFC#reader_get_tag_id and check if the expected tag was found, if it was not found got back to step 1
-
Call BrickletNFC#reader_request_page with page number
-
Wait for state to change to ReaderRequestPageReady (see BrickletNFC#reader_get_state or CALLBACK_READER_STATE_CHANGED callback)
-
Call BrickletNFC#reader_read_page 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 BrickletNFC#reader_authenticate_mifare_classic_page.
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.
423 424 425 426 427 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 423 def reader_request_page(page, length) check_validity send_request FUNCTION_READER_REQUEST_PAGE, [page, length], 'S S', 8, '' end |
#reader_request_tag_id ⇒ Object
After you call BrickletNFC#reader_request_tag_id 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 CALLBACK_READER_STATE_CHANGED callback or you can poll BrickletNFC#reader_get_state 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 BrickletNFC#reader_get_tag_id.
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 BrickletNFC#reader_request_tag_id 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 BrickletNFC#reader_request_tag_id.
241 242 243 244 245 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 241 def reader_request_tag_id check_validity send_request FUNCTION_READER_REQUEST_TAG_ID, [], '', 8, '' end |
#reader_write_ndef(ndef) ⇒ Object
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:
-
Call BrickletNFC#reader_request_tag_id
-
Wait for state to change to ReaderRequestTagIDReady (see BrickletNFC#reader_get_state or CALLBACK_READER_STATE_CHANGED callback)
-
If looking for a specific tag then call BrickletNFC#reader_get_tag_id and check if the expected tag was found, if it was not found got back to step 1
-
Call BrickletNFC#reader_write_ndef with the NDEF message that you want to write
-
Wait for state to change to ReaderWriteNDEFReady (see BrickletNFC#reader_get_state or CALLBACK_READER_STATE_CHANGED callback)
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 806 def reader_write_ndef(ndef) if ndef.length > 65535 raise ArgumentError, 'NDEF can be at most 65535 items long' end ndef_length = ndef.length ndef_chunk_offset = 0 if ndef_length == 0 ndef_chunk_data = [0] * 60 ret = reader_write_ndef_low_level ndef_length, ndef_chunk_offset, ndef_chunk_data else ret = nil # assigned in block @stream_mutex.synchronize { while ndef_chunk_offset < ndef_length ndef_chunk_data = ndef[ndef_chunk_offset, 60] if ndef_chunk_data.length < 60 ndef_chunk_data += [0] * (60 - ndef_chunk_data.length) end ret = reader_write_ndef_low_level ndef_length, ndef_chunk_offset, ndef_chunk_data ndef_chunk_offset += 60 end } end ret end |
#reader_write_ndef_low_level(ndef_length, ndef_chunk_offset, ndef_chunk_data) ⇒ Object
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:
-
Call BrickletNFC#reader_request_tag_id
-
Wait for state to change to ReaderRequestTagIDReady (see BrickletNFC#reader_get_state or CALLBACK_READER_STATE_CHANGED callback)
-
If looking for a specific tag then call BrickletNFC#reader_get_tag_id and check if the expected tag was found, if it was not found got back to step 1
-
Call BrickletNFC#reader_write_ndef with the NDEF message that you want to write
-
Wait for state to change to ReaderWriteNDEFReady (see BrickletNFC#reader_get_state or CALLBACK_READER_STATE_CHANGED callback)
299 300 301 302 303 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 299 def reader_write_ndef_low_level(ndef_length, ndef_chunk_offset, ndef_chunk_data) check_validity send_request FUNCTION_READER_WRITE_NDEF_LOW_LEVEL, [ndef_length, ndef_chunk_offset, ndef_chunk_data], 'S S C60', 8, '' end |
#reader_write_page(page, data) ⇒ Object
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)
The general approach for writing to a tag is as follows:
-
Call BrickletNFC#reader_request_tag_id
-
Wait for state to change to ReaderRequestTagIDReady (see BrickletNFC#reader_get_state or CALLBACK_READER_STATE_CHANGED callback)
-
If looking for a specific tag then call BrickletNFC#reader_get_tag_id and check if the expected tag was found, if it was not found got back to step 1
-
Call BrickletNFC#reader_write_page with page number and data
-
Wait for state to change to ReaderWritePageReady (see BrickletNFC#reader_get_state or CALLBACK_READER_STATE_CHANGED callback)
If you use a Mifare Classic tag you have to authenticate a page before you can write to it. See BrickletNFC#reader_authenticate_mifare_classic_page.
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.
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 899 def reader_write_page(page, data) if data.length > 65535 raise ArgumentError, 'Data can be at most 65535 items long' end data_length = data.length data_chunk_offset = 0 if data_length == 0 data_chunk_data = [0] * 58 ret = reader_write_page_low_level page, data_length, data_chunk_offset, data_chunk_data else ret = nil # assigned in block @stream_mutex.synchronize { while data_chunk_offset < data_length data_chunk_data = data[data_chunk_offset, 58] if data_chunk_data.length < 58 data_chunk_data += [0] * (58 - data_chunk_data.length) end ret = reader_write_page_low_level page, data_length, data_chunk_offset, data_chunk_data data_chunk_offset += 58 end } end ret end |
#reader_write_page_low_level(page, data_length, data_chunk_offset, data_chunk_data) ⇒ Object
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)
The general approach for writing to a tag is as follows:
-
Call BrickletNFC#reader_request_tag_id
-
Wait for state to change to ReaderRequestTagIDReady (see BrickletNFC#reader_get_state or CALLBACK_READER_STATE_CHANGED callback)
-
If looking for a specific tag then call BrickletNFC#reader_get_tag_id and check if the expected tag was found, if it was not found got back to step 1
-
Call BrickletNFC#reader_write_page with page number and data
-
Wait for state to change to ReaderWritePageReady (see BrickletNFC#reader_get_state or CALLBACK_READER_STATE_CHANGED callback)
If you use a Mifare Classic tag you have to authenticate a page before you can write to it. See BrickletNFC#reader_authenticate_mifare_classic_page.
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.
387 388 389 390 391 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 387 def reader_write_page_low_level(page, data_length, data_chunk_offset, data_chunk_data) check_validity send_request FUNCTION_READER_WRITE_PAGE_LOW_LEVEL, [page, data_length, data_chunk_offset, data_chunk_data], 'S S S C58', 8, '' end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id
to the block block
.
1079 1080 1081 1082 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 1079 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#reset ⇒ Object
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!
737 738 739 740 741 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 737 def reset check_validity send_request FUNCTION_RESET, [], '', 8, '' end |
#set_bootloader_mode(mode) ⇒ Object
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.
660 661 662 663 664 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 660 def set_bootloader_mode(mode) check_validity send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 9, 'C' end |
#set_detection_led_config(config) ⇒ Object
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.
587 588 589 590 591 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 587 def set_detection_led_config(config) check_validity send_request FUNCTION_SET_DETECTION_LED_CONFIG, [config], 'C', 8, '' end |
#set_maximum_timeout(timeout) ⇒ Object
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 BrickletNFC#reader_request_tag_id 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.
- .. versionadded
-
2.0.1$nbsp;(Plugin)
619 620 621 622 623 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 619 def set_maximum_timeout(timeout) check_validity send_request FUNCTION_SET_MAXIMUM_TIMEOUT, [timeout], 'S', 8, '' end |
#set_mode(mode) ⇒ Object
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
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.
211 212 213 214 215 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 211 def set_mode(mode) check_validity send_request FUNCTION_SET_MODE, [mode], 'C', 8, '' end |
#set_status_led_config(config) ⇒ Object
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.
706 707 708 709 710 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 706 def set_status_led_config(config) check_validity send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, '' end |
#set_write_firmware_pointer(pointer) ⇒ Object
Sets the firmware pointer for BrickletNFC#write_firmware. 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.
679 680 681 682 683 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 679 def set_write_firmware_pointer(pointer) check_validity send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 8, '' end |
#write_firmware(data) ⇒ Object
Writes 64 Bytes of firmware at the position as written by BrickletNFC#set_write_firmware_pointer 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.
693 694 695 696 697 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 693 def write_firmware(data) check_validity send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 9, 'C' end |
#write_uid(uid) ⇒ Object
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.
748 749 750 751 752 |
# File 'lib/tinkerforge/bricklet_nfc.rb', line 748 def write_uid(uid) check_validity send_request FUNCTION_WRITE_UID, [uid], 'L', 8, '' end |