serial(drvname=SERIAL0, baud=115200, stopbits=STOPBIT_1, parity=PARITY_NONE, bitsize=BITSIZE_8, rxsize=0, txsize=0, mode=MODE_UART, flow_ctrl=HW_FLOWCTRL_DISABLE):
This class implements a stream that can be used to connect to a serial port.
Initialize the serial port driver identified by
drivername and starts it up with a baud rate of
baud. Additional parameters can be passed such as:
txsize: the size in bytes of the receive and transmit buffers (0 selects the OS default)
This is the code needed to print something on the default serial port:
import serial # create a serial stream linked to SERIAL0 port ser = serial.serial() # print will output everything to it if passed as stream print("Hello World!",stream=ser)
Returns the number of characters that can be read without blocking.
Close the serial port.
Writes the content of buffer to the serial.
buffer must be a byte sequence (bytes, bytearray or string).
Returns the number of bytes actually written to the stream (can be less than the elements in
Reads at most
size bytes from the serial and returns a bytearray with the actual bytes read.
read blocks if no bytes are available in the stream.
read returns an empty bytearray the underlying stream can be considered disconnected.
readline(max_len=256, end="\r\n", with_end=True, timeout=-1)
Reads a line from the serial, ending with
end marker string, of
max_len bytes length, and returns a bytearray with the actual bytes read.
with_end is True, the returning line contains the
end marker as well.
timeout is positive, the function will return after
timeout milliseconds if the line is not read.