@@ -46,42 +46,49 @@ pub enum FunctionCode {
46
46
47
47
/// Custom Modbus Function Code.
48
48
Custom ( u8 ) ,
49
+
50
+ Disconnect ,
49
51
}
50
52
51
53
impl FunctionCode {
52
54
/// Create a new [`FunctionCode`] with `value`.
53
55
#[ must_use]
54
56
pub const fn new ( value : u8 ) -> Self {
55
57
match value {
56
- 0x01 => FunctionCode :: ReadCoils ,
57
- 0x02 => FunctionCode :: ReadDiscreteInputs ,
58
- 0x05 => FunctionCode :: WriteSingleCoil ,
59
- 0x06 => FunctionCode :: WriteSingleRegister ,
60
- 0x03 => FunctionCode :: ReadHoldingRegisters ,
61
- 0x04 => FunctionCode :: ReadInputRegisters ,
62
- 0x0F => FunctionCode :: WriteMultipleCoils ,
63
- 0x10 => FunctionCode :: WriteMultipleRegisters ,
64
- 0x16 => FunctionCode :: MaskWriteRegister ,
65
- 0x17 => FunctionCode :: ReadWriteMultipleRegisters ,
66
- code => FunctionCode :: Custom ( code) ,
58
+ 0x01 => Self :: ReadCoils ,
59
+ 0x02 => Self :: ReadDiscreteInputs ,
60
+ 0x05 => Self :: WriteSingleCoil ,
61
+ 0x06 => Self :: WriteSingleRegister ,
62
+ 0x03 => Self :: ReadHoldingRegisters ,
63
+ 0x04 => Self :: ReadInputRegisters ,
64
+ 0x0F => Self :: WriteMultipleCoils ,
65
+ 0x10 => Self :: WriteMultipleRegisters ,
66
+ 0x16 => Self :: MaskWriteRegister ,
67
+ 0x17 => Self :: ReadWriteMultipleRegisters ,
68
+ code => Self :: Custom ( code) ,
67
69
}
68
70
}
69
71
70
72
/// Get the [`u8`] value of the current [`FunctionCode`].
73
+ ///
74
+ /// # Panics
75
+ ///
76
+ /// Panics on [`Disconnect`](Self::Disconnect) which has no corresponding Modbus function code.
71
77
#[ must_use]
72
78
pub const fn value ( self ) -> u8 {
73
79
match self {
74
- FunctionCode :: ReadCoils => 0x01 ,
75
- FunctionCode :: ReadDiscreteInputs => 0x02 ,
76
- FunctionCode :: WriteSingleCoil => 0x05 ,
77
- FunctionCode :: WriteSingleRegister => 0x06 ,
78
- FunctionCode :: ReadHoldingRegisters => 0x03 ,
79
- FunctionCode :: ReadInputRegisters => 0x04 ,
80
- FunctionCode :: WriteMultipleCoils => 0x0F ,
81
- FunctionCode :: WriteMultipleRegisters => 0x10 ,
82
- FunctionCode :: MaskWriteRegister => 0x16 ,
83
- FunctionCode :: ReadWriteMultipleRegisters => 0x17 ,
84
- FunctionCode :: Custom ( code) => code,
80
+ Self :: ReadCoils => 0x01 ,
81
+ Self :: ReadDiscreteInputs => 0x02 ,
82
+ Self :: WriteSingleCoil => 0x05 ,
83
+ Self :: WriteSingleRegister => 0x06 ,
84
+ Self :: ReadHoldingRegisters => 0x03 ,
85
+ Self :: ReadInputRegisters => 0x04 ,
86
+ Self :: WriteMultipleCoils => 0x0F ,
87
+ Self :: WriteMultipleRegisters => 0x10 ,
88
+ Self :: MaskWriteRegister => 0x16 ,
89
+ Self :: ReadWriteMultipleRegisters => 0x17 ,
90
+ Self :: Custom ( code) => code,
91
+ Self :: Disconnect => unreachable ! ( ) ,
85
92
}
86
93
}
87
94
}
0 commit comments