python-SQL从串行连接插入数据
发布时间:2022-06-12 15:55:29 360
相关标签: # node.js
我一直在谷歌上搜索,但我似乎无法正确地找到它。
目的:创建功能数据库。我已关闭模式,并将来自COM3的数据插入到测试2数据库表中。
import sqlite3
import serial
import time
#
con = sqlite3.connect('Sensors Database.db')
cur = con.cursor()
# # Create table Scheme-MESSDATA
#
# cur.execute('''CREATE TABLE Test2
# (MESSID TEXT NOT NULL,gps_date TEXT NOT NULL,latitude REAL NOT NULL ,longitude REAL NOT NULL,alt REAL NOT NULL,actual_date TEXT NOT NULL,standard_pm1_0 INTEGER,standard_pm2_5 REAL,standard_pm10 REAL,atmospheric_pm1_0 REAL,atmospheric_pm2_5 REAL,atmospheric_pm10 REAL ,pm1_gt_3 REAL,pm1_gt_5 REAL,pm1_gt_10 REAL,pm1_gt_25 REAL,pm1_gt_50 REAL,pm1_gt_100 REAL,Temperature REAL, Humidity NUB,Pressure REAL ,Voc NUB)''')
con.commit()
ser = serial.Serial(
port='COM3', # /dev/ttyUSB0', for Linux systems
baudrate=57600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
while True:
try:
ser.flushInput()
podDdataIn: bytes = ser.readline()
print(podDdataIn)
if podDdataIn[:9] == "MESSKIT0R":
print(podDdataIn)
if podDdataIn[:9] == "MESSKIT02":
print(podDdataIn)
cur.execute(
'''INSERT INTO Test2 VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')''')
con.commit()
time.sleep(1)
ser.flushInput()
ser.write(podDdataIn)
except KeyboardInterrupt:
ser.close()
break
con.commit()
#
con.close()
问题:它提交“字符串”数据,但不是实际的串行数据。是正确的运算符,或者必须将列映射到串行接口的值。可能是操作员搞错了?
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报