How to generate the exception responses on the server side?
gustavowd opened this issue · 1 comments
In the tcp server example, there is no example of execption responses. There is no response such as IllegalFunction or IllegalDataAddress. This can be verified by the example, which always return input registers data, because the data is generated based on the request register count:
fn call(&self, req: Self::Request) -> Self::Future {
match req {
Request::ReadInputRegisters(_addr, cnt) => {
let mut registers = vec![0; cnt.into()];
registers[2] = 77;
future::ready(Ok(Response::ReadInputRegisters(registers)))
}
_ => unimplemented!(),
}
}
}
How can i generate the exeption responses? Actually, this code just work if the registers vector was the same length specified in cnt from the request. If I generated a bigger register vector, something like that:
fn call(&self, req: Self::Request) -> Self::Future {
match req {
Request::ReadInputRegisters(_addr, cnt) => {
let mut registers = vec![0; 128];
registers[2] = 77;
future::ready(Ok(Response::ReadInputRegisters(registers)))
}
_ => unimplemented!(),
}
}
}
an error occurs, cause the response implements a for of each register in the vector, which is not the same number of registers requested by the client.
Thanks in advance,
Gustavo