pub struct SlaveId(/* private fields */);
Expand description
A u8 wrapper type to represent slave ids
Implementations§
Source§impl SlaveId
impl SlaveId
pub const fn new(id: u8) -> Self
Sourcepub const fn new_default_tcp() -> Self
pub const fn new_default_tcp() -> Self
The default TCP slave id is 255 decimal or 0xFF hex.
Addressing in TCP is normally done through the ip address so the slave id just set to 0xFF. In many cases this rule is ignored and a certain slave address is expected. See https://modbus.org/docs/Modbus_Messaging_Implementation_Guide_V1_0b.pdf espacially page 23 for more details.
Sourcepub const fn new_broadcast() -> Self
pub const fn new_broadcast() -> Self
Creates a new broadcast slave id. The broadcast id is 0 and every slave device MUST react to it.
Sourcepub const fn is_device(self) -> bool
pub const fn is_device(self) -> bool
Check if this id is for a normal device. Only false if this is a reserved function code (> 248) or broadcast (0)
Sourcepub const fn is_reserved(self) -> bool
pub const fn is_reserved(self) -> bool
Checks if this function is any reserved slave address other than broadcast. (id > 248)
Sourcepub const fn is_broadcast(self) -> bool
pub const fn is_broadcast(self) -> bool
Checks if this is a broadcast slave id. The broadcast id is 0 and every slave device MUST react to it.
Sourcepub const fn is_default_tcp(self) -> bool
pub const fn is_default_tcp(self) -> bool
Checks if this is the default TCP slave id (0xFF)
Sourcepub const fn must_react(self, other: SlaveId) -> bool
pub const fn must_react(self, other: SlaveId) -> bool
Checks if a device with this slave id has to react to the given slave id other
Sourcepub fn from_data(data: &[u8]) -> (Option<Self>, Option<&[u8]>)
pub fn from_data(data: &[u8]) -> (Option<Self>, Option<&[u8]>)
Gets the slave id of the given modbus data.
None is returned if data contains less than 1 byte
Sourcepub unsafe fn from_data_unchecked(data: &[u8]) -> (Self, &[u8])
pub unsafe fn from_data_unchecked(data: &[u8]) -> (Self, &[u8])
Gets the slave id of the given modbus data.
§Safety
Providing data with less than one byte is undefined behavior