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 ClientThe underlying Client.
Implementations§
Source§impl<'c> Device<'c>
impl<'c> Device<'c>
Sourcepub fn get_info(&self) -> Result<DeviceInfo>
pub fn get_info(&self) -> Result<DeviceInfo>
Read the device’s name + version.
Sourcepub fn read(
&self,
index_group: u32,
index_offset: u32,
data: &mut [u8],
) -> Result<usize>
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.
Sourcepub fn read_exact(
&self,
index_group: u32,
index_offset: u32,
data: &mut [u8],
) -> Result<()>
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.
Sourcepub fn read_value<T: Default + AsBytes + FromBytes>(
&self,
index_group: u32,
index_offset: u32,
) -> Result<T>
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.
Sourcepub fn read_multi(&self, requests: &mut [ReadRequest<'_>]) -> Result<()>
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()?;Sourcepub fn write(
&self,
index_group: u32,
index_offset: u32,
data: &[u8],
) -> Result<()>
pub fn write( &self, index_group: u32, index_offset: u32, data: &[u8], ) -> Result<()>
Write some data to a given index group/offset.
Sourcepub fn write_value<T: AsBytes>(
&self,
index_group: u32,
index_offset: u32,
value: &T,
) -> Result<()>
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.
Sourcepub fn write_multi(&self, requests: &mut [WriteRequest<'_>]) -> Result<()>
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.
Sourcepub fn write_read(
&self,
index_group: u32,
index_offset: u32,
write_data: &[u8],
read_data: &mut [u8],
) -> Result<usize>
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.
Sourcepub fn write_read_exact(
&self,
index_group: u32,
index_offset: u32,
write_data: &[u8],
read_data: &mut [u8],
) -> Result<()>
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.
Sourcepub fn write_read_multi(
&self,
requests: &mut [WriteReadRequest<'_>],
) -> Result<()>
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.
Sourcepub fn get_state(&self) -> Result<(AdsState, u16)>
pub fn get_state(&self) -> Result<(AdsState, u16)>
Return the ADS and device state of the device.
Sourcepub fn write_control(&self, ads_state: AdsState, dev_state: u16) -> Result<()>
pub fn write_control(&self, ads_state: AdsState, dev_state: u16) -> Result<()>
(Try to) set the ADS and device state of the device.
Sourcepub fn add_notification(
&self,
index_group: u32,
index_offset: u32,
attributes: &Attributes,
) -> Result<Handle>
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.
Sourcepub fn add_notification_multi(
&self,
requests: &mut [AddNotifRequest],
) -> Result<()>
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.
Sourcepub fn delete_notification(&self, handle: Handle) -> Result<()>
pub fn delete_notification(&self, handle: Handle) -> Result<()>
Delete a notification with given handle.
Sourcepub fn delete_notification_multi(
&self,
requests: &mut [DelNotifRequest],
) -> Result<()>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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