@@ -42,46 +42,57 @@ It should also be noted that on macOS, both the Callout (`/dev/cu.*`) and Dial-i
42
42
43
43
# Usage
44
44
45
- Listing available ports :
45
+ ## Listing Available Ports :
46
46
47
47
``` rust
48
48
let ports = serialport :: available_ports (). expect (" No ports found!" );
49
49
for p in ports {
50
50
println! (" {}" , p . port_name);
51
51
}
52
-
53
52
```
54
53
55
- Opening and configuring a port:
54
+ ## Opening and Configuring a Port
56
55
57
56
``` rust
58
57
let port = serialport :: new (" /dev/ttyUSB0" , 115_200 )
59
58
. timeout (Duration :: from_millis (10 ))
60
- . open (). expect (" Failed to open port" );
59
+ . open ()
60
+ . expect (" Failed to open port" );
61
61
```
62
+ Some platforms expose additional functionality, which is opened using the ` open_native() ` method:
62
63
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:
64
71
65
72
``` 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" );
68
77
```
69
78
70
- Reading from a port (default is blocking with a 0ms timeout):
79
+ ## Writing to a Port
71
80
72
81
``` 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 !" );
75
84
```
76
85
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.
78
89
79
90
``` 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! " );
82
93
```
83
94
84
- Closing a port:
95
+ ## Closing a Port
85
96
86
97
` serialport-rs ` uses the Resource Acquisition Is Initialization (RAII) paradigm and so closing a
87
98
port is done when the ` SerialPort ` object is ` Drop ` ed either implicitly or explicitly using
0 commit comments