Advertisement
Guest User

Untitled

a guest
Nov 4th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import pymysql
  2. import datetime
  3. import serial
  4. from time import sleep
  5.  
  6. # coding: utf8
  7.  
  8.  
  9. ser = serial.Serial('/dev/ttyUSB1', 9600, timeout=0)
  10.  
  11.  
  12. connection = pymysql.connect(host='localhost',
  13. user='root',
  14. password='',
  15. db='fsae',
  16. charset='utf8mb4')
  17.  
  18. while True:
  19. while (ser.inWaiting() == 0):
  20. pass
  21. data = ser.readline(9600).strip('\r\n')
  22. parsed = data.split(',')
  23. print
  24. data
  25.  
  26. # try:
  27. # with connection.cursor() as cursor:
  28. # # Novo recorde
  29. # sql = "INSERT INTO pequena (seno,cosseno) VALUES (%s,%s)"
  30. # cursor.execute(sql, (seno, cosseno))
  31. #
  32. # connection.commit()
  33. # finally:
  34. # pass
  35. # if len(parsed)==2:
  36. # packet.append(parsed)
  37. # if len(packet)==10:
  38. # print packet
  39. # for i in range(10):
  40. # cursor = conn.cursor()
  41. # cursor.execute("INSERT INTO testes5 VALUES (%s, %s)", (packet[i][0], packet[i][1]))
  42. # conn.commit()
  43. # print "mysql upload", i+1
  44. # packet=[]
  45. # else:
  46. # print "data com mais de 2 colunas"
  47. # sleep(0.1)
  48.  
  49.  
  50.  
  51. connection.close()
  52. ser.close()
  53.  
  54. # assyncio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement