Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

### Fixed
- Upgrading MP5103 with invalid FW image does not show error in terminal
- Sending too many messages to the instrument when terminating the debugger.
- Sending too many messages to the instrument when terminating the debugger
- Terminal process panics when USB cable is removed during connection

## [0.21.1]

Expand Down
4 changes: 2 additions & 2 deletions instrument-repl/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1214,8 +1214,8 @@ impl Repl {
}
};
if out.send(req.clone()).is_err() {
error!("User input thread could not send to Receiver. Closing!");
exit(1);
info!("User input thread could not send to Receiver. Closing!");
exit(0)
}
// This `if` statement seeks to fix the NOTE above about not exiting.
// It feels a little awkward, but should be effective.
Expand Down
10 changes: 5 additions & 5 deletions kic-debug/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ impl Process {
}
}

pub fn exec_replace(self) -> anyhow::Result<()> {
pub fn exec_replace(self) -> anyhow::Result<i32> {
imp::exec_replace(&self)
}

#[cfg_attr(unix, allow(dead_code))]
pub fn exec(&self) -> anyhow::Result<()> {
pub fn exec(&self) -> anyhow::Result<i32> {
let exit = std::process::Command::new(&self.path)
.args(&self.args)
.spawn()?
.wait()?;
if exit.success() {
Ok(())
Ok(exit.code().unwrap_or(0))
} else {
Err(std::io::Error::other(format!(
"child process did not exit successfully: {}",
Expand All @@ -53,7 +53,7 @@ mod imp {
TRUE
}

pub(super) fn exec_replace(process: &Process) -> anyhow::Result<()> {
pub(super) fn exec_replace(process: &Process) -> anyhow::Result<i32> {
//Safety: This is an external handler that calls into the windows API. It is
// expected to be safe.
unsafe {
Expand All @@ -73,7 +73,7 @@ mod imp {
use crate::Process;
use std::os::unix::process::CommandExt;

pub(super) fn exec_replace(process: &Process) -> anyhow::Result<()> {
pub(super) fn exec_replace(process: &Process) -> anyhow::Result<i32> {
let mut command = std::process::Command::new(&process.path);
command.args(&process.args);
Err(command.exec().into()) // Exec replaces the current application's program memory, therefore execution will
Expand Down
16 changes: 11 additions & 5 deletions kic-lib/src/protocol/visa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,17 @@ impl Write for Visa {
impl Read for Visa {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
if self.nonblocking {
let stb = Stb::Stb(
self.inst
.read_stb()
.map_err(|e| std::io::Error::other(format!("error reading STB: {e}")))?,
);
let stb = match self.inst.read_stb() {
Ok(stb) => Stb::Stb(stb),
Err(e) =>
// If device is disconnected or STB read fails
{
return Err(std::io::Error::new(
std::io::ErrorKind::NotConnected,
format!("Device disconnected or STB read failed: {e}"),
))
}
};

if matches!(stb.message_available(), Ok(false)) {
return Err(std::io::Error::new(
Expand Down
12 changes: 9 additions & 3 deletions kic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,15 @@ fn main() -> anyhow::Result<()> {

if let Some(kv) = kic_visa_exe {
if kv.exists() {
let _ = Process::new(kv.clone(), std::env::args().skip(1)).exec_replace();
return Ok(());
match Process::new(kv.clone(), std::env::args().skip(1)).exec_replace() {
Ok(exit_code) => {
std::process::exit(exit_code);
}
Err(e) => {
error!("Error executing kic-visa: {e}");
std::process::exit(1);
}
}
}
}
}
Expand Down Expand Up @@ -809,7 +816,6 @@ fn connect(args: &ArgMatches) -> anyhow::Result<()> {
"{}",
format!("\n{e}\n\nClosing instrument connection...").red()
);
drop(repl);
pause_exit_on_error();
}

Expand Down
10 changes: 5 additions & 5 deletions kic/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ impl Process {
}
}

pub fn exec_replace(self) -> anyhow::Result<()> {
pub fn exec_replace(self) -> anyhow::Result<i32> {
imp::exec_replace(&self)
}

#[cfg_attr(unix, allow(dead_code))]
pub fn exec(&self) -> anyhow::Result<()> {
pub fn exec(&self) -> anyhow::Result<i32> {
let exit = std::process::Command::new(&self.path)
.args(&self.args)
.spawn()?
.wait()?;
if exit.success() {
Ok(())
Ok(exit.code().unwrap_or(0))
} else {
Err(std::io::Error::other(format!(
"child process did not exit successfully: {}",
Expand All @@ -53,7 +53,7 @@ mod imp {
TRUE
}

pub(super) fn exec_replace(process: &Process) -> anyhow::Result<()> {
pub(super) fn exec_replace(process: &Process) -> anyhow::Result<i32> {
//Safety: This is an external handler that calls into the windows API. It is
// expected to be safe.
unsafe {
Expand All @@ -73,7 +73,7 @@ mod imp {
use crate::Process;
use std::os::unix::process::CommandExt;

pub(super) fn exec_replace(process: &Process) -> anyhow::Result<()> {
pub(super) fn exec_replace(process: &Process) -> anyhow::Result<i32> {
let mut command = std::process::Command::new(&process.path);
command.args(&process.args);
Err(command.exec().into()) // Exec replaces the current application's program memory, therefore execution will
Expand Down
Loading