Device

Struct Device 

Source
pub struct Device<'c> {
    pub client: &'c Client,
    /* private fields */
}
Expand description

A Client wrapper that talks to a specific ADS device.

Fields§

§client: &'c Client

The underlying Client.

Implementations§

Source§

impl<'c> Device<'c>

Source

pub fn get_info(&self) -> Result<DeviceInfo>

Read the device’s name + version.

Source

pub fn read( &self, index_group: u32, index_offset: u32, data: &mut [u8], ) -> Result<usize>

Read some data at a given index group/offset. Returned data can be shorter than the buffer, the length is the return value.

Source

pub fn read_exact( &self, index_group: u32, index_offset: u32, data: &mut [u8], ) -> Result<()>

Read some data at a given index group/offset, ensuring that the returned data has exactly the size of the passed buffer.

Source

pub fn read_value<T: Default + AsBytes + FromBytes>( &self, index_group: u32, index_offset: u32, ) -> Result<T>

Read data of given type.

Any type that supports zerocopy::FromBytes can be read. You can also derive that trait on your own structures and read structured data directly from the symbol.

Note: to be independent of the host’s byte order, use the integer types defined in zerocopy::byteorder.

Source

pub fn read_multi(&self, requests: &mut [ReadRequest<'_>]) -> Result<()>

Read multiple index groups/offsets with one ADS request (a “sum-up” request).

The returned data can be shorter than the buffer in each case, the length member of the ReadRequest is set to the returned length.

This function only returns Err on errors that cause the whole sum-up request to fail (e.g. if the device doesn’t support such requests). If the request as a whole succeeds, each single read can have returned its own error. The ReadRequest::data method will return either the properly truncated returned data or the error for each read.

Example:

// create buffers
let mut buf_1 = [0; 128];  // request reading 128 bytes
let mut buf_2 = [0; 128];  // from two indices
// create the request structures
let mut req_1 = ReadRequest::new(ix1, off1, &mut buf_1);
let mut req_2 = ReadRequest::new(ix2, off2, &mut buf_2);
//  actual request
device.read_multi(&mut [req_1, req_2])?;
// extract the resulting data, checking individual reads for
// errors and getting the returned data otherwise
let res_1 = req_1.data()?;
let res_2 = req_2.data()?;
Source

pub fn write( &self, index_group: u32, index_offset: u32, data: &[u8], ) -> Result<()>

Write some data to a given index group/offset.

Source

pub fn write_value<T: AsBytes>( &self, index_group: u32, index_offset: u32, value: &T, ) -> Result<()>

Write data of given type.

See read_value for details.

Source

pub fn write_multi(&self, requests: &mut [WriteRequest<'_>]) -> Result<()>

Write multiple index groups/offsets with one ADS request (a “sum-up” request).

This function only returns Err on errors that cause the whole sum-up request to fail (e.g. if the device doesn’t support such requests). If the request as a whole succeeds, each single write can have returned its own error. The WriteRequest::ensure method will return the error for each write.

Source

pub fn write_read( &self, index_group: u32, index_offset: u32, write_data: &[u8], read_data: &mut [u8], ) -> Result<usize>

Write some data to a given index group/offset and then read back some reply from there. This is not the same as a write() followed by read(); it is used as a kind of RPC call.

Source

pub fn write_read_exact( &self, index_group: u32, index_offset: u32, write_data: &[u8], read_data: &mut [u8], ) -> Result<()>

Like write_read, but ensure the returned data length matches the output buffer.

Source

pub fn write_read_multi( &self, requests: &mut [WriteReadRequest<'_>], ) -> Result<()>

Write multiple index groups/offsets with one ADS request (a “sum-up” request).

This function only returns Err on errors that cause the whole sum-up request to fail (e.g. if the device doesn’t support such requests). If the request as a whole succeeds, each single write/read can have returned its own error. The WriteReadRequest::data method will return either the properly truncated returned data or the error for each write/read.

Source

pub fn get_state(&self) -> Result<(AdsState, u16)>

Return the ADS and device state of the device.

Source

pub fn write_control(&self, ads_state: AdsState, dev_state: u16) -> Result<()>

(Try to) set the ADS and device state of the device.

Source

pub fn add_notification( &self, index_group: u32, index_offset: u32, attributes: &Attributes, ) -> Result<Handle>

Add a notification handle for some index group/offset.

Notifications are delivered via a MPMC channel whose reading end can be obtained from get_notification_channel on the Client object. The returned Handle can be used to check which notification has fired.

If the notification is not deleted explictly using delete_notification and the Handle, it is deleted when the Client object is dropped.

Source

pub fn add_notification_multi( &self, requests: &mut [AddNotifRequest], ) -> Result<()>

Add multiple notification handles.

This function only returns Err on errors that cause the whole sum-up request to fail (e.g. if the device doesn’t support such requests). If the request as a whole succeeds, each single read can have returned its own error. The AddNotifRequest::handle method will return either the returned handle or the error for each read.

Source

pub fn delete_notification(&self, handle: Handle) -> Result<()>

Delete a notification with given handle.

Source

pub fn delete_notification_multi( &self, requests: &mut [DelNotifRequest], ) -> Result<()>

Delete multiple notification handles.

This function only returns Err on errors that cause the whole sum-up request to fail (e.g. if the device doesn’t support such requests). If the request as a whole succeeds, each single read can have returned its own error. The DelNotifRequest::ensure method will return either the returned data or the error for each read.

Trait Implementations§

Source§

impl<'c> Clone for Device<'c>

Source§

fn clone(&self) -> Device<'c>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'c> Copy for Device<'c>

Auto Trait Implementations§

§

impl<'c> Freeze for Device<'c>

§

impl<'c> !RefUnwindSafe for Device<'c>

§

impl<'c> !Send for Device<'c>

§

impl<'c> !Sync for Device<'c>

§

impl<'c> Unpin for Device<'c>

§

impl<'c> !UnwindSafe for Device<'c>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.