bevy_serialport
Async serial port plugin for the Bevy game engine, providing seamless integration between serial communication and Bevy's ECS system.
Features
- ✨ Async Serial Communication: Non-blocking serial I/O using Tokio
- 🎯 Event-Driven Architecture: Receive serial data through Bevy events
- 🔧 Comprehensive Configuration: Full control over serial port settings
- 🛡️ Enhanced Error Handling: Detailed error types with context
- 🚀 High Performance: Optimized for minimal overhead
- 🎮 Multiple Port Support: Manage multiple serial connections simultaneously
- 🔌 Cross-Platform: Works on Windows, macOS, and Linux
- 📦 Utility Functions: Built-in helpers for port discovery and validation
Quick Start
Add this to your Cargo.toml:
[]
= "0.12"
= "0.19"
Basic Usage
use *;
use ;
use Duration;
Advanced Configuration
use ;
use Duration;
Port Discovery
use *;
Multiple Ports
Error Handling
The library provides comprehensive error handling:
use SerialError;
SerialData API
The SerialData event provides convenient methods for data access:
Examples
The repository includes several examples:
- Basic Receiver:
cargo run --example serial_receiver -- --port COM1 - Basic Sender:
cargo run --example serial_sender -- --port COM1 - Advanced Usage:
cargo run --example advanced_usage
Supported Platforms
| Platform | Status | Notes |
|---|---|---|
| Windows | ✅ | COM ports (COM1, COM2, etc.) |
| Linux | ✅ | USB/UART devices (/dev/ttyUSB0, /dev/ttyACM0, etc.) |
| macOS | ✅ | USB/UART devices (/dev/cu., /dev/tty.) |
Bevy Compatibility
| Bevy Version | bevy_serialport Version |
|---|---|
| 0.19 | 0.12 |
| 0.18 | 0.11 |
| 0.17 | 0.10 |
| 0.16 | 0.9 |
| 0.15 | 0.8 |
| 0.14 | 0.7 |
| 0.13 | 0.6 |
| 0.12 | 0.5 |
| 0.11 | 0.4 |
| 0.10 | 0.3 |
| 0.9 | 0.2 |
| 0.8 | 0.1 |
Common Use Cases
- 🔬 Scientific Instruments: Communicate with sensors and measurement devices
- 🤖 Robotics: Control motors, read sensors, and communicate with microcontrollers
- 🎮 Game Controllers: Interface with custom hardware controllers
- 📡 IoT Integration: Connect with embedded devices and sensors
- 🔧 Development Tools: Debug interfaces and diagnostic tools
Performance Considerations
- Uses Tokio's async runtime for non-blocking I/O
- Minimal memory allocations in the hot path
- Efficient message batching for high-throughput scenarios
- Thread-safe design with minimal locking overhead
Troubleshooting
Port Not Found
# Linux: Check available ports
# Windows: Use Device Manager or PowerShell
|
Permission Denied (Linux)
# Add user to dialout group
# Then logout and login again
Port Already in Use
Ensure no other applications are using the serial port. On Linux, you can check with:
Contributing
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
This project is dual-licensed under either:
- MIT License (http://opensource.org/licenses/MIT)
- Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
At your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Acknowledgments
- Built on top of tokio-serial for async serial communication
- Inspired by the Bevy community's commitment to ergonomic game development
- Thanks to all contributors and users who have helped improve this library
For more information, visit the documentation or check out the repository.