Read Serial Port Data by Bytes

  • Share this:

Code introduction


This function is used to read a specified number of bytes from a specified serial port.


Technology Stack : PySerial

Code Type : Function

Code Difficulty : Intermediate


                
                    
def read_serial_port(port_name, baud_rate, bytes_to_read):
    import serial
    ser = serial.Serial(port_name, baud_rate)
    data = ser.read(bytes_to_read)
    ser.close()
    return data                
              
Tags: