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

Can not disconnect slave, need help #210

Closed
ileon opened this issue Jul 25, 2023 · 3 comments
Closed

Can not disconnect slave, need help #210

ileon opened this issue Jul 25, 2023 · 3 comments
Labels

Comments

@ileon
Copy link

ileon commented Jul 25, 2023

async fn main() -> Result<()> {
{
let mut ctx1 = get_ctx(&get_default_sp_builder(), 2)?;
let rsp1 = ctx1.read_holding_registers(1, 2).await?;
println!("{rsp1:?}");
ctx1.disconnect().await?;
}

let mut ctx2 = get_ctx(&get_default_sp_builder(), 1)?;
let rsp2 = ctx2.read_holding_registers(1, 2).await?;
println!("{rsp2:?}");
ctx2.disconnect().await?;

Ok(())

}

above is my code, the rsp1 is right, but failed at the ctx2 row
What is the right method? thanks!

@uklotzde
Copy link
Member

Context? Fails how?

@ileon
Copy link
Author

ileon commented Jul 27, 2023

Context? Fails how?

there are two contexts, the ctx1 works normal, then the ctx1.disconnect().await? is not take effect, so the ctx2 panic because access is denied.

@uklotzde
Copy link
Member

get_ctx() and get_default_sp_builder() are not provided by tokio-modbus and I cannot comment on this. Everything might happen behind the scenes.

Please re-open if you could provide a runnable or at least comprehensible example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants