1 stable release
2024.12.0 | Dec 1, 2024 |
---|
#181 in Hardware support
124 downloads per month
120KB
2.5K
SLoC
modbus-relay
🚀 High-performance Modbus TCP to RTU relay written in Rust
Features • Installation • Usage • Configuration • Monitoring • Contributing
🌟 Features
- 🔄 Transparent TCP to RTU protocol conversion
- 🚀 High-performance asynchronous I/O with Tokio
- 🔧 Advanced RS485 support with configurable RTS control
- 🛡️ Robust error handling and connection management
- ⚡ Zero-copy buffer handling for optimal performance
- 📝 Structured logging with multiple output formats
- 🔌 Connection pooling with per-IP limits
- 🔄 Automatic reconnection with configurable backoff
- 🎯 Comprehensive test suite
- 📊 Built-in metrics and monitoring via HTTP API
🚀 Quick Start
Installation
# Install from crates.io
cargo install modbus-relay
# Or build from source
git clone https://github.com/aljen/modbus-relay
cd modbus-relay
cargo build --release
Basic Usage
# Generate default configuration
modbus-relay --dump-default-config > config.yaml
# Run with custom config
modbus-relay -c /path/to/config.yaml
# Run with default settings
modbus-relay
⚙️ Configuration
Configuration is managed through YAML files. Here's a complete example (config.yaml
):
tcp:
bind_addr: "0.0.0.0"
bind_port: 502
rtu:
device: "/dev/ttyUSB0"
baud_rate: 9600
data_bits: 8
parity: "none"
stop_bits: 1
flush_after_write: true
rts_type: "none" # Options: none, up, down
rts_delay_us: 0
transaction_timeout: "1s"
serial_timeout: "100ms"
max_frame_size: 256
http:
enabled: true
bind_addr: "127.0.0.1"
bind_port: 8080
metrics_enabled: true
connection:
max_connections: 100
idle_timeout: "60s"
connect_timeout: "5s"
per_ip_limits: 10
backoff:
initial_interval: "100ms"
max_interval: "30s"
multiplier: 2.0
max_retries: 5
logging:
trace_frames: false
log_level: "info"
format: "pretty" # Options: pretty, json
include_location: false
📊 Monitoring
The HTTP API provides basic monitoring endpoints:
GET /health
- Health check endpointGET /status
- Detailed status information
Planned monitoring features:
- Prometheus metrics support
- OpenTelemetry integration
- Advanced connection statistics
- Detailed performance metrics
🔍 Examples
Industrial Automation Setup
Example setup running on Raspberry Pi with multiple Modbus RTU devices connected via RS485.
🛠️ Tech Stack
- tokio - Asynchronous runtime
- tokio-serial - Async serial port handling
- tracing - Structured logging
- config - Configuration management
- axum - HTTP server framework
Coming Soon
- Prometheus metrics integration
- OpenTelemetry support
📚 Documentation
🤝 Contributing
Contributions are welcome! Please check out our:
📄 License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Dependencies
~17–26MB
~386K SLoC