PyRFID

Available translations: de

PyRFID is a Python library for using a 125kHz UART RFID reader that uses the EM4100 protocol. The cheap RDM6300 RFID reader was used during development. PyRFID is also used in PAM RFID.

Important: The RFID reader must support the EM4100 protocol to use PyRFID!

The reader is connected to host computer using an USB-TTL converter (see also PAM RFID). PySerial is used for the serial communication.

Each read process results in an exchange of a data packet which contains the RFID tag information.

Data packet

A data packet consists of 10 bytes of user data and a 2-byte checksum. The beginning and end of such a packet is marked by two single bytes. The format of a single data packet looks like this:

0x02 5 Hex-data Checksum 0x03
  • 0x02: Marks the beginning (length is 1 byte)
  • 5 Hex-data: RFID tag number in hexadecimal encoding (length is 10 byte; 1 hex = 2 byte)
  • Checksum: Checksum of the data packet (length is 2 byte)
  • 0x03: Marks the end (length 1 byte)

A checksum is calculated to check whether the RFID tag number has been transmitted correctly.

Checksum

After each data packet has been fully received the checksum is calculated using an XOR operation:

(1. hex number) XOR (2. hex number) XOR (3. hex number) XOR (4. hex number) XOR (5. hex number)

The result of this operation is compared against the received checksum. If the calculated checksum matches the received checksum the data packet was successfully transmitted and can be further processed. To read out the checksum PyRFID provides the method tagChecksum().

Tag types

An RFID tag also contains a flag for determining the type. This flag is used differently by manufacturers of RFID tags and is located at the beginning of the tag number. To read the type flag PyRFID provides the Python properties tagType and tagTypeFloat.

Formats

There are more possibilities to format a RFID tag number:

  • Hexadecimal: Bytes 0 to 9 are used raw e.g. 0F00789A62. To get the data in raw format use the method rawTag().
  • Floating point: Bytes 2 to 5 are used as number before comma and bytes 6 to 9 are used number after comma e.g. 120.39522. To get data as float use the method tagIdFloat().
  • Decimal: Bytes 4 to 9 are used and padded with zeros from left side to fit length 10 e.g. 0007903842. To get the data in this format use the methode tagId().

How to read a tag

To read a tag PyRFID provides the method readTag(). This method blocks until a tag has been read. An example can be found in /usr/share/doc/python-rfid/examples/.

Installation

After adding the PM Code Works APT repository to the system package sources, the package can be installed for Python 2 using following command:

~# apt-get install python-rfid

For Python 3 use following command:

~# apt-get install python3-rfid

Install missing dependencies:

~# apt-get install -f

As an alternative PyRFID is offered as ZIP archive.