1use thiserror::Error;
2
3#[derive(Error, Debug)]
5pub enum ModbusError {
6 #[error("I/O error: {0}")]
8 Io(#[from] std::io::Error),
9
10 #[error("CRC error: expected {expected:04x}, got {actual:04x}")]
12 CrcError {
13 expected: u16,
15 actual: u16,
17 },
18
19 #[error("Invalid function code: {0}")]
21 InvalidFunctionCode(u8),
22
23 #[error("Connection timeout after {0:?}")]
25 Timeout(std::time::Duration),
26
27 #[error("Invalid register address: {0} (max: 65535)")]
29 InvalidAddress(u16),
30
31 #[error("Invalid register count: {0} (max: 125)")]
33 InvalidCount(u16),
34
35 #[error("Modbus exception: code {code}, function {function}")]
37 ModbusException {
38 code: u8,
40 function: u8,
42 },
43
44 #[error("Configuration error: {0}")]
46 Config(String),
47
48 #[error("RDF mapping error: {0}")]
50 RdfMapping(String),
51}
52
53pub type ModbusResult<T> = Result<T, ModbusError>;