Provide some debug output.

This commit is contained in:
Henner Zeller 2026-02-22 13:28:39 +01:00
parent 39147d45f4
commit 52d734d95f
3 changed files with 12 additions and 5 deletions

View file

@ -2,6 +2,7 @@
use std::time::Duration;
use thiserror::Error;
use log::debug;
fn new_camera_rotation(theta: f64) -> nalgebra::Matrix3<f64> {
nalgebra::matrix![
@ -55,6 +56,8 @@ pub type StageIOResult<T> = std::result::Result<T, StageIOError>;
impl StageIO {
pub fn new(port: &str, speed: u32) -> StageIOResult<Self> {
let serial = serialport::new(port, speed).timeout(Duration::from_secs(60)).open()?;
// TODO: read and discard initial characters; some devices like to be
// chatty on start-up.
Ok(Self { serial })
}
@ -71,10 +74,12 @@ impl StageIO {
}
// Send request and wait for response deliminated with a newline
fn send_request<S: AsRef<str>>(&mut self, command: S) -> StageIOResult<String> {
pub fn send_request<S: AsRef<str>>(&mut self, command: S) -> StageIOResult<String> {
debug!("->: {:?}", command.as_ref());
self.serial.write_all(command.as_ref().as_bytes()).map_err(|e| StageIOError::Write(e))?;
let res = self.receive_until("\n")?;
Ok(res.trim().to_string())
let response = self.receive_until("\n")?;
debug!("<-: {:?}", response);
Ok(response.trim().to_string())
}
}