From d8137cc4bc3436e0d17fb86e7718b930db5732e7 Mon Sep 17 00:00:00 2001 From: Chris Liechti Date: Thu, 3 Sep 2015 23:09:16 +0200 Subject: doc update --- documentation/shortintro.rst | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/documentation/shortintro.rst b/documentation/shortintro.rst index 6b0d81f..e08f737 100644 --- a/documentation/shortintro.rst +++ b/documentation/shortintro.rst @@ -5,25 +5,24 @@ Opening serial ports ==================== -Open port 0 at "9600,8,N,1", no timeout:: +Open port at "9600,8,N,1", no timeout:: >>> import serial - >>> ser = serial.Serial(0) # open first serial port + >>> ser = serial.Serial('/dev/ttyUSB0') # open serial port >>> print(ser.name) # check which port was really used >>> ser.write(b"hello") # write a string >>> ser.close() # close port Open named port at "19200,8,N,1", 1s timeout:: - >>> ser = serial.Serial('/dev/ttyS1', 19200, timeout=1) - >>> x = ser.read() # read one byte - >>> s = ser.read(10) # read up to ten bytes (timeout) - >>> line = ser.readline() # read a '\n' terminated line - >>> ser.close() + >>> with serial.Serial('/dev/ttyS1', 19200, timeout=1) as ser: + ... x = ser.read() # read one byte + ... s = ser.read(10) # read up to ten bytes (timeout) + ... line = ser.readline() # read a '\n' terminated line -Open second port at "38400,8,E,1", non blocking HW handshaking:: +Open port at "38400,8,E,1", non blocking HW handshaking:: - >>> ser = serial.Serial(1, 38400, timeout=0, + >>> ser = serial.Serial('COM3', 38400, timeout=0, ... parity=serial.PARITY_EVEN, rtscts=1) >>> s = ser.read(100) # read up to one hundred bytes ... # or as much is in the buffer @@ -35,14 +34,14 @@ Get a Serial instance and configure/open it later:: >>> ser = serial.Serial() >>> ser.baudrate = 19200 - >>> ser.port = 0 + >>> ser.port = 'COM1' >>> ser Serial(port='COM1', baudrate=19200, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=0, rtscts=0) >>> ser.open() - >>> ser.isOpen() + >>> ser.is_open True >>> ser.close() - >>> ser.isOpen() + >>> ser.is_open False Readline -- cgit v1.2.1