SM130 Class Reference

Class representing a SonMicro SM130 RFID module. More...

#include <SM130.h>


Public Member Functions

 SM130 ()
 Constructor.
void reset ()
 Hardware or software reset of the SM130 module.
const char * getFirmwareVersion ()
 Returns a null-terminated string with the firmware version of the SM130 module.
boolean available ()
 Returns true if a response packet is available.
byte * getRawData ()
 Returns a pointer to the response packet.
byte getCommand ()
 Returns the last executed command.
byte getPacketLength ()
 Returns the packet length, excluding checksum.
byte getCheckSum ()
 Returns the checksum.
byte * getPayload ()
 Returns a pointer to the packet payload.
byte getBlockNumber ()
 Returns the block number for read/write commands.
byte * getBlock ()
 Returns a pointer to the read block (with a length of 16 bytes).
byte * getTagNumber ()
 Returns the tag's serial number as a byte array.
byte getTagLength ()
 Returns the length of the tag's serial number obtained by getTagNumer().
const char * getTagString ()
 Returns the tag's serial number as a hexadecimal null-terminated string.
byte getTagType ()
 Returns the tag type (SM130::MIFARE_XX).
const char * getTagName ()
 Returns the tag type as a null-terminated string.
char getErrorCode ()
 Returns the error code of the last executed command.
const char * getErrorMessage ()
 Returns a human-readable error message corresponding to the error code.
byte getAntennaPower ()
 Returns the antenna power level (0 or 1).
void seekTag ()
 Sends a SEEK_TAG command.
void selectTag ()
 Sends a SELECT_TAG command.
void haltTag ()
 Sends a HALT_TAG command.
void setAntennaPower (byte level)
 Set antenna power (on/off).
void sleep ()
 Sends a SLEEP command (can only wake-up with hardware reset!).
void writeBlock (byte block, const char *message)
 Writes a null-terminated string of maximum 15 characters.
void writeFourByteBlock (byte block, const char *message)
 Writes a null-terminated string of maximum 3 characters to a Mifare Ultralight.
void authenticate (byte block)
 Sends a AUTHENTICATE command using the transport key.
void authenticate (byte block, byte keyType, byte key[6])
 Sends a AUTHENTICATE command using the specified key.
void readBlock (byte block)
 Reads a 16-byte block.

Data Fields

boolean debug
 debug mode, prints all I2C communication to Serial port
byte address
 I2C address (default 0x42).
byte pinRESET
 RESET pin (default 3).
byte pinDREADY
 DREADY pin (default 4).

Static Public Attributes

static const int VERSION = 1
 version of this library
static const byte MIFARE_ULTRALIGHT = 1
static const byte MIFARE_1K = 2
static const byte MIFARE_4K = 3
static const byte CMD_RESET = 0x80
static const byte CMD_VERSION = 0x81
static const byte CMD_SEEK_TAG = 0x82
static const byte CMD_SELECT_TAG = 0x83
static const byte CMD_AUTHENTICATE = 0x85
static const byte CMD_READ16 = 0x86
static const byte CMD_READ_VALUE = 0x87
static const byte CMD_WRITE16 = 0x89
static const byte CMD_WRITE_VALUE = 0x8a
static const byte CMD_WRITE4 = 0x8b
static const byte CMD_WRITE_KEY = 0x8c
static const byte CMD_INC_VALUE = 0x8d
static const byte CMD_DEC_VALUE = 0x8e
static const byte CMD_ANTENNA_POWER = 0x90
static const byte CMD_READ_PORT = 0x91
static const byte CMD_WRITE_PORT = 0x92
static const byte CMD_HALT_TAG = 0x93
static const byte CMD_SET_BAUD = 0x94
static const byte CMD_SLEEP = 0x96


Detailed Description

Class representing a SonMicro SM130 RFID module.

Nearly complete implementation of the SM130 datasheet.
Functions dealing with value blocks and stored keys are not implemented.

Definition at line 28 of file SM130.h.


Constructor & Destructor Documentation

SM130 (  ) 

Constructor.

An instance of SM130 should be created as a global variable, outside of any function. The constructor sets data fields to default values for use with RFIDuino. These may be changed in setup() before SM130::reset() is called.

Definition at line 40 of file SM130.cpp.


Member Function Documentation

void authenticate ( byte  block,
byte  keyType,
byte  key[6] 
)

Sends a AUTHENTICATE command using the specified key.

Authenticate with specified key A or key B.

Parameters:
block Block number
keyType Which key to use: 0xAA for key A or 0xBB for key B
key Key value (6 bytes)

Definition at line 283 of file SM130.cpp.

void authenticate ( byte  block  ) 

Sends a AUTHENTICATE command using the transport key.

Authenticate with transport key (0xFFFFFFFFFFFF).

Parameters:
block Block number

Definition at line 268 of file SM130.cpp.

boolean available (  ) 

Returns true if a response packet is available.

Checks for availability of a valid response packet.

This function should always be called and return true prior to using results of a command.

Returns:
true if a valid response packet is available

Definition at line 123 of file SM130.cpp.

byte getAntennaPower (  ) 

Returns the antenna power level (0 or 1).

Definition at line 110 of file SM130.h.

byte* getBlock (  ) 

Returns a pointer to the read block (with a length of 16 bytes).

Definition at line 94 of file SM130.h.

byte getBlockNumber (  ) 

Returns the block number for read/write commands.

Definition at line 92 of file SM130.h.

byte getCheckSum (  ) 

Returns the checksum.

Definition at line 88 of file SM130.h.

byte getCommand (  ) 

Returns the last executed command.

Definition at line 84 of file SM130.h.

char getErrorCode (  ) 

Returns the error code of the last executed command.

Definition at line 106 of file SM130.h.

const char * getErrorMessage (  ) 

Returns a human-readable error message corresponding to the error code.

Get error message for last command.

Returns:
Human-readable error message as a null-terminated string

Definition at line 220 of file SM130.cpp.

const char * getFirmwareVersion (  ) 

Returns a null-terminated string with the firmware version of the SM130 module.

Get the firmware version string.

Definition at line 98 of file SM130.cpp.

byte getPacketLength (  ) 

Returns the packet length, excluding checksum.

Definition at line 86 of file SM130.h.

byte* getPayload (  ) 

Returns a pointer to the packet payload.

Definition at line 90 of file SM130.h.

byte* getRawData (  ) 

Returns a pointer to the response packet.

Definition at line 82 of file SM130.h.

byte getTagLength (  ) 

Returns the length of the tag's serial number obtained by getTagNumer().

Definition at line 98 of file SM130.h.

const char* getTagName (  ) 

Returns the tag type as a null-terminated string.

Definition at line 104 of file SM130.h.

byte* getTagNumber (  ) 

Returns the tag's serial number as a byte array.

Definition at line 96 of file SM130.h.

const char* getTagString (  ) 

Returns the tag's serial number as a hexadecimal null-terminated string.

Definition at line 100 of file SM130.h.

byte getTagType (  ) 

Returns the tag type (SM130::MIFARE_XX).

Definition at line 102 of file SM130.h.

void haltTag (  ) 

Sends a HALT_TAG command.

Definition at line 116 of file SM130.h.

void readBlock ( byte  block  ) 

Reads a 16-byte block.

Read 16-byte block.

Parameters:
block Block number

Definition at line 297 of file SM130.cpp.

void reset (  ) 

Hardware or software reset of the SM130 module.

Reset the SM130 module.

This function should be called in setup(). It initializes the IO pins and issues a hardware or software reset, depending on the definition of pinRESET. After reset, a HALT_TAG command is issued to terminate the automatic SEEK mode.

Wire.begin() should also be called in setup(), and Wire.h should be included.

If pinRESET has the value 0xff (-1), software reset over I2C will be used. If pinDREADY has the value 0xff (-1), the SM130 will be polled over I2C while in SEEK mode, otherwise the DREADY pin will be polled in SEEK mode. For other commands, response polling is always over I2C.

Definition at line 65 of file SM130.cpp.

void seekTag (  ) 

Sends a SEEK_TAG command.

Definition at line 112 of file SM130.h.

void selectTag (  ) 

Sends a SELECT_TAG command.

Definition at line 114 of file SM130.h.

void setAntennaPower ( byte  level  ) 

Set antenna power (on/off).

Turns on/off the RF field.

Parameters:
level 0 is off, anything else is on

Definition at line 255 of file SM130.cpp.

void sleep (  ) 

Sends a SLEEP command (can only wake-up with hardware reset!).

Definition at line 120 of file SM130.h.

void writeBlock ( byte  block,
const char *  message 
)

Writes a null-terminated string of maximum 15 characters.

Write 16-byte block.

The block will be padded with zeroes if the message is shorter than 15 characters.

Parameters:
block Block number
message Null-terminated string of up to 15 characters

Definition at line 313 of file SM130.cpp.

void writeFourByteBlock ( byte  block,
const char *  message 
)

Writes a null-terminated string of maximum 3 characters to a Mifare Ultralight.

Write 4-byte block.

This command is used for Mifare Ultralight tags which have 4 byte blocks.

Parameters:
block Block number
message Null-terminated string of up to 3 characters

Definition at line 330 of file SM130.cpp.


Field Documentation

byte address

I2C address (default 0x42).

Definition at line 69 of file SM130.h.

const byte CMD_ANTENNA_POWER = 0x90 [static]

Definition at line 61 of file SM130.h.

const byte CMD_AUTHENTICATE = 0x85 [static]

Definition at line 52 of file SM130.h.

const byte CMD_DEC_VALUE = 0x8e [static]

Definition at line 60 of file SM130.h.

const byte CMD_HALT_TAG = 0x93 [static]

Definition at line 64 of file SM130.h.

const byte CMD_INC_VALUE = 0x8d [static]

Definition at line 59 of file SM130.h.

const byte CMD_READ16 = 0x86 [static]

Definition at line 53 of file SM130.h.

const byte CMD_READ_PORT = 0x91 [static]

Definition at line 62 of file SM130.h.

const byte CMD_READ_VALUE = 0x87 [static]

Definition at line 54 of file SM130.h.

const byte CMD_RESET = 0x80 [static]

Definition at line 48 of file SM130.h.

const byte CMD_SEEK_TAG = 0x82 [static]

Definition at line 50 of file SM130.h.

const byte CMD_SELECT_TAG = 0x83 [static]

Definition at line 51 of file SM130.h.

const byte CMD_SET_BAUD = 0x94 [static]

Definition at line 65 of file SM130.h.

const byte CMD_SLEEP = 0x96 [static]

Definition at line 66 of file SM130.h.

const byte CMD_VERSION = 0x81 [static]

Definition at line 49 of file SM130.h.

const byte CMD_WRITE16 = 0x89 [static]

Definition at line 55 of file SM130.h.

const byte CMD_WRITE4 = 0x8b [static]

Definition at line 57 of file SM130.h.

const byte CMD_WRITE_KEY = 0x8c [static]

Definition at line 58 of file SM130.h.

const byte CMD_WRITE_PORT = 0x92 [static]

Definition at line 63 of file SM130.h.

const byte CMD_WRITE_VALUE = 0x8a [static]

Definition at line 56 of file SM130.h.

boolean debug

debug mode, prints all I2C communication to Serial port

Definition at line 68 of file SM130.h.

const byte MIFARE_1K = 2 [static]

Definition at line 45 of file SM130.h.

const byte MIFARE_4K = 3 [static]

Definition at line 46 of file SM130.h.

const byte MIFARE_ULTRALIGHT = 1 [static]

Definition at line 44 of file SM130.h.

byte pinDREADY

DREADY pin (default 4).

Definition at line 71 of file SM130.h.

byte pinRESET

RESET pin (default 3).

Definition at line 70 of file SM130.h.

const int VERSION = 1 [static]

version of this library

Definition at line 42 of file SM130.h.


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

Generated on Mon May 11 17:40:05 2009 for SM130 Library by  doxygen 1.5.9