mirror of
https://github.com/italicsjenga/mppt-modbus.git
synced 2024-12-23 16:51:30 +11:00
list serial ports & update clap
This commit is contained in:
parent
c594cf1e8b
commit
e9e3530e09
|
@ -7,6 +7,6 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libmodbus-rs = "0.8.3"
|
libmodbus-rs = "0.8.3"
|
||||||
clap = { version = "3.1", features = ["derive"] }
|
clap = { version = "3.2.20", features = ["derive"] }
|
||||||
bincode = "1.3"
|
bincode = "1.3"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
23
src/main.rs
23
src/main.rs
|
@ -1,4 +1,4 @@
|
||||||
use std::path::Path;
|
use std::{path::Path, process::Command};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use libmodbus_rs::{Modbus, ModbusClient, ModbusRTU};
|
use libmodbus_rs::{Modbus, ModbusClient, ModbusRTU};
|
||||||
|
@ -117,10 +117,15 @@ struct MpptEeprom {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
|
/// Serial port to connect to MPPT
|
||||||
#[clap(short, long, default_value = "/dev/ttyUSB0")]
|
#[clap(short, long, default_value = "/dev/ttyUSB0")]
|
||||||
serial_port: String,
|
serial_port: String,
|
||||||
|
|
||||||
|
/// list serial ports on this system
|
||||||
|
#[clap(long)]
|
||||||
|
get_serial_ports: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Info {
|
struct Info {
|
||||||
|
@ -154,10 +159,24 @@ impl Info {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
if args.get_serial_ports {
|
||||||
|
let output = Command::new("sh")
|
||||||
|
.arg("-c")
|
||||||
|
.arg("ls /dev/tty*")
|
||||||
|
.output()
|
||||||
|
.expect("failed to execute process");
|
||||||
|
let s = match std::str::from_utf8(&output.stdout) {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(e) => panic!("Invalid UTF-8 sequence: {}", e),
|
||||||
|
};
|
||||||
|
println!("{}", s);
|
||||||
|
return;
|
||||||
|
}
|
||||||
let baud = 9600;
|
let baud = 9600;
|
||||||
let parity = 'N';
|
let parity = 'N';
|
||||||
let data_bit = 8;
|
let data_bit = 8;
|
||||||
let stop_bit = 2;
|
let stop_bit = 2;
|
||||||
|
|
||||||
if !Path::new(&args.serial_port).exists() {
|
if !Path::new(&args.serial_port).exists() {
|
||||||
println!(
|
println!(
|
||||||
"Serial port {} does not exist\nTry \"mppt-control --help\" for usage instructions",
|
"Serial port {} does not exist\nTry \"mppt-control --help\" for usage instructions",
|
||||||
|
|
Loading…
Reference in a new issue