[][src]Struct sds011::SDS011

pub struct SDS011 { /* fields omitted */ }

Struct holds a link to a sensor and provides functions to interact with it

Example:

use sds011::{SDS011};
use std::thread::sleep;
use std::time::{Duration};

match SDS011::new(port) {
    Ok(mut sensor) => {
        sensor.set_work_period(work_period).unwrap();

        loop {
            if let Some(m) = sensor.query() {
                println!("{:?}", m);
            }

            sleep(Duration::from_secs(5u64 * 60));
        }
    },
    Err(e) => println!("{:?}", e.description),
};

Implementations

impl SDS011[src]

pub fn new(port: &str) -> Result<SDS011>[src]

Creates new instance of SDS011 port is required, for example /dev/ttyUSB0

Example

let mut sensor = SDS011::new("/dev/ttyUSB0").unwrap();

pub fn set_report_mode(&mut self) -> Result<()>[src]

Sets report mode TODO at the moment sets WRITE and PASSIVE mode only

pub fn query(&mut self) -> Result<Message>[src]

Reads data from the sensor and returns as Message

pub fn cmd_begin(&self) -> Vec<u8>[src]

Returns command header and command ID bytes

pub fn set_work_period(&mut self, work_time: u8) -> Result<()>[src]

Sets working period work_time must be between 0 and 30

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.