-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread.py
More file actions
43 lines (36 loc) · 1.06 KB
/
read.py
File metadata and controls
43 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
import serial
import mysql.connector
cnx = mysql.connector.connect(
host="localhost",
user="root",
database="uids"
)
cursor = cnx.cursor()
cursor.execute("SELECT * FROM validUids")
results = cursor.fetchall()
ser = serial.Serial(
port='COM4', #plz change this according to your port number
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
ser.flush()
if __name__ == '__main__':
valid = False
while True:
if ser.in_waiting > 0:
line = ser.readline().decode('utf-8').rstrip()
for uid in results:
print("row: ",uid[0])
if(uid[0].strip() == line.strip()):
valid = True
ser.write('Wow......'.encode())
if(valid):
print('UID is valid')
valid= False
else:
ser.write('Not working....'.encode())
print("UID is invalid, Sorry!")