'I can't handle this Error TypeError: can't concat str to bytes
import time import serial import sys SCREEN_DISPLAY=True SAVE_TO_FILE=True
txtfile = open('datafile.csv','rb')
serialport = serial.Serial('COM5',timeout=20,baudrate=9600)
while True:
sensordata = serialport.readline().decode('ascii')
timenow = time.strftime("Date: %Y-%m-%d // Time: %H:%M:%S // Temperature: ")
if SCREEN_DISPLAY: print(str.encode(timenow)+sensordata)
time.sleep(0.05)
if SAVE_TO_FILE: txtfile.write(str.encode(timenow)+sensordata)
serialport.close() txtfile.close()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
