Advertisement
Guest User

Untitled

a guest
Nov 5th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import serial
  3. import mysql.connector
  4.  
  5. SERIALPORT = "/dev/tty.wchusbserial410" #serial port on mac
  6. SERIALRATE = 9600
  7.  
  8. ser = serial.Serial(SERIALPORT, SERIALRATE)
  9. conn = mysql.connector.connect(host='localhost', database='drinkDispenser', user='root', password='root')
  10. if conn.is_connected():
  11.     print('Connected to MySQL database')
  12.  
  13. cursor = conn.cursor()
  14. print ("connection OK, cursor OK")
  15.  
  16. while 1:
  17.     serial_line = ser.readline()
  18.     if(serial_line != "GO_BLINK"):
  19.         IDCardReadLine = ser.readline()
  20.         print(IDCardReadLine) #del this line - only show the tag ID
  21.        
  22.         sqlSearchCardID = "SELECT idUser, nameUser, userCardID, isActive FROM Users WHERE userCardID LIKE = %s" %(IDCardReadLine)
  23.         sqlSearchName = "SELECT nameUser FROM Users WHERE userCardID LIKE = %s" %(IDCardReadLine)
  24.  
  25.         if(sqlSearchCardID != '' and sqlSearchName != ''):
  26.             sqlQueryInsertData = "INSERT INTO Records (idRecord, recordData, recordDateTime, userCardID) VALUES (NULL, 'Registo ok por: %s', CURRENT_TIMESTAMP, '%s')" %(IDCardReadLine, IDCardReadLine)
  27.             cursor.execute(sqlQueryInsertData)
  28.             conn.commit()
  29.         else:
  30.             print "Error"
  31.            
  32.     ser.flush()
  33.  
  34.  
  35. cursor.close()
  36. ser.close()
  37. conn.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement