You can download this code by clicking the button below.
This code is now available for download.
This function reads data from a specified serial port and returns the read data as a string.
Technology Stack : PySerial
Code Type : Function
Code Difficulty : Intermediate
def read_serial_data(port, baudrate, timeout=1):
import serial
ser = serial.Serial(port, baudrate, timeout=timeout)
data = ser.read_all().decode('utf-8')
ser.close()
return data