upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
Classes | Public Member Functions | List of all members

API for the SM130 RFID Reader Module. More...

Detailed Description

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.

sm130.jpg


SM130 RFID Reader image provided by SparkFun* under CC BY-NC-SA-3.0.

Classes

class  CMD_T
 
class  KEY_TYPES_T
 
class  TAG_TYPE_T
 

Public Member Functions

synchronized void delete ()
 
 SM130 (int uart, int reset)
 
 SM130 (int uart)
 
int setBaudRate (int baud)
 
int setBaudRate ()
 
String getFirmwareVersion ()
 
boolean reset ()
 
void hardwareReset ()
 
boolean select ()
 
boolean waitForTag (long timeout)
 
boolean authenticate (short block, SM130.KEY_TYPES_T keyType, String key)
 
boolean authenticate (short block, SM130.KEY_TYPES_T keyType)
 
String readBlock16 (short block)
 
int readValueBlock (short block)
 
boolean writeBlock16 (short block, String contents)
 
boolean writeValueBlock (short block, int value)
 
boolean writeBlock4 (short block, String contents)
 
boolean writeKey (short eepromSector, SM130.KEY_TYPES_T keyType, String key)
 
int adjustValueBlock (short block, int value, boolean incr)
 
boolean setAntennaPower (boolean on)
 
short readPorts ()
 
boolean writePorts (short val)
 
boolean haltTag ()
 
boolean setSM130BaudRate (int baud)
 
boolean sleep ()
 
char getLastErrorCode ()
 
String getLastErrorString ()
 
int getUIDLen ()
 
String getUID ()
 
SM130.TAG_TYPE_T getTagType ()
 
String tag2String (SM130.TAG_TYPE_T tag)
 
String string2HexString (String input)
 

Constructor & Destructor Documentation

SM130 ( int  uart,
int  reset 
)

Instantiates an SM130 object

Parameters
uartThe UART port. Default is 0.
resetThe Reset pin. Default is 13.

Member Function Documentation

int adjustValueBlock ( short  block,
int  value,
boolean  incr 
)

Increment or decrement a value block.

Parameters
blockThe block to adjust
valueThe number to increment or decrement the value block by
incrtrue to increment, false to decrement
Returns
The contents of the value block after the operation has completed.
boolean authenticate ( short  block,
SM130.KEY_TYPES_T  keyType,
String  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
blockThe block to authenticate for
keyTypeone of the KEY_TYPE_T values
keyThe 6 byte key to use for Type A and Type B keys
Returns
true if authentication was successful, false otherwise
String getFirmwareVersion ( )

Gets the firmware version string.

Returns
The firmware revision
char getLastErrorCode ( )

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.
String getLastErrorString ( )

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.
SM130.TAG_TYPE_T getTagType ( )

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.
String getUID ( )

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.
int getUIDLen ( )

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.
boolean haltTag ( )

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
void hardwareReset ( )

Resets the device using the hardware RESET pin. This is required if the device has been put to sleep using the sleep() method.

String readBlock16 ( short  block)

Read a 16 byte block. Depending on the tag, authentication of the block may be required for this method to succeed.

Parameters
blockThe block to read
Returns
The 16 byte block if successful, an empty string otherwise
short readPorts ( )

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
int readValueBlock ( short  block)

Read a 4 byte value block. Depending on the tag, authentication of the block may be required for this method to succeed.

Parameters
blockThe block to read
Returns
The 4 byte signed integer value block if successful, 0 otherwise
boolean reset ( )

Issues a reset command to the device.

Returns
true if successful
boolean select ( )

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.
boolean setAntennaPower ( boolean  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
ontrue to enable antenna power, false to disable
Returns
true if successful, false otherwise
int setBaudRate ( int  baud)

Sets the baud rate for the device. The default is 19200.

Parameters
baudDesired baud rate, default 19200
Returns
mraa::Result value
boolean setSM130BaudRate ( int  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
baudThe new baud rate to set. Valid values are 9600, 19200, 38400, 57600, and 115200.
Returns
true if successful, false otherwise
boolean sleep ( )

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
String string2HexString ( String  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
inputThe string to convert
Returns
A string representation of the input in space separated hex values
String tag2String ( SM130.TAG_TYPE_T  tag)

Convert the supplied tag type into a human readable string.

Parameters
tagOne of the TAG_TYPE_T values
Returns
A string representation of the supplied tag type
boolean waitForTag ( long  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
timeoutThe 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
boolean writeBlock16 ( short  block,
String  contents 
)

Write 16 bytes to a block. Depending on the tag, authentication of the block may be required for this method to succeed.

Parameters
blockThe block to write
contentsA 16 byte string containing the data to write
Returns
true if successful, false otherwise
boolean writeBlock4 ( short  block,
String  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
blockThe block to write
contentsA 4 byte string containing the data to write
Returns
true if successful, false otherwise
boolean writeKey ( short  eepromSector,
SM130.KEY_TYPES_T  keyType,
String  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
eepromSectorA number between 0 and 15, indicating the EEPROM sector you want to store the key in
keyTypeEither KEY_TYPE_A or KEY_TYPE_B
keyThe 6 byte key to store in the EEPROM
Returns
true if successful, false otherwise
boolean writePorts ( short  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
valbitmask of output status bits to write
Returns
true if successful, false otherwise
boolean writeValueBlock ( short  block,
int  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
blockThe block to write
valuethe signed 4 byte integer to write to the value block
Returns
true if successful, false otherwise

The documentation for this class was generated from the following file: