diff options
author | Chris Liechti <cliechti@gmx.net> | 2015-10-12 23:19:04 +0200 |
---|---|---|
committer | Chris Liechti <cliechti@gmx.net> | 2015-10-12 23:19:04 +0200 |
commit | a1436b1378aec9c83ff11f66a6f2cd4b82ee1927 (patch) | |
tree | 7eb63ef5017d9fa8cffc3d3ee2db5549058ae6b0 | |
parent | 94247bc2aa918a53b5366b868e8d9b88d7d02b1e (diff) | |
download | pyserial-git-a1436b1378aec9c83ff11f66a6f2cd4b82ee1927.tar.gz |
doc update (add example)
-rw-r--r-- | documentation/pyserial_api.rst | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/documentation/pyserial_api.rst b/documentation/pyserial_api.rst index 411a832..c23d837 100644 --- a/documentation/pyserial_api.rst +++ b/documentation/pyserial_api.rst @@ -1104,6 +1104,27 @@ This module provides classes to simplify working with threads and protocols. Closes serial port. +Example:: + + class PrintLines(LineReader): + def connection_made(self, transport): + super(PrintLines, self).connection_made(transport) + sys.stdout.write('port opened\n') + self.write_line('hello world') + + def handle_line(self, data): + sys.stdout.write('line received: {}\n'.format(repr(data))) + + def connection_lost(self, exc): + if exc: + traceback.print_exc(exc) + sys.stdout.write('port closed\n') + + ser = serial.serial_for_url('loop://', baudrate=115200, timeout=1) + with SerialPortWorker(ser, PrintLines) as protocol: + protocol.write_line('hello') + time.sleep(2) + asyncio ======= |