Advertisement
Guest User

Untitled

a guest
Feb 20th, 2013
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. import serial
  2. from struct import pack
  3. from time import sleep
  4.  
  5. user = {"\x00\x01\x02\x03\x04" : "Arnaud",
  6.         "\x05\x06\x07\x07\x08" : "Florent"}
  7.  
  8. def formatText(msg):
  9.     msg = '{s:{c}^{n}}'.format(s=msg,n=16,c=' ')
  10.     return "\xAB\x04" + pack("B", len(msg)) + msg
  11.  
  12. arduino = serial.Serial('/dev/ttyACM0', 9600)
  13. arduino.setDTR(level=False)
  14. sleep(2)
  15.  
  16. pingReq = "\xAB\x00\x00"
  17. clearReq = "\xAB\x04\x01\xAB"
  18.  
  19. arduino.write(pingReq);
  20. receive = arduino.read(3);
  21.  
  22. if(receive == "\xAB\x01\x00"):
  23.     print "Receive ping response"
  24.  
  25. arduino.write(formatText("PASSEZ VOTRE"));
  26. arduino.write(formatText("CARTE"));
  27.  
  28. rfidIdentReq = "\xAA\x00\x03\x25\x26\x00\x00\xBB"
  29. rfidReq = "\xAB\x02" + pack("B", len(rfidIdentReq)) + rfidIdentReq
  30.  
  31. while 1:
  32.     arduino.write(rfidReq)
  33.     ABheader = arduino.read(3)
  34.  
  35.     raw = arduino.read(3)
  36.     length = ord(raw[2])
  37.  
  38.     raw += arduino.read(length + 2)
  39.    
  40.     code = raw[5:10]
  41.     # for i in raw:
  42.     #     print hex(ord(i)),
  43.     # print
  44.    
  45.     if length == 6:
  46.         break
  47.     sleep(0.6)
  48.  
  49. for i in code:
  50.     print hex(ord(i)),
  51. print
  52. arduino.write(clearReq)
  53. arduino.write(formatText("MERCI"))
  54. arduino.write(formatText(user[code]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement