Important: The RFID reader must support the EM4100 protocol to use PyRFID!
Each read process results in an exchange of a data packet which contains the RFID tag information.
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: 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.
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
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
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
- 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
- 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
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
After adding the PM Code Works APT repository to the system package sources, the package can be installed for Python 2 using following command:
$ sudo apt-get install python-rfid
For Python 3 use following command:
$ sudo apt-get install python3-rfid
Install missing dependencies:
$ sudo apt-get install -f
As an alternative PyRFID is offered as ZIP archive.