2014-09-26 50 views
1

我有一個串行連接的逗號分隔的靜態輸出。傳入的數據將始終有23個值。使用Python 3.4將標題添加到逗號分隔字符串中

# 「987654321」, 「 」「」,0.00,0.00,0.30,0.06,0.35,0.50,2.00,0.50,0.00:從機

數據串,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,3.71

import serial 

con=serial.Serial('COM4',115200) 

while 1: 

    if con.inWaiting(): 

     val = con.read(con.inWaiting()) 

     if len(val)> 1 : 
      stra = val.decode("utf-8") 

我接收數據並且可以查看數據到驗證它是正確的。試圖列標題添加到字符串時,我失去了這樣的數據可以被插入到數據庫

我使用的是樹莓派到本機運行和數據庫

列標題之間的程序: 批次ID,子ID,Grand ID,Value4,Value5,Dime,Penny,Nickel,Quarter,美元,Half,Value12,Value13,Value14,Value15,Value16,Value17,Value18,Value19,Value20,Value21,Value22,合計

Raspberry Pi上的數據庫將是MySQL,當單元連接到網絡時,它將被上傳到SQL Sever

+0

什麼列標題?什麼數據庫?請[編輯]澄清你的問題。 – davidism 2014-09-26 14:35:53

回答