簡體   English   中英

將數據保存在列 Python DS18B20

[英]Save Data in a Column Python DS18B20

我的 Python 數據代碼保存了溫度傳感器(DS18B20)的數據,但沒有將溫度保存在列中。 溫度寫成這樣的一行:['25.25']。 有人可以告訴我如何解決它。 我必須將讀取的溫度從傳感器分成幾個數字。 謝謝你的幫助

    while programmStatus == 1:
    #while True:
            now = datetime.now(timezoneBerlin)
                
#while True:
    # open new file
            with open ( 'test.tsv', 'w') as f:
                for temperature_single in Temperature:
                    f.write ("{:>5}\n".format('Temperature'))    
                    f.write("\t{:>5}\n".format 
                    (format(temperature_single)))
                    f.write("\n")
                    f.flush()
                    f.close()
   
                x = 0
                ds1820readout()
                print ("Sensorname und Temperaturevalue:")
                while x < tempSensorQuantity:
                    print (tempSensorName[x] , " " , tempSensorValue[x], " °C")
                    x = x + 1
print ("\n")

在這段代碼中,關閉文件有一個 I/0 錯誤,有人可以幫忙嗎?

似乎溫度是一個值列表。 如果您嘗試將它們放入 csv 中,您必須先遍歷列表,例如:

tempSensorName = []
tempSensorQuantity = 0 
tempSensorValue = [] 
programmStatus = 1
Temperature = tempSensorValue   

def ds1820einlesen():
    global tempSensorName, tempSensorQuantity, programmStatus 
def ds1820auslesen():
    global tempSensorName, tempSensorQuantity, tempSensorValue,              
            with open ( 'test.tsv', 'w') as f:
                for temperature_single in Temperature:
                    f.write ("{:>5}\n".format('Temperature'))    
                    f.write("\t{:>5}\n".format(format(temperature_single)))
                    f.write("\n")
                    f.flush()
                    f.close()
    
                    x = 0
                    ds1820auslesen()
                    print ("Sensorname and Temperaturevalue:")
                    while x < tempSensorQuantity:
                        print (tempSensorName[x] , " " ,
    tempSensorValue[x], " °C")
                            x = x + 1
    print ("\n")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM