def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.SetSize((480, 320)) self.SetTitle('Baroness Control') self.panelStart = PanelStart(self) self.panelDrinks = PanelDrinks(self) self.panelUsers = PanelUsers(self) self.panelThanks = PanelThanks(self) self.panelSorry = PanelSorry(self) self.panelRFID = PanelRFID(self) if settings.enableRFID: self.rfid = rfid.RFID(self.on_rfid) self.user = User() self.rfidid = "" self.drinkl = "" self.active = 0 self.switchPanels() self.Show()
import serial import rfid import gpiozero lock = gpiozero.LED(17) #lock is GPIO GP17, LED class must be used rfid_permission_led = gpiozero.LED(18) #LED to flash if not authenticated ser = serial.Serial( port='/dev/ttyS0', baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1 ) while True: raw_data = ser.readline() #read serial port until a '\n' termination byte is recieved rfid_message = rfid.RFID(raw_data) #pass raw_data to new instance object 'rfid_message' if rfid_message.authenticate == 1: #if authenticated for access, unlock #lock.on() #lock will unlock for 5 seconds print(raw_data) print('RFID: ' + str(rfid_message.rfid_requesting_access)) print('Access granted!') elif len(raw_data) == 0: #if no data is present(timeout reached), do nothing. pass else: rfid_permission_led.blink(0.6, 0.4, 4) #blink on for 0.6seconds, off, for 0.4 seconds, blink 4 times print('No Access')
import rfid import rfid.t5577 import matplotlib.pyplot as plt data = bytes([0, 0, 0x03, 0x55] * 7) print("Writing", rfid.pretty_bytes(data)) print("Writing", rfid.bytes_to_binary_string(data)) data_sorted = rfid.binary_string_to_bytes(rfid.sort_cycle(rfid.bytes_to_binary_string(data), False)) if data_sorted != data: print("Warning! Data cycles to", rfid.pretty_bytes(data_sorted)) r = rfid.RFID() samples = rfid.t5577.write_card_basic(data, bit_width=50, modulation="fsk2a") r.raw_write(samples) samples = r.raw_read(2**15) samples_demod = rfid.fsk_demodulator(samples, p0=8, p1=10) (decoded_bits, decoded_waveform) = rfid.decoder(samples_demod, bit_width=50) plt.plot(samples_demod) plt.plot(decoded_waveform) plt.show() cycles = rfid.find_cycles(rfid.thresh(decoded_bits), length=96) for cycle in cycles: cycle_bytes = rfid.binary_string_to_bytes(rfid.sort_cycle(cycle, False)) if cycle_bytes == data_sorted: print("Read back OK!") else: print("Bad read:", rfid.pretty_bytes(cycle_bytes)) print("Bad read", rfid.bytes_to_binary_string(cycle_bytes))
import rfid test = rfid.RFID() cartao = test.read() print(cartao)