serial: fix a bug where baud rate was not applied
This commit is contained in:
1 parent
e7c61bd62e
commit
70e18c74aa
2 files changed
+14
-10
No files matched your search
+13
-9
@@ -8,7 +8,9 @@
|
||||
use crate::{Child, CommandBuilder, ExitStatus, MasterPty, PtyPair, PtySize, PtySystem, SlavePty};
|
||||
use anyhow::{ensure, Context};
|
||||
use filedescriptor::FileDescriptor;
|
||||
use serial::{BaudRate, CharSize, FlowControl, Parity, SerialPort, StopBits, SystemPort};
|
||||
use serial::{
|
||||
BaudRate, CharSize, FlowControl, Parity, PortSettings, SerialPort, StopBits, SystemPort,
|
||||
};
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::io::Result as IoResult;
|
||||
use std::io::{Read, Write};
|
||||
@@ -64,14 +66,16 @@ impl PtySystem for SerialTty {
|
||||
let mut port = serial::open(&self.port)
|
||||
.with_context(|| format!("openpty on serial port {:?}", self.port))?;
|
||||
|
||||
port.reconfigure(&|settings| {
|
||||
settings.set_baud_rate(self.baud)?;
|
||||
settings.set_char_size(self.char_size);
|
||||
settings.set_parity(self.parity);
|
||||
settings.set_stop_bits(self.stop_bits);
|
||||
settings.set_flow_control(self.flow_control);
|
||||
Ok(())
|
||||
})?;
|
||||
let settings = PortSettings {
|
||||
baud_rate: self.baud,
|
||||
char_size: self.char_size,
|
||||
parity: self.parity,
|
||||
stop_bits: self.stop_bits,
|
||||
flow_control: self.flow_control,
|
||||
};
|
||||
log::debug!("serial settings: {:#?}", settings);
|
||||
port.configure(&settings)?;
|
||||
|
||||
// The timeout needs to be rather short because, at least on Windows,
|
||||
// a read with a long timeout will block a concurrent write from
|
||||
// happening. In wezterm we tend to have a thread looping on read
|
||||
|
||||
+1
-1
@@ -427,7 +427,7 @@ fn run_serial(config: config::ConfigHandle, opts: &SerialCommand) -> anyhow::Res
|
||||
serial.set_baud_rate(serial::BaudRate::from_speed(baud));
|
||||
}
|
||||
|
||||
let pty_system = Box::new(portable_pty::serial::SerialTty::new(&opts.port));
|
||||
let pty_system = Box::new(serial);
|
||||
let domain: Arc<dyn Domain> = Arc::new(LocalDomain::with_pty_system("local", pty_system));
|
||||
let mux = Rc::new(mux::Mux::new(Some(domain.clone())));
|
||||
Mux::set_mux(&mux);
|
||||
|
||||
Reference in new issue
Block a user