From 9ad044afd3ba15749178adb27af2591f2bb1c054 Mon Sep 17 00:00:00 2001 From: Chris Liechti Date: Thu, 17 Dec 2015 19:43:59 +0100 Subject: doc update --- documentation/pyserial_api.rst | 4 +++- documentation/shortintro.rst | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/documentation/pyserial_api.rst b/documentation/pyserial_api.rst index 1b15762..a3f2ae8 100644 --- a/documentation/pyserial_api.rst +++ b/documentation/pyserial_api.rst @@ -139,7 +139,9 @@ Native ports In case a write timeout is configured for the port and the time is exceeded. - Write the string *data* to the port. + Write the bytes *data* to the port. This should be of type ``bytes`` + (or compatible such as ``bytearray`` or ``memoryview``). Unicode + strings must be encoded (e.g. ``'hello'.encode('utf-8'``). .. versionchanged:: 2.5 Accepts instances of :class:`bytes` and :class:`bytearray` when diff --git a/documentation/shortintro.rst b/documentation/shortintro.rst index e08f737..4cbdda7 100644 --- a/documentation/shortintro.rst +++ b/documentation/shortintro.rst @@ -10,7 +10,7 @@ Open port at "9600,8,N,1", no timeout:: >>> import serial >>> 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.write(b'hello') # write a string >>> ser.close() # close port Open named port at "19200,8,N,1", 1s timeout:: @@ -44,6 +44,15 @@ Get a Serial instance and configure/open it later:: >>> ser.is_open False +Also supported with context manager:: + + serial.Serial() as ser: + ser.baudrate = 19200 + ser.port = 'COM1' + ser.open() + ser.write(b'hello') + + Readline ======== Be carefully when using :meth:`readline`. Do specify a timeout when opening the -- cgit v1.2.1