SM130 Class
- ID: sm130
- Name: RFID Reader
- Category: rfid
- Manufacturer: sparkfun
- Link: https://www.sparkfun.com/products/10126
- Connection: uart gpio
This module defines the SM130 interface for the sm130 RFID library
This module was developed using an SM130 and a Sparkfun RFID Evaluation shield using a UART for communications. It should be fairly trivial to add support for I2C communication in the future, if you have the correct firmware on the SM130 .
Item Index
Methods
- SM130
- setBaudRate
- getFirmwareVersion
- reset
- hardwareReset
- select
- waitForTag
- authenticate
- readBlock16
- readValueBlock
- writeBlock16
- writeValueBlock
- writeBlock4
- writeKey
- adjustValueBlock
- setAntennaPower
- readPorts
- writePorts
- haltTag
- setSM130BaudRate
- sleep
- getLastErrorCode
- getLastErrorString
- getUIDLen
- getUID
- getTagType
- tag2String
- string2HexString
Properties
- CMD_RESET
- CMD_VERSION
- CMD_SEEK_TAG
- CMD_SELECT_TAG
- CMD_AUTHENTICATE
- CMD_READ16
- CMD_READ_VALUE
- CMD_WRITE16
- CMD_WRITE_VALUE
- CMD_WRITE4
- CMD_WRITE_KEY
- CMD_INC_VALUE
- CMD_DEC_VALUE
- CMD_ANTENNA_POWER
- CMD_READ_PORT
- CMD_WRITE_PORT
- CMD_HALT_TAG
- CMD_SET_BAUD
- CMD_SLEEP
- TAG_NONE
- TAG_MIFARE_ULTRALIGHT
- TAG_MIFARE_1K
- TAG_MIFARE_4K
- TAG_UNKNOWN
- KEY_TYPE_EEPROM_A0
- KEY_TYPE_EEPROM_A1
- KEY_TYPE_EEPROM_A2
- KEY_TYPE_EEPROM_A3
- KEY_TYPE_EEPROM_A4
- KEY_TYPE_EEPROM_A5
- KEY_TYPE_EEPROM_A6
- KEY_TYPE_EEPROM_A7
- KEY_TYPE_EEPROM_A8
- KEY_TYPE_EEPROM_A9
- KEY_TYPE_EEPROM_A10
- KEY_TYPE_EEPROM_A11
- KEY_TYPE_EEPROM_A12
- KEY_TYPE_EEPROM_A13
- KEY_TYPE_EEPROM_A14
- KEY_TYPE_EEPROM_A15
- KEY_TYPE_EEPROM_B0
- KEY_TYPE_EEPROM_B1
- KEY_TYPE_EEPROM_B2
- KEY_TYPE_EEPROM_B3
- KEY_TYPE_EEPROM_B4
- KEY_TYPE_EEPROM_B5
- KEY_TYPE_EEPROM_B6
- KEY_TYPE_EEPROM_B7
- KEY_TYPE_EEPROM_B8
- KEY_TYPE_EEPROM_B9
- KEY_TYPE_EEPROM_B10
- KEY_TYPE_EEPROM_B11
- KEY_TYPE_EEPROM_B12
- KEY_TYPE_EEPROM_B13
- KEY_TYPE_EEPROM_B14
- KEY_TYPE_EEPROM_B15
- KEY_TYPE_A
- KEY_TYPE_B
- KEY_TYPE_A_AND_TRANSPORT_F
Methods
SM130
-
uart
-
reset
Instantiates an SM130 object
Parameters:
-
uart
NumberThe UART port. Default is 0.
-
reset
NumberThe Reset pin. Default is 13.
Returns:
setBaudRate
-
baud
Sets the baud rate for the device. The default is 19200.
Parameters:
-
baud
NumberDesired baud rate, default 19200
Returns:
mraa::Result value
getFirmwareVersion
()
String
Gets the firmware version string.
Returns:
The firmware revision
reset
()
Boolean
Issues a reset command to the device.
Returns:
true if successful
hardwareReset
()
Resets the device using the hardware RESET pin. This is required if the device has been put to sleep using the sleep() method.
select
()
Boolean
Checks to see if a tag is in the RF field, and selects it if one is present.
Returns:
true if a tag was detected, false if no tag is present or an error was detected.
waitForTag
-
timeout
Waits for a tag to enter the RF field for up to 'timeout' milliseconds. It will call select() every 100ms until 'timeout' has been exceeded.
Parameters:
-
timeout
NumberThe number of milliseconds to wait for a tag to appear
Returns:
true if a tag was detected, false if no tag was detected within the timeout value, or an error occurred
authenticate
-
block
-
keyType
-
key
Set the authentication key for a block. Depending on the permissions on the tag, the correct key must be authenticated for that block in order to perform read and write operations.
Parameters:
-
block
NumberThe block to authenticate for
-
keyType
KEY_TYPES_Tone of the KEY_TYPE_T values
-
key
StringThe 6 byte key to use for Type A and Type B keys
Returns:
true if authentication was successful, false otherwise
readBlock16
-
block
Read a 16 byte block. Depending on the tag, authentication of the block may be required for this method to succeed.
Parameters:
-
block
NumberThe block to read
Returns:
The 16 byte block if successful, an empty string otherwise
readValueBlock
-
block
Read a 4 byte value block. Depending on the tag, authentication of the block may be required for this method to succeed.
Parameters:
-
block
NumberThe block to read
Returns:
The 4 byte signed integer value block if successful, 0 otherwise
writeBlock16
-
block
-
contents
Write 16 bytes to a block. Depending on the tag, authentication of the block may be required for this method to succeed.
Parameters:
-
block
NumberThe block to write
-
contents
StringA 16 byte string containing the data to write
Returns:
true if successful, false otherwise
writeValueBlock
-
block
-
value
Write to a 4 byte value block. Depending on the tag, authentication of the block may be required for this method to succeed.
Parameters:
-
block
NumberThe block to write
-
value
Numberthe signed 4 byte integer to write to the value block
Returns:
true if successful, false otherwise
writeBlock4
-
block
-
contents
Write 4 bytes to a block. This is typically used for Ultralight tags. Depending on the tag, authentication of the block may be required for this method to succeed.
Parameters:
-
block
NumberThe block to write
-
contents
StringA 4 byte string containing the data to write
Returns:
true if successful, false otherwise
writeKey
-
eepromSector
-
keyType
-
key
Write a key into one of the 16 EEPROM key slots. This can be a Type A or Type B key. It is not possible to read these keys once written. Once stored, the key can be used for authentication without having to send the key itself. You can then use the appropriate KEY_TYPE_EEPROM_* keyTypes in a call to authenticate() .
Parameters:
-
eepromSector
NumberA number between 0 and 15, indicating the EEPROM sector you want to store the key in
-
keyType
KEY_TYPES_TEither KEY_TYPE_A or KEY_TYPE_B
-
key
StringThe 6 byte key to store in the EEPROM
Returns:
true if successful, false otherwise
adjustValueBlock
-
block
-
value
-
incr
Increment or decrement a value block.
Parameters:
-
block
NumberThe block to adjust
-
value
NumberThe number to increment or decrement the value block by
-
incr
Booleantrue to increment, false to decrement
Returns:
The contents of the value block after the operation has completed.
setAntennaPower
-
on
Turn the antenna power on or off. The power is on by default after a reset. If you turn off the antenna, and methods used for interacting with tags will fail until power is re-enabled.
Parameters:
-
on
Booleantrue to enable antenna power, false to disable
Returns:
true if successful, false otherwise
readPorts
()
Number
Read the status of the 2 onboard GPIO input pins. Bit 0 is for input 0, bit 1 for input 1. All other bits will be 0.
Returns:
bitmask of input port status values
writePorts
-
val
Set the output status of the 2 onboard gpio outputs. Bit 0 is for output 0, bit 1 for output 1. All other bits will be discarded.
Parameters:
-
val
Numberbitmask of output status bits to write
Returns:
true if successful, false otherwise
haltTag
()
Boolean
Halts a tag. Once a tag is halted, it cannot be accessed until it is removed and reinserted into the RF field and selected.
Returns:
true if successful, false otherwise
setSM130BaudRate
-
baud
Changes the baud rate of the SM130 . WARNING: This is a potentially dangerous command that could cause you to lose contact with the device. Once the command is validated and issued, the host baudrate will be changed to match, and this method will wait for a response at the new baudrate for up to 1 second.
If this response does not arrive, the old baudrate will be restored, though there is no way to know whether the SM130 actually succeessfully executed the baudrate change.
Once the SM130 has changed it's baudrate, the new value will be stored in it's EEPROM, and any further access to the device will need to use the new baudrate. This is true even after a power on reset.
Parameters:
-
baud
NumberThe new baud rate to set. Valid values are 9600, 19200, 38400, 57600, and 115200.
Returns:
true if successful, false otherwise
sleep
()
Boolean
Put the SM130 to sleep. Once the device has been put to sleep, the only way to wake it is via hardwareReset() or a power cycle.
Returns:
true if successful, false otherwise
getLastErrorCode
()
String
Get the last error that occurred. After a successful operation, this will be 0. See the datasheet for the various errors that can occur in various circumstances.
Returns:
The last error code, or 0 if the last operation succeeded.
getLastErrorString
()
String
Get the text representation of the last error that occurred. The returned string is empty if the last operation completed successfully.
Returns:
The last error string if an error occurred, or an empty string if the last operation succeeded.
getUIDLen
()
Number
Get the UID length of the currently selected tag.
Returns:
The UID length of the currently selected tag, or 0 if no tag is currently selected.
getUID
()
String
Get the UID of the currently selected tag.
Returns:
The UID of the currently selected tag, or an empty string if no tag is currently selected.
getTagType
()
TAG_TYPE_T
Get the tag type of the currently selected tag.
Returns:
The tag type of the currently selected tag, or TAG_NONE if no tag is currently selected.
tag2String
-
tag
Convert the supplied tag type into a human readable string.
Parameters:
-
tag
TAG_TYPE_TOne of the TAG_TYPE_T values
Returns:
A string representation of the supplied tag type
string2HexString
-
input
This is a convenience function that converts a supplied string into a space separated hex formatted string. This can be useful for printing out binary data in a human readable format, like the UID.
Parameters:
-
input
StringThe string to convert
Returns:
A string representation of the input in space separated hex values