Hi ,
I am trying to read a serial data and save that in a file. I could not print any data to the file.
I am trying to read a serial data and save that in a file. I could not print any data to the file.
from __future__ import print_function import serial, time, io, datetime from serial import Serial import time addr = "COM5" ## serial port to read data from baud = 921600 ## baud rate for instrument ser = serial.Serial( port = addr,\ baudrate = baud,\ parity=serial.PARITY_NONE,\ stopbits=serial.STOPBITS_ONE,\ bytesize=serial.EIGHTBITS,\ timeout=0) print("Connected to: " + ser.portstr) filename="data_file.txt" f = open("data_file.txt", "a") while True: s = ser.readline() line = s.decode('utf-8').replace('\r\n','') time.sleep(.1) f.write(line+"\r\n") # Appends output to fileCan someone help me. Thank you.