yangyize / easy-modbus Goto Github PK
View Code? Open in Web Editor NEWA Rust Modbus library.
License: MIT License
A Rust Modbus library.
License: MIT License
This is a simple test program for Modbus. As you see there is an error.
That is our program's response. I wonder, why does our program respond in three different responses and why do the tid numbers not match?
The code of program is a copy of example.
use std::error::Error;
use futures::SinkExt;
use tokio::net::{TcpListener, TcpStream};
use tokio_stream::StreamExt;
use tokio_util::codec::Framed;
use easy_modbus::{codec::TcpServerCodec, Frame};
use std::fmt;
#[tokio::main]
async fn main() -> Result<(), Box> {
let addr = "127.0.0.1:502".to_string();
let server = TcpListener::bind(&addr).await?;
println!("Listening on: {}", addr);
loop {
let (stream, _) = server.accept().await?;
tokio::spawn(async move {
if let Err(e) = process(stream).await {
println!("failed to process connection; error = {}", e);
}
});
}
}
async fn process(stream: TcpStream) -> Result<(), Box> {
let mut transport = Framed::new(stream, TcpServerCodec);
let frame = Frame::tcp();
let mut test_vec: Vec<u8> = vec![0xff, 0xff, 0xff, 0xff];
while let Some(request) = transport.next().await {
match request {
Ok(request) => {
println!("load request --- {:?}\n", request);
let mut response = frame.read_holding_register_response(0x01, test_vec.clone());
println!("send response --- {:?}\n", response);
transport.send(response).await?;
}
Err(e) => return Err(e.into()),
}
}
Ok(())
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.