当前位置: 移动技术网 > IT编程>数据库>Mysql > 通过读取串口数据,把数据写入MySQL

通过读取串口数据,把数据写入MySQL

2018年03月12日  | 移动技术网IT编程  | 我要评论

通过读取串口数据,把数据写入MySQL

import MySQLdb//定义引用数据库的驱动文件
import serial
import time
ser = serial.Serial('/dev/ttyATH0', 115200, timeout=65)//读串口
while True:
data = ser.readline()
print repr(data)//输出读到的数据
conn=MySQLdb.connect(host='192.168.2.1',user='root',passwd='root',db='ma'//连接数据库
cursor=conn.cursor()
sql= "insert into data(m_message) values(%s)"//插入数据库
pgg = data
pga = (pgg)
n = cursor.execute(sql,pga)
print n
print pgg
#print (time.strftime("%H:%M:%S"))

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网