@@ -13,8 +13,7 @@ Example uses:
1313Has no dependencies other than the Python standard library.
1414
1515Only works on * nix type systems. Tested on Debian Linux, but should work on
16- others (macOS, BSD, etc.). For Windows, look at [ com0com] or
17- [ Virtual Serial Port Driver] .
16+ others (macOS, BSD, etc.). Windows support is being worked on.
1817
1918## Installation
2019
@@ -81,17 +80,33 @@ Now typing data on one terminal will appear in the other.
8180
8281## Use as a library
8382
84- ` virtualserialports.run(num_ports, loopback=False, debug=False) `
83+ As of version 2.0.0, much improved support has been added for use as a library,
84+ with processing done in the background.
8585
86- * * num_ports* : number of ports to create.
87- * * loopback* : whether to echo data back to the sender.
88- * * debug* : whether to print debugging info to stdout.
86+ It is recommended to use as a context manager, which will handle setup and
87+ clean up nicely:
8988
90- ### Example
89+ ``` python
90+ with VirtualSerialPorts(2 ) as ports:
91+ print (f ' Port 1: { ports[0 ]} ' )
92+ print (f ' Port 2: { ports[1 ]} ' )
9193
92- import virtualserialports
93- virtualserialports.run(2, loopback=True, debug=False)
94+ # Open and use ports as required.
95+ # When the context manager ends, ports will be removed.
96+ ```
9497
98+ ` ports ` is a list of strings, which can be used to open the ports, e.g with
99+ PySerial. A complete example is in example.py.
95100
96- [ com0com ] : https://sourceforge.net/projects/com0com/
97- [ Virtual Serial Port Driver ] : https://www.virtual-serial-port.org/
101+ It can also be used without a context manager as follows:
102+
103+ ``` python
104+ vsp = VirtualSerialPorts(2 )
105+ vsp.open()
106+ # `vsp.ports` is a list of strings of the created ports.
107+
108+ vsp.start()
109+ # Use ports as you wish here.
110+ vsp.stop()
111+ vsp.close()
112+ ```
0 commit comments