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

Sync RTU Client #51

Closed
hanusek opened this issue Feb 18, 2020 · 8 comments
Closed

Sync RTU Client #51

hanusek opened this issue Feb 18, 2020 · 8 comments

Comments

@hanusek
Copy link

hanusek commented Feb 18, 2020

Hello. I need sync rtu client. Where I find?

@zzeroo
Copy link
Contributor

zzeroo commented Feb 19, 2020

https://docs.rs/tokio-modbus/0.3.5/tokio_modbus/client/sync/rtu

There is a sync module https://docs.rs/tokio-modbus/0.3.5/tokio_modbus/client/sync/index.html

@hanusek
Copy link
Author

hanusek commented Feb 19, 2020

@david-mcgillicuddy-moixa

Those both exist for me. There's also the direct example: https://github.com/slowtec/tokio-modbus/blob/master/examples/rtu-client.rs

@hanusek
Copy link
Author

hanusek commented Feb 19, 2020

Those both exist for me. There's also the direct example: https://github.com/slowtec/tokio-modbus/blob/master/examples/rtu-client.rs

its asnyc.

@hanusek
Copy link
Author

hanusek commented Feb 19, 2020

I'm wrote a example.

		let mut settings = tokio_serial::SerialPortSettings::default();
		settings.baud_rate = 115200;
		println!("settings is '{:?}'", settings);

		const SLAVE_1: Slave = Slave(0x01);
		let result = sync::rtu::connect_slave("/dev/ttyUSB0", &settings, SLAVE_1);
		
		let mut ctx = match result
   		{  
       		Ok(ctx) => ctx,  
       		Err(error) => {  
				println!("There was a problem connect to slave : {:?}", error);
				return;  
		},
		};
		  

		let time_ms = time::Duration::from_millis(500);
		thread::sleep(time_ms);

		println!("Write");

		match ctx.write_single_register(0, 1)
		{
			Err(e) => {			
				println!("Error : '{:?}'", e);
			}
			Ok(f) => f,
		};
		thread::sleep(time_ms);

		match ctx.write_single_register(1, 2)
		{
			Err(e) => {			
				println!("Error : '{:?}'", e);
			}
			Ok(f) => f,
		};
		println!("Write done");

		let mut value = 1;
		loop
		{
			println!("Write");
			value = value + 1;
			match ctx.write_single_register(0, value)
			{
				Err(e) => {			
					println!("Error : '{:?}'", e);
				}
				Ok(f) => f,
			};
			
			thread::sleep(time_ms);

			println!("READ");
			let buff = ctx.read_holding_registers(0,2).unwrap();
			println!("Response is '{:?}'", buff);
		}

I have a problem when not receive response.
How set timeout?

@david-mcgillicuddy-moixa
Copy link

david-mcgillicuddy-moixa commented Feb 19, 2020

I was not ever able to get timeouts in sync working due to #19
So I currently use the async code and race it with a tokio timeout using either select2 in old tokio or select! in new tokio (depending on if you're using 0.3.5 or master of tokio-modbus).

@hanusek
Copy link
Author

hanusek commented Feb 20, 2020

I was not ever able to get timeouts in sync working due to #19
So I currently use the async code and race it with a tokio timeout using either select2 in old tokio or select! in new tokio (depending on if you're using 0.3.5 or master of tokio-modbus).

;(
I'm switching to https://github.com/zzeroo/libmodbus-rs

@flosse
Copy link
Member

flosse commented Mar 8, 2020

I'm switching to https://github.com/zzeroo/libmodbus-rs

Ok, so I'm closing this issue. Feel free to reopen it if there are questions left.

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

No branches or pull requests

4 participants