ran rustfmt
This commit is contained in:
parent
e0b5bab35a
commit
fde9f2f408
8 changed files with 30 additions and 47 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::time::Duration;
|
||||
use super::Result;
|
||||
use std::io::{Read, Write};
|
||||
use std::time::Duration;
|
||||
|
||||
const DEFAULT_BAUD_RATE: u32 = 38_400;
|
||||
|
||||
|
@ -12,25 +12,25 @@ pub trait SerialComm {
|
|||
fn purge_buffers(&mut self) -> Result<()>;
|
||||
}
|
||||
|
||||
/// Communicate with a serial device using the
|
||||
/// serialport library
|
||||
/// Communicate with a serial device using the
|
||||
/// serialport library
|
||||
///
|
||||
/// /dev/tty* or similar on unix-like systems
|
||||
/// COM devices on Windows systems
|
||||
pub struct SerialPort {
|
||||
device: Box<dyn serialport::SerialPort>
|
||||
device: Box<dyn serialport::SerialPort>,
|
||||
}
|
||||
|
||||
impl SerialPort {
|
||||
/// Creates a new instance of a SerialPort
|
||||
pub fn new(path: &str) -> Result<Self> {
|
||||
let device = serialport::new(path, DEFAULT_BAUD_RATE)
|
||||
.timeout(Duration::from_millis(10))
|
||||
.parity(serialport::Parity::None)
|
||||
.data_bits(serialport::DataBits::Eight)
|
||||
.stop_bits(serialport::StopBits::One)
|
||||
.path(path)
|
||||
.open()?;
|
||||
.timeout(Duration::from_millis(10))
|
||||
.parity(serialport::Parity::None)
|
||||
.data_bits(serialport::DataBits::Eight)
|
||||
.stop_bits(serialport::StopBits::One)
|
||||
.path(path)
|
||||
.open()?;
|
||||
|
||||
Ok(Self { device })
|
||||
}
|
||||
|
@ -54,10 +54,10 @@ impl SerialComm for SerialPort {
|
|||
}
|
||||
}
|
||||
|
||||
/// Communicate with a USB to Serial FTDI device
|
||||
/// Communicate with a USB to Serial FTDI device
|
||||
/// with the FTDI library
|
||||
pub struct FTDIDevice {
|
||||
device: ftdi::Device
|
||||
device: ftdi::Device,
|
||||
}
|
||||
|
||||
impl FTDIDevice {
|
||||
|
@ -83,7 +83,7 @@ impl SerialComm for FTDIDevice {
|
|||
fn read(&mut self, data: &mut [u8]) -> Result<usize> {
|
||||
Ok(self.device.read(data)?)
|
||||
}
|
||||
|
||||
|
||||
fn set_baud_rate(&mut self, baud_rate: u32) -> Result<()> {
|
||||
Ok(self.device.set_baud_rate(baud_rate)?)
|
||||
}
|
||||
|
@ -92,4 +92,3 @@ impl SerialComm for FTDIDevice {
|
|||
Ok(self.device.usb_purge_buffers()?)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue