modbus_rtu/error/request_packet.rs
1/// Errors that can occur while building a Modbus RTU request packet.
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3pub enum RequestPacketError {
4 /// This error is raised when the function tries to produce a request packet
5 /// that exceeds the Modbus RTU protocol's maximum packet length of 256 bytes.
6 ///
7 /// Requests that attempt to write too many values at once will exceed
8 /// the 256-byte limit of the request packet.
9 ///
10 /// ---
11 ///
12 /// If you intentionally need to bypass the request packet length limit,
13 /// enable the Cargo feature as shown below.
14 ///
15 /// ## Warning: packets produced with this feature enabled may fail during communication.
16 ///
17 /// ```ignore
18 /// [dependencies]
19 /// modbus-rtu = { version = "1.0", features = ["unlimited_packet_size"] }
20 /// ```
21 ///
22 RequestTooBig,
23
24 /// This error is raised when the expected response packet would exceed the
25 /// Modbus RTU protocol's maximum packet length of 256 bytes.
26 ///
27 /// ---
28 ///
29 /// If you intentionally need to bypass the response packet length limit,
30 /// enable the Cargo feature as shown below.
31 ///
32 /// ## Warning: packets produced with this feature enabled may fail during communication.
33 ///
34 /// ```ignore
35 /// [dependencies]
36 /// modbus-rtu = { version = "1.0", features = ["unlimited_packet_size"] }
37 /// ```
38 ///
39 ResponseWillTooBig,
40
41 /// This error occurs when attempting to broadcast a function that does not
42 /// support broadcasting (e.g., 0x01, 0x03).
43 ///
44 /// ---
45 ///
46 /// If you intentionally need to broadcast such functions, enable the Cargo
47 /// feature as shown below.
48 ///
49 /// ## Warning: packets produced with this feature enabled may fail during communication.
50 ///
51 /// ```ignore
52 /// [dependencies]
53 /// modbus-rtu = { version = "1.0", features = ["enforce_broadcast"] }
54 /// ```
55 ///
56 CannotBroadcast,
57}
58
59impl core::fmt::Display for RequestPacketError {
60 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
61 let message = match self {
62 Self::RequestTooBig => "request packet exceeds 256-byte.",
63 Self::ResponseWillTooBig => "expected response packet exceeds 256-byte.",
64 Self::CannotBroadcast => "this function does not support Modbus RTU broadcasting.",
65 };
66 f.write_str(message)
67 }
68}
69
70impl core::error::Error for RequestPacketError {}