-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f05e506
commit da4ee7c
Showing
12 changed files
with
337 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,4 +32,5 @@ members = [ | |
"sunspec-gen", | ||
"examples/readme", | ||
"examples/model103", | ||
"examples/model712", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "sunspec-example-model712" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
tokio = { version = "1.33.0", features = ["rt-multi-thread", "macros", "time"] } | ||
tokio-modbus = { version = "0.15", features = ["tcp"] } | ||
sunspec = { path = "../../" } | ||
clap = { version = "4.4.7", features = ["derive"] } | ||
itertools = "0.13.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Model 103 example | ||
|
||
This code connects to a device that supports sunspec via modbus TCP and | ||
outputs the contents of model 1 and then proceeds reading model 103 | ||
(three phase inverter) outputting the value "W / W_SF" and "WH / WH_SF" | ||
every second. | ||
|
||
Usage example: | ||
|
||
``` | ||
$ cargo run 192.168.178.38:1502 1 | ||
``` | ||
|
||
Example output: | ||
|
||
``` | ||
Manufacturer: SolarEdge | ||
Model: SE25K-RW00IBNM4 | ||
Version: 0004.0018.0518 | ||
Serial Number: -redacted- | ||
Supported models: 1, 103 | ||
157.185 kWh 2.292 kW | ||
157.185 kWh 2.269 kW | ||
157.186 kWh 2.270 kW | ||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::{error::Error, net::SocketAddr, time::Duration}; | ||
|
||
use clap::Parser; | ||
use itertools::Itertools; | ||
use sunspec::{ | ||
client::{AsyncClient, Config}, models::{model1::Model1, model712::Model712}, DEFAULT_DISCOVERY_ADDRESSES | ||
}; | ||
use tokio_modbus::{client::tcp::connect_slave, Slave}; | ||
|
||
#[derive(Parser)] | ||
struct Args { | ||
addr: SocketAddr, | ||
device_id: u8, | ||
#[arg( | ||
long, | ||
short='d', | ||
help = "Discovery addresses", | ||
name = "ADDRESS", | ||
default_values_t = DEFAULT_DISCOVERY_ADDRESSES | ||
)] | ||
discovery_addresses: Vec<u16>, | ||
#[arg( | ||
long, | ||
short = 't', | ||
help = "Read timeout in seconds", | ||
name = "SECONDS", | ||
default_value_t = 1.0 | ||
)] | ||
read_timeout: f32, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn Error>> { | ||
let args = Args::parse(); | ||
|
||
let mut client = AsyncClient::new( | ||
connect_slave(args.addr, Slave(args.device_id)).await?, | ||
Config { | ||
discovery_addresses: args.discovery_addresses, | ||
read_timeout: (args.read_timeout != 0.0) | ||
.then(|| Duration::from_secs_f32(args.read_timeout)), | ||
..Default::default() | ||
}, | ||
) | ||
.await?; | ||
|
||
let m1: Model1 = client.read_model().await?; | ||
|
||
println!("Manufacturer: {}", m1.mn); | ||
println!("Model: {}", m1.md); | ||
println!("Version: {}", m1.vr.as_deref().unwrap_or("(unspecified)")); | ||
println!("Serial Number: {}", m1.sn); | ||
|
||
println!( | ||
"Supported models: {}", | ||
client | ||
.models | ||
.supported_model_ids() | ||
.iter() | ||
.map(|id| id.to_string()) | ||
.join(", ") | ||
); | ||
|
||
let m712: Model712 = client.read_model().await?; | ||
println!("{:?}", m712); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.