Skip to content

Commit c5e7433

Browse files
sirhceleldruin
authored andcommitted
Add hint do setting DTR on open to README
1 parent d164f36 commit c5e7433

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

README.md

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,46 +42,57 @@ It should also be noted that on macOS, both the Callout (`/dev/cu.*`) and Dial-i
4242

4343
# Usage
4444

45-
Listing available ports:
45+
## Listing Available Ports:
4646

4747
```rust
4848
let ports = serialport::available_ports().expect("No ports found!");
4949
for p in ports {
5050
println!("{}", p.port_name);
5151
}
52-
5352
```
5453

55-
Opening and configuring a port:
54+
## Opening and Configuring a Port
5655

5756
```rust
5857
let port = serialport::new("/dev/ttyUSB0", 115_200)
5958
.timeout(Duration::from_millis(10))
60-
.open().expect("Failed to open port");
59+
.open()
60+
.expect("Failed to open port");
6161
```
62+
Some platforms expose additional functionality, which is opened using the `open_native()` method:
6263

63-
Writing to a port:
64+
```rust
65+
let port = serialport::new("/dev/ttyUSB0", 115_200)
66+
.open_native()
67+
.expect("Failed to open port");
68+
```
69+
There are devices which wait for DTR before sending any data. Configure
70+
automatically setting DTR when opening a port by the builder:
6471

6572
```rust
66-
let output = "This is a test. This is only a test.".as_bytes();
67-
port.write(output).expect("Write failed!");
73+
let port = serialport::new("/dev/ttyUSB0", 115_200)
74+
.dtr_on_open(true)
75+
.open()
76+
.expect("Failed to open port");
6877
```
6978

70-
Reading from a port (default is blocking with a 0ms timeout):
79+
## Writing to a Port
7180

7281
```rust
73-
let mut serial_buf: Vec<u8> = vec![0; 32];
74-
port.read(serial_buf.as_mut_slice()).expect("Found no data!");
82+
let output = "This is a test. This is only a test.".as_bytes();
83+
port.write(output).expect("Write failed!");
7584
```
7685

77-
Some platforms expose additional functionality, which is opened using the `open_native()` method:
86+
## Reading from a Port
87+
88+
The port operates in blocking mode with a default timeout of 0 ms.
7889

7990
```rust
80-
let port = serialport::new("/dev/ttyUSB0", 115_200)
81-
.open_native().expect("Failed to open port");
91+
let mut serial_buf: Vec<u8> = vec![0; 32];
92+
port.read(serial_buf.as_mut_slice()).expect("Found no data!");
8293
```
8394

84-
Closing a port:
95+
## Closing a Port
8596

8697
`serialport-rs` uses the Resource Acquisition Is Initialization (RAII) paradigm and so closing a
8798
port is done when the `SerialPort` object is `Drop`ed either implicitly or explicitly using

0 commit comments

Comments
 (0)