Coder Social home page Coder Social logo

bevy_serialport's Introduction

crates.io

bevy_serialport

bevy_serialport is a plugin for add async serial port support for bevy.

Usage

use std::time::Duration;

use bevy::{app::ScheduleRunnerSettings, log::LogPlugin, prelude::*};
use bytes::Bytes;

use bevy_serialport::{
    DataBits, FlowControl, Parity, Runtime, SerialData, SerialPortPlugin, SerialPortSetting,
    SerialResource, StopBits,
};


fn main() {
    App::new()
        .insert_resource(ScheduleRunnerSettings::run_loop(Duration::from_millis(10)))
        .add_plugin(LogPlugin)
        .add_plugins(MinimalPlugins)
        .add_plugin(SerialPortPlugin)
        .add_startup_system(setup)
        .add_system(receive)
        .add_system(send_test_data)
        .run()
}

fn setup(cmd_args: Res<Args>, mut serial_res: ResMut<SerialResource>, rt: Res<Runtime>) {
    let serial_setting = SerialPortSetting {
        port_name: "COM1".to_string(),
        baud_rate: 115200,
        data_bits: DataBits::Five,
        flow_control: FlowControl::None,
        parity: Parity::None,
        stop_bits: StopBits::One,
        timeout: Default::default(),
    };
    serial_res
        .open_with_setting(rt.clone(), serial_setting)
        .expect("open serial port error");
}

fn receive(mut serial_ev: EventReader<SerialData>) {
    for message in serial_ev.iter() {
        info!("receive {:?}", message);
    }
}

fn send_test_data(mut serial_res: ResMut<SerialResource>) {
    serial_res.send_message("COM1", Bytes::from(&b"123457"[..]))
}

Supported Versions

bevy bevy_serialport
0.13 0.6
0.12 0.5
0.11 0.4
0.10 0.3
0.9 0.2
0.8 0.1

License

Dual-licensed under either

  • MIT
  • Apache 2.0

bevy_serialport's People

Contributors

foxzool avatar varoonp123 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.