From c594cf1e8bd8c0bef1b0d4be283116ebc581888f Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Mon, 5 Sep 2022 09:30:24 +1000 Subject: [PATCH] packaging etc --- Cargo.lock | 2 +- Cargo.toml | 2 +- install.sh | 1 + src/main.rs | 10 ++++++++++ 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100755 install.sh diff --git a/Cargo.lock b/Cargo.lock index 249b11e..97a2d30 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -382,7 +382,7 @@ dependencies = [ ] [[package]] -name = "modbus-test" +name = "mppt-control" version = "0.1.0" dependencies = [ "bincode", diff --git a/Cargo.toml b/Cargo.toml index b3d0f66..9cfd693 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "modbus-test" +name = "mppt-control" version = "0.1.0" edition = "2021" diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..80d5eab --- /dev/null +++ b/install.sh @@ -0,0 +1 @@ +git pull && cargo install --path . \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 1771f61..f89efd2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +use std::path::Path; + use clap::Parser; use libmodbus_rs::{Modbus, ModbusClient, ModbusRTU}; use serde::{Deserialize, Serialize}; @@ -125,6 +127,7 @@ struct Info { v_scale: f32, i_scale: f32, } + impl Info { pub fn from(data: &[u16]) -> Self { Self { @@ -155,6 +158,13 @@ fn main() { let parity = 'N'; let data_bit = 8; let stop_bit = 2; + if !Path::new(&args.serial_port).exists() { + println!( + "Serial port {} does not exist\nTry \"mppt-control --help\" for usage instructions", + args.serial_port + ); + return; + } println!("Connecting to device on {}", args.serial_port); let mut modbus = Modbus::new_rtu(&args.serial_port, baud, parity, data_bit, stop_bit) .expect("Could not create modbus device");