diff --git a/charge-controller-supervisor/src/tristar.rs b/charge-controller-supervisor/src/tristar.rs index d5df060..5cdf5d1 100644 --- a/charge-controller-supervisor/src/tristar.rs +++ b/charge-controller-supervisor/src/tristar.rs @@ -55,9 +55,9 @@ pub struct Tristar { scaling: Option, } -#[derive(Default, Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct TristarState { - scaling: Option, + scaling: Scaling, battery_voltage: f64, target_voltage: f64, input_current: f64, @@ -86,7 +86,7 @@ impl TristarState { fn from_ram(ram: &[u16]) -> Self { let scaling = Scaling::from(ram); Self { - scaling: Some(scaling), + scaling, battery_voltage: scaling.get_voltage(ram[TristarRamAddress::AdcVbFMed]), target_voltage: scaling.get_voltage(ram[TristarRamAddress::VbRef]), input_current: scaling.get_current(ram[TristarRamAddress::AdcIaFShadow]), @@ -266,6 +266,7 @@ impl Tristar { let modbus_serial = tokio_serial::SerialStream::open( &tokio_serial::new(port, *baud_rate).timeout(std::time::Duration::from_secs(3)), )?; + tokio_modbus::client::rtu::attach_slave(modbus_serial, slave) } crate::config::Transport::Tcp { ip, port } => { @@ -287,7 +288,7 @@ impl Tristar { pub async fn refresh(&mut self) -> eyre::Result { let new_state = self.get_data().await?; - self.scaling = new_state.scaling; + self.scaling = Some(new_state.scaling); self.consecutive_errors = 0; BATTERY_VOLTAGE .with_label_values(&[&self.friendly_name])