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"
1414spidev = " 0.3.0"
1515sysfs_gpio = " 0.5.1"
1616serial-unix = " 0.4.0"
17+ serial-core = " 0.4.0"
1718nb = " 0.1.1"
1819
1920[dev-dependencies ]
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ pub extern crate i2cdev;
1818pub extern crate spidev;
1919pub extern crate sysfs_gpio;
2020pub extern crate serial_unix;
21+ pub extern crate serial_core;
2122pub extern crate nb;
2223
2324use std:: io:: { self , Write } ;
Original file line number Diff line number Diff line change 11//! Implementation of [`Serial`](https://docs.rs/embedded-hal/0.2.1/embedded_hal/serial/index.html)
22
33use std:: io:: { ErrorKind as IoErrorKind , Read , Write } ;
4+ use std:: path:: Path ;
45
56use nb;
67
78use hal;
9+ use serial_core;
810use serial_unix:: TTYPort ;
911
1012/// Newtype around [`serial_unix::TTYPort`] that implements
1113/// the `embedded-hal` traits.
1214pub struct Serial ( pub TTYPort ) ;
1315
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+
1423/// Helper to convert std::io::Error to the nb::Error
1524fn translate_io_errors ( err : std:: io:: Error ) -> nb:: Error < IoErrorKind > {
1625 match err. kind ( ) {
@@ -60,8 +69,7 @@ mod test {
6069 fn create_pty_and_serial ( ) -> ( std:: fs:: File , Serial ) {
6170 let ( master, _slave, name) =
6271 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" ) ;
6573 ( master, serial)
6674 }
6775
You can’t perform that action at this time.
0 commit comments