GithubHelp home page GithubHelp logo

Sync RTU Client about tokio-modbus HOT 8 CLOSED

slowtec avatar slowtec commented on May 27, 2024
Sync RTU Client

from tokio-modbus.

Comments (8)

zzeroo avatar zzeroo commented on May 27, 2024 1

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

from tokio-modbus.

hanusek avatar hanusek commented on May 27, 2024

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

The requested resource does not exist

from tokio-modbus.

david-mcgillicuddy-moixa avatar david-mcgillicuddy-moixa commented on May 27, 2024

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

from tokio-modbus.

hanusek avatar hanusek commented on May 27, 2024

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.

from tokio-modbus.

hanusek avatar hanusek commented on May 27, 2024

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?

from tokio-modbus.

david-mcgillicuddy-moixa avatar david-mcgillicuddy-moixa commented on May 27, 2024

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).

from tokio-modbus.

hanusek avatar hanusek commented on May 27, 2024

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

from tokio-modbus.

flosse avatar flosse commented on May 27, 2024

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.

from tokio-modbus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.