Last active
August 9, 2021 08:26
-
-
Save cooncesean/5961086 to your computer and use it in GitHub Desktop.
Sample script to loop indefinitely and look for RFID tags using pyserial.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# `serial` refers to the pyserial library which can be found here: http://pyserial.sourceforge.net/ | |
import serial | |
BAUD_RATE = 9600 | |
RFID_BYTES = 12 | |
START_CHAR = '\x02' | |
ser = serial.Serial('/dev/tty.usbserial-AH01D7DV', BAUD_RATE) | |
while True: | |
print 'Wating for RFID Tag......' | |
# Wait until a tag is read | |
rfid = ser.read(RFID_BYTES) | |
rfid = str(rfid.strip(START_CHAR)) | |
# Only act if we think we have a valid tag | |
if len(rfid) == (RFID_BYTES - 1): | |
print 'Tag Found', rfid | |
# Logic to do things with the RFID tag ..... | |
# Flush the bus | |
ser.flushInput() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment