Skip to content

Commit

Permalink
example: tcp-server: update comments based on PR #163 discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
cdbennett authored and uklotzde committed Mar 12, 2023
1 parent ace3d81 commit 167acf2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions examples/tcp-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ impl tokio_modbus::server::Service for ExampleService {
}
}
_ => {
eprintln!("SERVER: Unimplemented function code in request: {req:?}");
// TODO: We want to return a Modbus Exception response `IllegalFunction`.
// Not sure how to directly do that.
println!("SERVER: Exception::IllegalFunction - Unimplemented function code in request: {req:?}");
// TODO: We want to return a Modbus Exception response `IllegalFunction`. https://github.com/slowtec/tokio-modbus/issues/165
return future::ready(Err(std::io::Error::new(
std::io::ErrorKind::AddrNotAvailable,
format!("Unimplemented function code in request"),
Expand Down Expand Up @@ -105,8 +104,8 @@ fn register_read(
if let Some(r) = registers.get(&reg_addr) {
response_values[i as usize] = *r;
} else {
// TODO: We want to return a Modbus Exception response `IllegalDataAddress`.
// Not sure how to directly do that.
// TODO: Return a Modbus Exception response `IllegalDataAddress` https://github.com/slowtec/tokio-modbus/issues/165
println!("SERVER: Exception::IllegalDataAddress");
return Err(std::io::Error::new(
std::io::ErrorKind::AddrNotAvailable,
format!("no register at address {reg_addr}"),
Expand All @@ -129,6 +128,8 @@ fn register_write(
if let Some(r) = registers.get_mut(&reg_addr) {
*r = *value;
} else {
// TODO: Return a Modbus Exception response `IllegalDataAddress` https://github.com/slowtec/tokio-modbus/issues/165
println!("SERVER: Exception::IllegalDataAddress");
return Err(std::io::Error::new(
std::io::ErrorKind::AddrNotAvailable,
format!("no register at address {reg_addr}"),
Expand Down Expand Up @@ -195,7 +196,8 @@ async fn client_context(socket_addr: SocketAddr) {
let response = ctx.read_holding_registers(0x100, 1).await;
println!("CLIENT: The result is '{response:?}'");
assert!(response.is_err());
// TODO: is there a way to get the actual Modbus Exception code? To determine what type of error?
// TODO: How can Modbus client identify Modbus exception responses? E.g. here we expect IllegalDataAddress
// Question here: https://github.com/slowtec/tokio-modbus/issues/169

println!("CLIENT: Done.")
},
Expand Down

0 comments on commit 167acf2

Please sign in to comment.