OneWireSearch

Struct OneWireSearch 

Source
pub struct OneWireSearch<'a, T> { /* private fields */ }
Expand description

A structure for searching devices on a 1-Wire bus. This structure implements the search algorithm for discovering devices on the 1-Wire bus. It maintains the state of the search.

Implementations§

Source§

impl<'a, T> OneWireSearch<'a, T>

Source

pub fn new(onewire: &'a mut T, cmd: OneWireSearchKind) -> Self

Creates a new OneWireSearch instance.

§Arguments
  • onewire - A mutable reference to a type that implements the OneWire trait.
  • cmd - The command to use for the search operation (e.g., 0xf0 for normal search, 0xec for search in alarm state).
Source

pub fn with_family( onewire: &'a mut T, cmd: OneWireSearchKind, family: u8, ) -> Self

Creates a new OneWireSearch instance with a specific family code.

§Arguments
  • onewire - A mutable reference to a type that implements the OneWire trait.
  • cmd - The command to use for the search operation (e.g., 0xf0 for normal search, 0xec for search in alarm state).
  • family - The family code of the devices to search for.
Source§

impl<T: OneWire> OneWireSearch<'_, T>

Source

pub fn next(&mut self) -> Result<Option<u64>, OneWireError<T::BusError>>

Searches for devices on the 1-Wire bus. This method implements the 1-Wire search algorithm to discover devices connected to the bus. The next method can be called repeatedly to find all devices on the bus. At the end of the search, calling this method will return None to indicate that no more devices are present. At that point, the search state becomes unusable and should be dropped. The search state is reset if the verify method is called.

§Returns

A result containing the ROM code of the found device as a u64 value.

BitDescription
0-7Family code (e.g., 0x28 for DS18B20)
8-15Serial number (first byte)
16-23Serial number (second byte)
24-31Serial number (third byte)
32-39Serial number (fourth byte)
40-47Serial number (fifth byte)
48-55Serial number (sixth byte)
56-63CRC-8 (0b1_0001_1001 poly)
Source

pub fn verify(&mut self, rom: u64) -> Result<bool, OneWireError<T::BusError>>

Verifies if the device with the given ROM code is present on the 1-Wire bus.

This function should be called with a search state that has been exhausted (i.e., after calling next until it returns None). This functions resets the search state, and calling next after this call will start a new search.

Trait Implementations§

Source§

impl<T> Debug for OneWireSearch<'_, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for OneWireSearch<'a, T>

§

impl<'a, T> RefUnwindSafe for OneWireSearch<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for OneWireSearch<'a, T>
where T: Send,

§

impl<'a, T> Sync for OneWireSearch<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for OneWireSearch<'a, T>

§

impl<'a, T> !UnwindSafe for OneWireSearch<'a, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.