From e6ddfd085704a56618860df454e77dc04a797aed Mon Sep 17 00:00:00 2001 From: spacemeowx2 Date: Sun, 6 Dec 2020 10:30:01 +0800 Subject: [PATCH] fix: set serial settings --- blflash/src/main.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/blflash/src/main.rs b/blflash/src/main.rs index c8f422d..6beffd3 100644 --- a/blflash/src/main.rs +++ b/blflash/src/main.rs @@ -9,7 +9,7 @@ use blflash::{ }; use env_logger::Env; use main_error::MainError; -use serial::{BaudRate, SerialPort}; +use serial::{BaudRate, CharSize, FlowControl, Parity, SerialPort, SerialPortSettings, StopBits}; use std::path::PathBuf; use std::{ borrow::Cow, @@ -95,7 +95,14 @@ enum Opt { impl Connection { fn open_serial(&self) -> Result { - 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) } fn create_flasher(&self, chip: impl Chip + 'static) -> Result {