File tree Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ i2cdev = "0.4.1"
14
14
spidev = " 0.3.0"
15
15
sysfs_gpio = " 0.5.1"
16
16
serial-unix = " 0.4.0"
17
+ serial-core = " 0.4.0"
17
18
nb = " 0.1.1"
18
19
19
20
[dev-dependencies ]
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ pub extern crate i2cdev;
18
18
pub extern crate spidev;
19
19
pub extern crate sysfs_gpio;
20
20
pub extern crate serial_unix;
21
+ pub extern crate serial_core;
21
22
pub extern crate nb;
22
23
23
24
use std:: io:: { self , Write } ;
Original file line number Diff line number Diff line change 1
1
//! Implementation of [`Serial`](https://docs.rs/embedded-hal/0.2.1/embedded_hal/serial/index.html)
2
2
3
3
use std:: io:: { ErrorKind as IoErrorKind , Read , Write } ;
4
+ use std:: path:: Path ;
4
5
5
6
use nb;
6
7
7
8
use hal;
9
+ use serial_core;
8
10
use serial_unix:: TTYPort ;
9
11
10
12
/// Newtype around [`serial_unix::TTYPort`] that implements
11
13
/// the `embedded-hal` traits.
12
14
pub struct Serial ( pub TTYPort ) ;
13
15
16
+ impl Serial {
17
+ /// Wrapper for `serial_unix::TTYPort::open`
18
+ pub fn open ( path : & Path ) -> Result < Serial , serial_core:: Error > {
19
+ Ok ( Serial ( TTYPort :: open ( path) ?) )
20
+ }
21
+ }
22
+
14
23
/// Helper to convert std::io::Error to the nb::Error
15
24
fn translate_io_errors ( err : std:: io:: Error ) -> nb:: Error < IoErrorKind > {
16
25
match err. kind ( ) {
@@ -60,8 +69,7 @@ mod test {
60
69
fn create_pty_and_serial ( ) -> ( std:: fs:: File , Serial ) {
61
70
let ( master, _slave, name) =
62
71
openpty:: openpty ( None , None , None ) . expect ( "Creating pty failed" ) ;
63
- let port = TTYPort :: open ( Path :: new ( & name) ) . expect ( "Creating TTYPort failed" ) ;
64
- let serial = Serial ( port) ;
72
+ let serial = Serial :: open ( Path :: new ( & name) ) . expect ( "Creating TTYPort failed" ) ;
65
73
( master, serial)
66
74
}
67
75
You can’t perform that action at this time.
0 commit comments