I’m snagged on a little bug with Py code for RasPi3. Two strings (one from RFID badge and the other read in from a .txt file) should be equal and evaluate to True when compared. I’ve tried ==, is, and trimmed any white space. Below is the code with the troublemaker line marked with a comment above it.
Apologies for the copy and paste job… can’t figure out how to paste it properly here
import serial
serial = serial.Serial("/dev/ttyUSB0", baudrate=9600)
scannedBadgeID = ‘’
hasScannedBadgeID = False
scannedBadgeApproved = False
fileLines = []
filename = “/home/pi/HoodUsers.txt”
def populateDataBase():
try:
with open(filename,‘r’) as myFile:
for line in myFile:
fileLines.append(line)
except IOError:
print(“Error: File does not appear to exist.”)
return
while True:
while not hasScannedBadgeID:
data = serial.read()
if "x03" in str(data):
hasScannedBadgeID = True
scannedBadgeID = scannedBadgeID.replace("'","").replace("b","").replace("\\x02","").replace("\\r\\n","").strip()
else:
scannedBadgeID = scannedBadgeID + str(data)
populateDataBase()
print(scannedBadgeID)
for line in fileLines:
lineSplit = line.split("|")
userBadgeID = lineSplit[1].strip()
print("1: " + scannedBadgeID)
print("2: " + userBadgeID)
print("3: " + userBadgeID is scannedBadgeID)
print()
##########Line Below is where error is##########
if(scannedBadgeID is userBadgeID)
print(userName)
userName = lineSplit[0]
userStatus = lineSplit[2]
userActiveStatus = lineSplit[3]
scannedBadgeApproved = True
break
else:
userBadgeID = ""
cont = input("Carry On?")
hasScannedBadgeID = False
scannedBadgeID = ""
fileLines = []