Rfid

class Rfid(port='/dev/ttyAMA0', baudrate=9600)[source]

Bases: object

Handles RFID reader communication via serial port.

port

Serial port path.

Type:

str

baudrate

Serial baudrate.

Type:

int

multiple

Whether multiple tags where detected recently-ish.

Type:

bool

time_detections

Time window in seconds to check for duplicate IDs.

Type:

float

id

The most recently read RFID tag ID.

Type:

str

id_history

History of read IDs and timestamps.

Type:

Deque[tuple[str, datetime]]

reading

Flag to control reading loop (not used in loop, running is used).

Type:

bool

s

The serial connection.

Type:

serial.Serial

thread

Background thread for reading serial data.

Type:

threading.Thread

running

Flag to control the background thread.

Type:

bool

__init__(port='/dev/ttyAMA0', baudrate=9600) None[source]

Initializes the RFID reader.

Parameters:
  • port (str) – Serial port. Defaults to “/dev/ttyAMA0”.

  • baudrate (int) – Baudrate. Defaults to 9600.

Methods

__init__([port, baudrate])

Initializes the RFID reader.

clean_old_ids()

Removes IDs from history that are older than time_detections.

get_id()

Retrieves the current RFID tag ID and multiple status.

read_serial()

Reads data from the serial port in a background loop.

stop()

Stops the serial reading thread.

update_multiple()

Updates the multiple flag if more than one unique ID is in history.

read_serial() None[source]

Reads data from the serial port in a background loop.

clean_old_ids() None[source]

Removes IDs from history that are older than time_detections.

update_multiple() None[source]

Updates the multiple flag if more than one unique ID is in history.

stop() None[source]

Stops the serial reading thread.

get_id() tuple[str, bool][source]

Retrieves the current RFID tag ID and multiple status.

Returns:

A tuple containing the ID (str) and whether multiple tags were detected (bool).

Returns (“”, False) if reading is disabled.

Return type:

tuple[str, bool]