diff --git a/Cargo.lock b/Cargo.lock index b6fb54c..1fe7858 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1391,9 +1391,9 @@ dependencies = [ [[package]] name = "modbus-robust" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4efb5df2e29d48ae9dcc51ef9255aae09f2f3f2a20a3d67ca8c11912ef2f2d5f" +checksum = "cb003d13b507a1c281916df2522f9e9d91c2fea6f4026d1f5b3b7767a2f48b6c" dependencies = [ "async-trait", "tokio", @@ -2158,7 +2158,16 @@ version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f49a1853cf82743e3b7950f77e0f4d622ca36cf4317cba00c767838bac8d490" +dependencies = [ + "thiserror-impl 2.0.4", ] [[package]] @@ -2172,6 +2181,17 @@ dependencies = [ "syn 2.0.90", ] +[[package]] +name = "thiserror-impl" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8381894bb3efe0c4acac3ded651301ceee58a15d47c2e34885ed1908ad667061" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", +] + [[package]] name = "time" version = "0.3.37" @@ -2242,20 +2262,19 @@ dependencies = [ [[package]] name = "tokio-modbus" -version = "0.9.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0f38205d1e83e64947e0b07731cc05667952f5fb0986279573022305edfbf4e" +checksum = "e493b54318dffe0c341d705839c58cdad1fca4b77d1e0a5d8ab1c22ac175bf37" dependencies = [ "async-trait", "byteorder", "bytes 1.9.0", - "futures", + "futures-core", "futures-util", "log", "smallvec", - "socket2", + "thiserror 2.0.4", "tokio", - "tokio-serial", "tokio-util", ] @@ -2377,7 +2396,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c878a167baa8afd137494101a688ef8c67125089ff2249284bd2b5f9bfedb815" dependencies = [ - "thiserror", + "thiserror 1.0.69", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 1d23491..54a6e8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,7 +62,7 @@ etherparse = { version = "0.16.0", optional = true } futures = "0.3.28" influxdb2 = { version = "0.5.2", default-features = false, features = ["rustls"], optional = true } log = "0.4.17" -modbus-robust = { version = "0.1.0", optional = true } +modbus-robust = { version = "0.2.0", optional = true } mqtt-async-client = { version = "0.3.1", optional = true } pcap = { version = "2.2.0", features = ["capture-stream"], optional = true } phf = { version = "0.11.2", default-features = false } @@ -70,7 +70,7 @@ serde = { version = "1.0.159", features = ["derive"] } serde_json = { version = "1.0.95", optional = true } serde_with = { version = "3.2.0", optional = true } tokio = { version = "1.21.2", features = ["macros", "rt"] } -tokio-modbus = { version = "0.9.0", default-features = false, features = ["rtu", "tcp"], optional = true } +tokio-modbus = { version = "0.16.0", default-features = false, features = ["rtu", "tcp"], optional = true } tokio-serial = { version = "5.4.4", optional = true } toml = "0.8.19" diff --git a/src/modbus.rs b/src/modbus.rs index 4c790d8..85a93bf 100644 --- a/src/modbus.rs +++ b/src/modbus.rs @@ -53,14 +53,16 @@ fn default_modbus_id() -> u8 { 1 } -async fn read_values(ctx: &mut Context) -> Result, std::io::Error> { +async fn read_values( + ctx: &mut Context, +) -> Result, Box> { let mut values = Vec::with_capacity(FIELDS.len()); let mut parts = [0u16; 2]; for (field, regs) in FIELDS.iter().zip(REGISTERS.iter()) { let value = if !regs.is_empty() { for (i, reg) in regs.iter().enumerate() { // TODO: better error handling - parts[i] = ctx.read_holding_registers(*reg, 1).await?[0]; + parts[i] = ctx.read_holding_registers(*reg, 1).await??[0]; } field.from_u16s(parts[..regs.len()].iter().cloned()) } else { @@ -69,7 +71,7 @@ async fn read_values(ctx: &mut Context) -> Result, std::io::Error> { values.push(value); } // Get the inverter time, since that'll determine which program is current - let time_regs = ctx.read_holding_registers(REG_CLOCK, 3).await?; + let time_regs = ctx.read_holding_registers(REG_CLOCK, 3).await??; let hour = time_regs[1] & 0xff; let minute = time_regs[2] >> 8; let second = time_regs[2] & 0xff; @@ -100,7 +102,7 @@ pub async fn create_stream( Ok(socket_addr) => modbus_robust::new_tcp_slave(socket_addr, slave), Err(_) => modbus_robust::new_rtu_slave(&config.device, config.baud, slave), }; - let serial_words = ctx.read_holding_registers(3, 5).await?; + let serial_words = ctx.read_holding_registers(3, 5).await??; let mut serial_bytes = [0u8; 10]; for i in 0..5 { let bytes = serial_words[i].to_be_bytes();