[−][src]Struct pzem004t::Pzem
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]
Serial: Write<u8, Error = WriteError> + Read<u8, Error = ReadError>,
pub fn new(
uart: Serial,
addr: Option<u8>
) -> Result<Self, Error<WriteError, ReadError>>
[src]
uart: Serial,
addr: Option<u8>
) -> Result<Self, Error<WriteError, ReadError>>
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]
&mut self,
m: &mut Measurement,
timeout: Option<(&mut T, T::Time)>
) -> Result<(), Error<WriteError, ReadError>>
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]
&mut self,
timeout: Option<(&mut T, T::Time)>
) -> Result<u16, Error<WriteError, ReadError>>
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]
&mut self,
timeout: Option<(&mut T, T::Time)>
) -> Result<u16, Error<WriteError, ReadError>>
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]
&mut self,
threshold: u16,
timeout: Option<(&mut T, T::Time)>
) -> Result<(), Error<WriteError, ReadError>>
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]
&mut self,
addr: u8,
timeout: Option<(&mut T, T::Time)>
) -> Result<(), Error<WriteError, ReadError>>
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]
&mut self,
timeout: Option<(&mut T, T::Time)>
) -> Result<(), Error<WriteError, ReadError>>
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,
Serial: Send,
impl<Serial> Sync for Pzem<Serial> where
Serial: Sync,
Serial: Sync,
impl<Serial> Unpin for Pzem<Serial> where
Serial: Unpin,
Serial: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,