# bevy_serial `bevy_serial` is a plugin to add non-blocking serial communication to bevy. This plugin is based on [`mio-serial`](https://github.com/berkowski/mio-serial) that can realize non-blocking high-performance I/O. Reading and writing from/to serial port is realized via bevy's event system. Each serial port is handled via port name or a unique label you choose. These event handlers are added to the following stage to minimize the frame delay. - Reading: `PreUpdate` - Writing: `PostUpdate` ## Usage ### Simple Example Here is a simple example: ```rust use bevy::prelude::*; use bevy_serial::{SerialPlugin, SerialReadEvent, SerialWriteEvent}; // to write data to serial port periodically #[derive(Resource)] struct SerialWriteTimer(Timer); const SERIAL_PORT: &str = "/dev/ttyUSB0"; fn main() { App::new() .add_plugins(MinimalPlugins) // simply specify port name and baud rate for `SerialPlugin` .add_plugins(SerialPlugin::new(SERIAL_PORT, 115200)) // to write data to serial port periodically (every 1 second) .insert_resource(SerialWriteTimer(Timer::from_seconds( 1.0, TimerMode::Repeating, ))) // reading and writing from/to serial port is achieved via bevy's event system .add_systems(Update, read_serial) .add_systems(Update, write_serial) .run(); } // reading event for serial port fn read_serial(mut ev_serial: EventReader) { // you can get label of the port and received data buffer from `SerialReadEvent` for SerialReadEvent(label, buffer) in ev_serial.read() { let s = String::from_utf8(buffer.clone()).unwrap(); println!("received packet from {label}: {s}"); } } // writing event for serial port fn write_serial( mut ev_serial: EventWriter, mut timer: ResMut, time: Res