Skip to content

Commit

Permalink
examples: update clients with the new API
Browse files Browse the repository at this point in the history
  • Loading branch information
creberust committed Feb 2, 2024
1 parent a708092 commit ed9aa22
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions examples/rtu-over-tcp-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ async fn client_context(socket_addr: SocketAddr) {
let mut ctx = tokio_modbus::prelude::rtu::attach_slave(transport, Slave(1));

println!("CLIENT: Reading 2 input registers...");
let response = ctx.read_input_registers(0x00, 2).await.unwrap();
let response = ctx.read_input_registers(0x00, 2).await.unwrap().unwrap();
println!("CLIENT: The result is '{response:?}'");
assert_eq!(response, [1234, 5678]);

Expand All @@ -179,7 +179,7 @@ async fn client_context(socket_addr: SocketAddr) {

// Read back a block including the two registers we wrote.
println!("CLIENT: Reading 4 holding registers...");
let response = ctx.read_holding_registers(0x00, 4).await.unwrap();
let response = ctx.read_holding_registers(0x00, 4).await.unwrap().unwrap();
println!("CLIENT: The result is '{response:?}'");
assert_eq!(response, [10, 7777, 8888, 40]);

Expand Down
2 changes: 1 addition & 1 deletion examples/tcp-client-custom-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Fetching the coupler ID");
let rsp = ctx
.call(Request::Custom(0x66, Cow::Borrowed(&[0x11, 0x42])))
.await?;
.await??;

match rsp {
Response::Custom(f, rsp) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/tcp-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut ctx = tcp::connect(socket_addr).await?;

println!("Fetching the coupler ID");
let data = ctx.read_input_registers(0x1000, 7).await?;
let data = ctx.read_input_registers(0x1000, 7).await??;

let bytes: Vec<u8> = data.iter().fold(vec![], |mut x, elem| {
x.push((elem & 0xff) as u8);
Expand Down
4 changes: 2 additions & 2 deletions examples/tcp-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ async fn client_context(socket_addr: SocketAddr) {
let mut ctx = tcp::connect(socket_addr).await.unwrap();

println!("CLIENT: Reading 2 input registers...");
let response = ctx.read_input_registers(0x00, 2).await.unwrap();
let response = ctx.read_input_registers(0x00, 2).await.unwrap().unwrap();
println!("CLIENT: The result is '{response:?}'");
assert_eq!(response, [1234, 5678]);

Expand All @@ -179,7 +179,7 @@ async fn client_context(socket_addr: SocketAddr) {

// Read back a block including the two registers we wrote.
println!("CLIENT: Reading 4 holding registers...");
let response = ctx.read_holding_registers(0x00, 4).await.unwrap();
let response = ctx.read_holding_registers(0x00, 4).await.unwrap().unwrap();
println!("CLIENT: The result is '{response:?}'");
assert_eq!(response, [10, 7777, 8888, 40]);

Expand Down
4 changes: 2 additions & 2 deletions examples/tls-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ async fn client_context(socket_addr: SocketAddr) {
let mut ctx = tcp::attach(transport);

println!("CLIENT: Reading 2 input registers...");
let response = ctx.read_input_registers(0x00, 2).await.unwrap();
let response = ctx.read_input_registers(0x00, 2).await.unwrap().unwrap();
println!("CLIENT: The result is '{response:?}'");
assert_eq!(response, [1234, 5678]);

Expand All @@ -282,7 +282,7 @@ async fn client_context(socket_addr: SocketAddr) {

// Read back a block including the two registers we wrote.
println!("CLIENT: Reading 4 holding registers...");
let response = ctx.read_holding_registers(0x00, 4).await.unwrap();
let response = ctx.read_holding_registers(0x00, 4).await.unwrap().unwrap();
println!("CLIENT: The result is '{response:?}'");
assert_eq!(response, [10, 7777, 8888, 40]);

Expand Down

0 comments on commit ed9aa22

Please sign in to comment.