Organize project: Move old code and documentation to oldcode folder, add comprehensive README
This commit is contained in:
52
rfid_module.py
Normal file
52
rfid_module.py
Normal file
@@ -0,0 +1,52 @@
|
||||
"""
|
||||
RFID reader initialization and handling
|
||||
"""
|
||||
|
||||
import logging
|
||||
from config_settings import SERIAL_DEVICES, CONFIG_CARD_ID
|
||||
from logger_module import log_with_server
|
||||
|
||||
|
||||
def initialize_rfid_reader():
|
||||
"""
|
||||
Initialize RFID reader with multiple device attempts and error handling
|
||||
|
||||
Returns:
|
||||
Reader object or None if initialization fails
|
||||
"""
|
||||
try:
|
||||
from rdm6300 import Reader
|
||||
except ImportError:
|
||||
print("✗ rdm6300 module not installed")
|
||||
return None
|
||||
|
||||
print("Initializing RFID reader...")
|
||||
|
||||
for device in SERIAL_DEVICES:
|
||||
try:
|
||||
print(f"Attempting to initialize RFID reader on {device}...")
|
||||
r = Reader(device)
|
||||
r.start()
|
||||
print(f"✓ RFID reader successfully initialized on {device}")
|
||||
return r
|
||||
|
||||
except FileNotFoundError:
|
||||
print(f"✗ Device {device} not found")
|
||||
continue
|
||||
except PermissionError:
|
||||
print(f"✗ Permission denied for {device}")
|
||||
print(f" Hint: Try adding user to dialout group: sudo usermod -a -G dialout $USER")
|
||||
continue
|
||||
except Exception as e:
|
||||
print(f"✗ Failed to initialize on {device}: {e}")
|
||||
continue
|
||||
|
||||
# If we get here, all devices failed
|
||||
print("✗ Could not initialize RFID reader on any device")
|
||||
print("Available solutions:")
|
||||
print(" 1. Check hardware connections")
|
||||
print(" 2. Enable UART: sudo raspi-config -> Interface Options -> Serial")
|
||||
print(" 3. Add user to dialout group: sudo usermod -a -G dialout $USER")
|
||||
print(" 4. Reboot the system after making changes")
|
||||
|
||||
return None
|
||||
Reference in New Issue
Block a user