| Crates.io | tokio-mc |
| lib.rs | tokio-mc |
| version | 0.1.4 |
| created_at | 2024-11-26 01:58:46.417259+00 |
| updated_at | 2025-08-02 12:52:25.911161+00 |
| description | A library for communication with PLCs using the MC protocol |
| homepage | https://github.com/hanHHHyU/tokio-mc |
| repository | https://github.com/hanHHHyU/tokio-mc |
| max_upload_size | |
| id | 1461094 |
| size | 194,986 |
tokio-mc is a pure Rust library for Mitsubishi Communication (MC) protocol, built on top of tokio.
Async & Sync communication with Mitsubishi and Keyence PLCs using the 3E frame protocol.
Easy integration with the tokio ecosystem for async programming.
Add the following to your Cargo.toml to use tokio-mc with the desired features:
# For async usage
tokio-mc = { version = "0.1.3", features = ["3e-async"] }
# For sync usage
tokio-mc = { version = "0.1.3", features = ["3e-sync"] }
Here's how to use the async features of tokio-mc:
use std::net::SocketAddr;
use tokio::time::Duration;
use tokio_mc::{
client::{tcp::*, Reader, Writer},
frame::Model,
Error,
};
#[tokio::main]
async fn main() -> Result<(), Error> {
let addr = "192.168.1.30:5000"
.parse::<SocketAddr>()
.map_err(|e| Error::Transport(std::io::Error::new(std::io::ErrorKind::InvalidInput, e)))?;
let mut context = connect(addr).await?;
context.set_plc_model(Model::Keyence);
let u16_values = context.read_u16s("D1002", 2).await?;
println!("Read U16s: {:?}", u16_values);
Ok(())
}
Here's how to use the sync features of tokio-mc:
use std::net::SocketAddr;
use tokio_mc::{
client::sync::{tcp::*, Reader, Writer},
frame::Model,
Error,
};
fn main() -> Result<(), Error> {
let addr = "192.168.110.252:5000".parse::<SocketAddr>().unwrap();
let mut context = connect(addr)?;
context.set_plc_model(Model::Keyence);
// Read different data types
let u8_values = context.read_u8s("D1000", 2)?;
println!("Read U8s: {:?}", u8_values);
context.write_bools("M200", &[true, false, true, true])?;
println!("Written Bools successfully");
Ok(())
}
When using this library for PLC communication, please first make sure that there is no abnormality in your connection. I used the 3E frame protocol, which has been tested with Keyence and Mitsubishi and used in actual projects. If you have any feedback or suggestions, please contact me via QQ email.
Some codes are referenced from tokio-modbus。