pub struct BacnetClient { /* private fields */ }Expand description
High-level BACnet client for device communication
Implementations§
Source§impl BacnetClient
impl BacnetClient
Sourcepub fn new() -> Result<Self, ClientError>
pub fn new() -> Result<Self, ClientError>
Create a new BACnet client with default configuration.
Binds to all interfaces on an OS-assigned ephemeral port with a 5 second
timeout. Use BacnetClient::builder to customize.
Sourcepub fn new_with_local_addr<A: ToSocketAddrs>(
addr: A,
) -> Result<Self, ClientError>
pub fn new_with_local_addr<A: ToSocketAddrs>( addr: A, ) -> Result<Self, ClientError>
Create a new BACnet client with a specific local socket address (any
type implementing ToSocketAddrs).
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Begin building a client with custom configuration.
Sourcepub fn local_addr(&self) -> Result<SocketAddr, ClientError>
pub fn local_addr(&self) -> Result<SocketAddr, ClientError>
The local socket address the client is bound to.
Sourcepub fn discover_device(
&self,
target_addr: SocketAddr,
) -> Result<DeviceInfo, ClientError>
pub fn discover_device( &self, target_addr: SocketAddr, ) -> Result<DeviceInfo, ClientError>
Discover a device by IP address
Sourcepub fn who_is(
&self,
low_limit: Option<u32>,
high_limit: Option<u32>,
) -> Result<Vec<DeviceInfo>, ClientError>
pub fn who_is( &self, low_limit: Option<u32>, high_limit: Option<u32>, ) -> Result<Vec<DeviceInfo>, ClientError>
Broadcast a Who-Is on the local subnet and collect every device that answers with an I-Am, until the configured timeout elapses.
low_limit and high_limit bound the device-instance range; pass both
to target a range, or None/None to ask every device. Results are
de-duplicated by device id.
Unlike discover_device (which unicasts to a
single known address), this reaches all devices on the local network.
Sourcepub fn who_is_to(
&self,
target_addr: SocketAddr,
low_limit: Option<u32>,
high_limit: Option<u32>,
) -> Result<Vec<DeviceInfo>, ClientError>
pub fn who_is_to( &self, target_addr: SocketAddr, low_limit: Option<u32>, high_limit: Option<u32>, ) -> Result<Vec<DeviceInfo>, ClientError>
Send a Who-Is to a specific address (broadcast or unicast) and collect all I-Am replies until the timeout elapses.
This is the explicit-target form of who_is; use it for
subnet-directed broadcasts (e.g. 192.168.1.255:47808) or to query a
BBMD/foreign-device peer directly.
Sourcepub fn read_object_list(
&self,
target_addr: SocketAddr,
device_id: u32,
) -> Result<Vec<ObjectIdentifier>, ClientError>
pub fn read_object_list( &self, target_addr: SocketAddr, device_id: u32, ) -> Result<Vec<ObjectIdentifier>, ClientError>
Read the device’s object list
Sourcepub fn read_objects_properties(
&self,
target_addr: SocketAddr,
objects: &[ObjectIdentifier],
) -> Result<Vec<ObjectInfo>, ClientError>
pub fn read_objects_properties( &self, target_addr: SocketAddr, objects: &[ObjectIdentifier], ) -> Result<Vec<ObjectInfo>, ClientError>
Read properties for multiple objects
Sourcepub fn read_property(
&self,
target_addr: SocketAddr,
object: ObjectIdentifier,
property: PropertyIdentifier,
) -> Result<Vec<PropertyValue>, ClientError>
pub fn read_property( &self, target_addr: SocketAddr, object: ObjectIdentifier, property: PropertyIdentifier, ) -> Result<Vec<PropertyValue>, ClientError>
Read a property of an object and return all decoded values.
Most properties decode to a single value; arrays and lists (e.g.
Object_List, Priority_Array) decode to several, so the full set is
returned. Returns ClientError::PropertyError if the device reports
the property as unknown, or ClientError::Timeout if there is no
response.
Sourcepub fn write_property(
&self,
target_addr: SocketAddr,
object: ObjectIdentifier,
property: PropertyIdentifier,
value: &PropertyValue,
priority: Option<u8>,
) -> Result<(), ClientError>
pub fn write_property( &self, target_addr: SocketAddr, object: ObjectIdentifier, property: PropertyIdentifier, value: &PropertyValue, priority: Option<u8>, ) -> Result<(), ClientError>
Write a single property of an object.
priority is the BACnet command priority (1-16) for commandable
properties such as Present_Value; pass None to omit it. A successful
write is acknowledged with a SimpleAck; a device-side failure surfaces as
ClientError::PropertyError / ClientError::Rejected /
ClientError::Abort.
Sourcepub fn write_property_verified(
&self,
target_addr: SocketAddr,
object: ObjectIdentifier,
property: PropertyIdentifier,
value: &PropertyValue,
priority: Option<u8>,
) -> Result<WriteOutcome, ClientError>
pub fn write_property_verified( &self, target_addr: SocketAddr, object: ObjectIdentifier, property: PropertyIdentifier, value: &PropertyValue, priority: Option<u8>, ) -> Result<WriteOutcome, ClientError>
Write a property and then read it back to confirm it took effect.
This is the safe way to command a value: it returns
Err(..)if the device refused the write (Error/Reject/Abort) or a transfer failed;Ok(WriteOutcome::Verified)if the read-back matchesvalue;Ok(WriteOutcome::NotEffective { read_back })if the device acknowledged the write but the property still reports a different value (e.g. a higher-priority command is winning, or the property is not commandable at this priority).
Floating-point values are compared with a small tolerance.
A device commonly returns the SimpleAck before Present_Value reflects
the new command (priority-array resolution can lag), so the read-back is
polled a few times before concluding the write did not take effect.