[][src]Struct pzem004t::Pzem

pub struct Pzem<Serial> { /* fields omitted */ }

Struct representing a PZEM004T sensor connected to a serial bus.

Methods

impl<Serial, WriteError, ReadError> Pzem<Serial> where
    Serial: Write<u8, Error = WriteError> + Read<u8, Error = ReadError>, 
[src]

pub fn new(
    uart: Serial,
    addr: Option<u8>
) -> Result<Self, Error<WriteError, ReadError>>
[src]

Creates a new PZEM004T struct, consuming the serial peripheral.

When omitting the addr argument, will use the default general address for a single-slave environment, namely 0xf8.

Can return Err(Error::IllegalAddress) if addr is not in range of legal addresses [0x01..0xf8].

pub fn read<T: CountDown>(
    &mut self,
    m: &mut Measurement,
    timeout: Option<(&mut T, T::Time)>
) -> Result<(), Error<WriteError, ReadError>>
[src]

Reads the measurements off the sensor and stores them into m.

The timeout can be omitted (will wait indefinitely) in such a way:

pzem.communicate::<NoTimeout>(&mut m, None).unwrap();

Look NoTimeout.

pub fn get_threshold<T: CountDown>(
    &mut self,
    timeout: Option<(&mut T, T::Time)>
) -> Result<u16, Error<WriteError, ReadError>>
[src]

Reads the current power alarm threshold value of the energy monitor.

In case of success, returns the raw u16 value of the alarm threshold, where 1LSB corresponds to 1W.

pub fn get_addr<T: CountDown>(
    &mut self,
    timeout: Option<(&mut T, T::Time)>
) -> Result<u16, Error<WriteError, ReadError>>
[src]

Reads the current Modbus-RTU address of the energy monitor.

Returns the raw u8 value of the address, or an error.

pub fn set_threshold<T: CountDown>(
    &mut self,
    threshold: u16,
    timeout: Option<(&mut T, T::Time)>
) -> Result<(), Error<WriteError, ReadError>>
[src]

Sets the power alarm threshold value of the energy monitor.

Example

// Will set the alarm threshold to 230 W:
pzem.set_threshold(230, Some(&mut ti, 2.hz())).unwrap();

pub fn set_addr<T: CountDown>(
    &mut self,
    addr: u8,
    timeout: Option<(&mut T, T::Time)>
) -> Result<(), Error<WriteError, ReadError>>
[src]

Sets the Modbus-RTU address of the energy monitor.

Also updates the Pzem struct to refer to the sensor by the new address.

Example

// Will set the slave address to 0x10:
pzem.set_addr(0x10, Some(&mut tim, 2.hz())).unwrap();

pub fn reset_energy<T: CountDown>(
    &mut self,
    timeout: Option<(&mut T, T::Time)>
) -> Result<(), Error<WriteError, ReadError>>
[src]

Sets the energy counting register back to 0.

pub fn release(self) -> Serial[src]

Releases the underlying serial peripheral.

Auto Trait Implementations

impl<Serial> Send for Pzem<Serial> where
    Serial: Send

impl<Serial> Sync for Pzem<Serial> where
    Serial: Sync

impl<Serial> Unpin for Pzem<Serial> where
    Serial: Unpin

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.