fix: set serial settings

This commit is contained in:
spacemeowx2 2020-12-06 10:30:01 +08:00
parent a373f055fc
commit e6ddfd0857

View File

@ -9,7 +9,7 @@ use blflash::{
}; };
use env_logger::Env; use env_logger::Env;
use main_error::MainError; use main_error::MainError;
use serial::{BaudRate, SerialPort}; use serial::{BaudRate, CharSize, FlowControl, Parity, SerialPort, SerialPortSettings, StopBits};
use std::path::PathBuf; use std::path::PathBuf;
use std::{ use std::{
borrow::Cow, borrow::Cow,
@ -95,7 +95,14 @@ enum Opt {
impl Connection { impl Connection {
fn open_serial(&self) -> Result<impl SerialPort, Error> { fn open_serial(&self) -> Result<impl SerialPort, Error> {
let serial = serial::open(&self.port)?; let mut serial = serial::open(&self.port)?;
serial.reconfigure(&|setup: &mut dyn SerialPortSettings| {
setup.set_char_size(CharSize::Bits8);
setup.set_stop_bits(StopBits::Stop1);
setup.set_parity(Parity::ParityNone);
setup.set_flow_control(FlowControl::FlowNone);
Ok(())
})?;
Ok(serial) Ok(serial)
} }
fn create_flasher(&self, chip: impl Chip + 'static) -> Result<Flasher, Error> { fn create_flasher(&self, chip: impl Chip + 'static) -> Result<Flasher, Error> {