pyupm_sm130 module

class pyupm_sm130.SM130(uart=0, reset=13)[source]

Bases: object

API for the SM130 RFID Reader Module.

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.

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

C++ includes: sm130.hpp

CMD_ANTENNA_POWER = 144
CMD_AUTHENTICATE = 133
CMD_DEC_VALUE = 142
CMD_HALT_TAG = 147
CMD_INC_VALUE = 141
CMD_READ16 = 134
CMD_READ_PORT = 145
CMD_READ_VALUE = 135
CMD_RESET = 128
CMD_SEEK_TAG = 130
CMD_SELECT_TAG = 131
CMD_SET_BAUD = 148
CMD_SLEEP = 150
CMD_VERSION = 129
CMD_WRITE16 = 137
CMD_WRITE4 = 139
CMD_WRITE_KEY = 140
CMD_WRITE_PORT = 146
CMD_WRITE_VALUE = 138
KEY_TYPE_A = 170
KEY_TYPE_A_AND_TRANSPORT_F = 255
KEY_TYPE_B = 187
KEY_TYPE_EEPROM_A0 = 16
KEY_TYPE_EEPROM_A1 = 17
KEY_TYPE_EEPROM_A10 = 26
KEY_TYPE_EEPROM_A11 = 27
KEY_TYPE_EEPROM_A12 = 28
KEY_TYPE_EEPROM_A13 = 29
KEY_TYPE_EEPROM_A14 = 30
KEY_TYPE_EEPROM_A15 = 31
KEY_TYPE_EEPROM_A2 = 18
KEY_TYPE_EEPROM_A3 = 19
KEY_TYPE_EEPROM_A4 = 20
KEY_TYPE_EEPROM_A5 = 21
KEY_TYPE_EEPROM_A6 = 22
KEY_TYPE_EEPROM_A7 = 23
KEY_TYPE_EEPROM_A8 = 24
KEY_TYPE_EEPROM_A9 = 25
KEY_TYPE_EEPROM_B0 = 32
KEY_TYPE_EEPROM_B1 = 33
KEY_TYPE_EEPROM_B10 = 42
KEY_TYPE_EEPROM_B11 = 43
KEY_TYPE_EEPROM_B12 = 44
KEY_TYPE_EEPROM_B13 = 45
KEY_TYPE_EEPROM_B14 = 46
KEY_TYPE_EEPROM_B15 = 47
KEY_TYPE_EEPROM_B2 = 34
KEY_TYPE_EEPROM_B3 = 35
KEY_TYPE_EEPROM_B4 = 36
KEY_TYPE_EEPROM_B5 = 37
KEY_TYPE_EEPROM_B6 = 38
KEY_TYPE_EEPROM_B7 = 39
KEY_TYPE_EEPROM_B8 = 40
KEY_TYPE_EEPROM_B9 = 41
TAG_MIFARE_1K = 2
TAG_MIFARE_4K = 3
TAG_MIFARE_ULTRALIGHT = 1
TAG_NONE = 0
TAG_UNKNOWN = 255
adjustValueBlock(block, value, incr)[source]

int32_t adjustValueBlock(uint8_t block, int32_t value, bool incr)

Increment or decrement a value block.

block: The block to adjust

value: The number to increment or decrement the value block by

incr: true to increment, false to decrement

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

authenticate(*args)[source]

bool authenticate(uint8_t block, KEY_TYPES_T keyType, std::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.

block: The block to authenticate for

keyType: one of the KEY_TYPE_T values

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

true if authentication was successful, false otherwise

getFirmwareVersion()[source]

string getFirmwareVersion()

Gets the firmware version string.

The firmware revision

getLastErrorCode()[source]

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.

The last error code, or 0 if the last operation succeeded.

getLastErrorString()[source]

std::string getLastErrorString()

Get the text representation of the last error that occurred. The returned string is empty if the last operation completed successfully.

The last error string if an error occurred, or an empty string if the last operation succeeded.

getTagType()[source]

TAG_TYPE_T getTagType()

Get the tag type of the currently selected tag.

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

getUID()[source]

std::string getUID()

Get the UID of the currently selected tag.

The UID of the currently selected tag, or an empty string if no tag is currently selected.

getUIDLen()[source]

int getUIDLen()

Get the UID length of the currently selected tag.

The UID length of the currently selected tag, or 0 if no tag is currently selected.

haltTag()[source]

bool 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.

true if successful, false otherwise

hardwareReset()[source]

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.

readBlock16(block)[source]

string readBlock16(uint8_t block)

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

block: The block to read

The 16 byte block if successful, an empty string otherwise

readPorts()[source]

uint8_t 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.

bitmask of input port status values

readValueBlock(block)[source]

int32_t readValueBlock(uint8_t block)

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

block: The block to read

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

reset()[source]

bool reset()

Issues a reset command to the device.

true if successful

select()[source]

bool select()

Checks to see if a tag is in the RF field, and selects it if one is present.

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

setAntennaPower(on)[source]

bool setAntennaPower(bool 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.

on: true to enable antenna power, false to disable

true if successful, false otherwise

setBaudRate(baud=19200)[source]

mraa::Result setBaudRate(int baud=19200)

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

baud: Desired baud rate, default 19200

mraa::Result value

setSM130BaudRate(baud)[source]

bool 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.

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

true if successful, false otherwise

sleep()[source]

bool 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.

true if successful, false otherwise

string2HexString(input)[source]

string string2HexString(std::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.

input: The string to convert

A string representation of the input in space separated hex values

tag2String(tag)[source]

string tag2String(TAG_TYPE_T tag)

Convert the supplied tag type into a human readable string.

tag: One of the TAG_TYPE_T values

A string representation of the supplied tag type

waitForTag(timeout)[source]

bool waitForTag(uint32_t 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.

timeout: The number of milliseconds to wait for a tag to appear

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

writeBlock16(block, contents)[source]

bool writeBlock16(uint8_t block, std::string contents)

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

block: The block to write

contents: A 16 byte string containing the data to write

true if successful, false otherwise

writeBlock4(block, contents)[source]

bool writeBlock4(uint8_t block, std::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.

block: The block to write

contents: A 4 byte string containing the data to write

true if successful, false otherwise

writeKey(eepromSector, keyType, key)[source]

bool writeKey(uint8_t eepromSector, KEY_TYPES_T keyType, std::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().

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

keyType: Either KEY_TYPE_A or KEY_TYPE_B

key: The 6 byte key to store in the EEPROM

true if successful, false otherwise

writePorts(val)[source]

bool writePorts(uint8_t 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.

val: bitmask of output status bits to write

true if successful, false otherwise

writeValueBlock(block, value)[source]

bool writeValueBlock(uint8_t block, int32_t value)

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

block: The block to write

value: the signed 4 byte integer to write to the value block

true if successful, false otherwise