use std::path::Path;
use std::path::PathBuf;
use std::time::Duration;
use serialport::SerialPort;
pub struct AuxInterface
{
serial_port: PathBuf
}
impl AuxInterface
{
pub fn from_path(serial_port: &Path) -> Self
{
Self {
serial_port: serial_port.to_owned(),
}
}
pub fn serial_port(&self) -> &PathBuf
{
&self.serial_port
}
pub fn open(&self, baud: u32) -> serialport::Result<Box<dyn SerialPort>>
{
serialport::new(self.serial_port.to_string_lossy(), baud)
.timeout(Duration::from_millis(10))
.dtr_on_open(true)
.flow_control(serialport::FlowControl::None)
.open()
}
}