UPM

The UPM API is a high level sensor library for IoT devices using MRAA. See examples here. Back to index page.
SparkFun sensor images provided under CC BY-NC-SA-3.0.

SM130 Class

Module: sm130

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

Methods

SM130

(
  • uart
  • reset
)
Number

Instantiates an SM130 object

Parameters:

  • uart Number

    The UART port. Default is 0.

  • reset Number

    The Reset pin. Default is 13.

Returns:

Number:

setBaudRate

(
  • baud
)
Mraa::Result

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

Parameters:

  • baud Number

    Desired baud rate, default 19200

Returns:

Mraa::Result:

mraa::Result value

getFirmwareVersion

() String

Gets the firmware version string.

Returns:

String:

The firmware revision

reset

() Boolean

Issues a reset command to the device.

Returns:

Boolean:

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:

Boolean:

true if a tag was detected, false if no tag is present or an error was detected.

waitForTag

(
  • timeout
)
Boolean

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 Number

    The number of milliseconds to wait for a tag to appear

Returns:

Boolean:

true if a tag was detected, false if no tag was detected within the timeout value, or an error occurred

authenticate

(
  • block
  • keyType
  • key
)
Boolean

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 Number

    The block to authenticate for

  • keyType KEY_TYPES_T

    one of the KEY_TYPE_T values

  • key String

    The 6 byte key to use for Type A and Type B keys

Returns:

Boolean:

true if authentication was successful, false otherwise

readBlock16

(
  • block
)
String

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

Parameters:

  • block Number

    The block to read

Returns:

String:

The 16 byte block if successful, an empty string otherwise

readValueBlock

(
  • block
)
Number

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

Parameters:

  • block Number

    The block to read

Returns:

Number:

The 4 byte signed integer value block if successful, 0 otherwise

writeBlock16

(
  • block
  • contents
)
Boolean

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

Parameters:

  • block Number

    The block to write

  • contents String

    A 16 byte string containing the data to write

Returns:

Boolean:

true if successful, false otherwise

writeValueBlock

(
  • block
  • value
)
Boolean

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 Number

    The block to write

  • value Number

    the signed 4 byte integer to write to the value block

Returns:

Boolean:

true if successful, false otherwise

writeBlock4

(
  • block
  • contents
)
Boolean

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 Number

    The block to write

  • contents String

    A 4 byte string containing the data to write

Returns:

Boolean:

true if successful, false otherwise

writeKey

(
  • eepromSector
  • keyType
  • key
)
Boolean

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 Number

    A number between 0 and 15, indicating the EEPROM sector you want to store the key in

  • keyType KEY_TYPES_T

    Either KEY_TYPE_A or KEY_TYPE_B

  • key String

    The 6 byte key to store in the EEPROM

Returns:

Boolean:

true if successful, false otherwise

adjustValueBlock

(
  • block
  • value
  • incr
)
Number

Increment or decrement a value block.

Parameters:

  • block Number

    The block to adjust

  • value Number

    The number to increment or decrement the value block by

  • incr Boolean

    true to increment, false to decrement

Returns:

Number:

The contents of the value block after the operation has completed.

setAntennaPower

(
  • on
)
Boolean

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 Boolean

    true to enable antenna power, false to disable

Returns:

Boolean:

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:

Number:

bitmask of input port status values

writePorts

(
  • val
)
Boolean

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 Number

    bitmask of output status bits to write

Returns:

Boolean:

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:

Boolean:

true if successful, false otherwise

setSM130BaudRate

(
  • baud
)
Boolean

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 Number

    The new baud rate to set. Valid values are 9600, 19200, 38400, 57600, and 115200.

Returns:

Boolean:

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:

Boolean:

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:

String:

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:

String:

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:

Number:

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:

String:

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:

TAG_TYPE_T:

The tag type of the currently selected tag, or TAG_NONE if no tag is currently selected.

tag2String

(
  • tag
)
String

Convert the supplied tag type into a human readable string.

Parameters:

  • tag TAG_TYPE_T

    One of the TAG_TYPE_T values

Returns:

String:

A string representation of the supplied tag type

string2HexString

(
  • input
)
String

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 String

    The string to convert

Returns:

String:

A string representation of the input in space separated hex values

Properties

CMD_RESET

Enum CMD_T

CMD_VERSION

Enum CMD_T

CMD_SEEK_TAG

Enum CMD_T

CMD_SELECT_TAG

Enum CMD_T

CMD_AUTHENTICATE

Enum CMD_T

CMD_READ16

Enum CMD_T

CMD_READ_VALUE

Enum CMD_T

CMD_WRITE16

Enum CMD_T

CMD_WRITE_VALUE

Enum CMD_T

CMD_WRITE4

Enum CMD_T

CMD_WRITE_KEY

Enum CMD_T

CMD_INC_VALUE

Enum CMD_T

CMD_DEC_VALUE

Enum CMD_T

CMD_ANTENNA_POWER

Enum CMD_T

CMD_READ_PORT

Enum CMD_T

CMD_WRITE_PORT

Enum CMD_T

CMD_HALT_TAG

Enum CMD_T

CMD_SET_BAUD

Enum CMD_T

CMD_SLEEP

Enum CMD_T

TAG_NONE

Enum TAG_TYPE_T

TAG_MIFARE_ULTRALIGHT

Enum TAG_TYPE_T

TAG_MIFARE_1K

Enum TAG_TYPE_T

TAG_MIFARE_4K

Enum TAG_TYPE_T

TAG_UNKNOWN

Enum TAG_TYPE_T

KEY_TYPE_EEPROM_A0

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_A1

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_A2

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_A3

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_A4

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_A5

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_A6

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_A7

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_A8

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_A9

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_A10

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_A11

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_A12

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_A13

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_A14

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_A15

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_B0

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_B1

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_B2

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_B3

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_B4

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_B5

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_B6

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_B7

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_B8

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_B9

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_B10

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_B11

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_B12

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_B13

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_B14

Enum KEY_TYPES_T

KEY_TYPE_EEPROM_B15

Enum KEY_TYPES_T

KEY_TYPE_A

Enum KEY_TYPES_T

KEY_TYPE_B

Enum KEY_TYPES_T

KEY_TYPE_A_AND_TRANSPORT_F

Enum KEY_TYPES_T