Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to generate the exception responses on the server side? #154

Closed
gustavowd opened this issue Feb 27, 2023 · 1 comment
Closed

How to generate the exception responses on the server side? #154

gustavowd opened this issue Feb 27, 2023 · 1 comment

Comments

@gustavowd
Copy link
Contributor

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

@gustavowd gustavowd changed the title How to generate the exception responses on the server side How to generate the exception responses on the server side? Feb 27, 2023
@uklotzde
Copy link
Member

uklotzde commented Mar 5, 2023

I consider this request as a special case of #128. We do not need to maintain multiple issues for the same overarching topic.

Please add your suggestions to the other issue. Thank you.

@uklotzde uklotzde closed this as completed Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants