@@ -16,37 +16,67 @@ use std::{
16
16
use crate :: bytes:: Bytes ;
17
17
18
18
/// A Modbus function code.
19
+ ///
20
+ /// All function codes as defined by the protocol specification V1.1b3.
19
21
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
20
22
pub enum FunctionCode {
21
- /// Modbus Function Code: `01` (` 0x01`) .
23
+ /// 01 ( 0x01) Read Coils .
22
24
ReadCoils ,
23
- /// Modbus Function Code: `02` (`0x02`).
25
+
26
+ /// 02 (0x02) Read Discrete Inputs
24
27
ReadDiscreteInputs ,
25
28
26
- /// Modbus Function Code: `05` (`0x05`).
29
+ /// 03 (0x03) Read Holding Registers
30
+ ReadHoldingRegisters ,
31
+
32
+ /// 04 (0x04) Read Input Registers
33
+ ReadInputRegisters ,
34
+
35
+ /// 05 (0x05) Write Single Coil
27
36
WriteSingleCoil ,
28
- /// Modbus Function Code: `06` (`0x06`).
37
+
38
+ /// 06 (0x06) Write Single Register
29
39
WriteSingleRegister ,
30
40
31
- /// Modbus Function Code: `03` (`0x03`).
32
- ReadHoldingRegisters ,
33
- /// Modbus Function Code: `04` (`0x04`).
34
- ReadInputRegisters ,
41
+ /// 07 (0x07) Read Exception Status (Serial Line only)
42
+ ReadExceptionStatus ,
43
+
44
+ /// 08 (0x08) Diagnostics (Serial Line only)
45
+ Diagnostics ,
35
46
36
- /// Modbus Function Code: `15` (`0x0F`).
47
+ /// 11 (0x0B) Get Comm Event Counter (Serial Line only)
48
+ GetCommEventCounter ,
49
+
50
+ /// 12 (0x0C) Get Comm Event Log (Serial Line only)
51
+ GetCommEventLog ,
52
+
53
+ /// 15 (0x0F) Write Multiple Coils
37
54
WriteMultipleCoils ,
38
- /// Modbus Function Code: `16` (`0x10`).
55
+
56
+ /// 16 (0x10) Write Multiple Registers
39
57
WriteMultipleRegisters ,
40
58
41
- /// Modbus Function Code: `17` (`0x11`).
59
+ /// 17 (0x11) Report Slave ID (Serial Line only)
42
60
ReportServerId ,
43
61
44
- /// Modbus Function Code: `22` (`0x16`).
62
+ /// 20 (0x14) Read File Record
63
+ ReadFileRecord ,
64
+
65
+ /// 21 (0x15) Write File Record
66
+ WriteFileRecord ,
67
+
68
+ /// 22 (0x16) Mask Write Register
45
69
MaskWriteRegister ,
46
70
47
- /// Modbus Function Code: `23` (` 0x17`).
71
+ /// 23 ( 0x17) Read/Write Multiple Registers
48
72
ReadWriteMultipleRegisters ,
49
73
74
+ /// 24 (0x18) Read FIFO Queue
75
+ ReadFifoQueue ,
76
+
77
+ /// 43 ( 0x2B) Encapsulated Interface Transport
78
+ EncapsulatedInterfaceTransport ,
79
+
50
80
/// Custom Modbus Function Code.
51
81
Custom ( u8 ) ,
52
82
@@ -60,15 +90,23 @@ impl FunctionCode {
60
90
match value {
61
91
0x01 => Self :: ReadCoils ,
62
92
0x02 => Self :: ReadDiscreteInputs ,
63
- 0x05 => Self :: WriteSingleCoil ,
64
- 0x06 => Self :: WriteSingleRegister ,
65
93
0x03 => Self :: ReadHoldingRegisters ,
66
94
0x04 => Self :: ReadInputRegisters ,
95
+ 0x05 => Self :: WriteSingleCoil ,
96
+ 0x06 => Self :: WriteSingleRegister ,
97
+ 0x07 => Self :: ReadExceptionStatus ,
98
+ 0x08 => Self :: Diagnostics ,
99
+ 0x0B => Self :: GetCommEventCounter ,
100
+ 0x0C => Self :: GetCommEventLog ,
67
101
0x0F => Self :: WriteMultipleCoils ,
68
102
0x10 => Self :: WriteMultipleRegisters ,
69
103
0x11 => Self :: ReportServerId ,
104
+ 0x14 => Self :: ReadFileRecord ,
105
+ 0x15 => Self :: WriteFileRecord ,
70
106
0x16 => Self :: MaskWriteRegister ,
71
107
0x17 => Self :: ReadWriteMultipleRegisters ,
108
+ 0x18 => Self :: ReadFifoQueue ,
109
+ 0x2B => Self :: EncapsulatedInterfaceTransport ,
72
110
code => Self :: Custom ( code) ,
73
111
}
74
112
}
@@ -83,15 +121,23 @@ impl FunctionCode {
83
121
match self {
84
122
Self :: ReadCoils => 0x01 ,
85
123
Self :: ReadDiscreteInputs => 0x02 ,
86
- Self :: WriteSingleCoil => 0x05 ,
87
- Self :: WriteSingleRegister => 0x06 ,
88
124
Self :: ReadHoldingRegisters => 0x03 ,
89
125
Self :: ReadInputRegisters => 0x04 ,
126
+ Self :: WriteSingleCoil => 0x05 ,
127
+ Self :: WriteSingleRegister => 0x06 ,
128
+ Self :: ReadExceptionStatus => 0x07 ,
129
+ Self :: Diagnostics => 0x08 ,
130
+ Self :: GetCommEventCounter => 0x0B ,
131
+ Self :: GetCommEventLog => 0x0C ,
90
132
Self :: WriteMultipleCoils => 0x0F ,
91
133
Self :: WriteMultipleRegisters => 0x10 ,
92
134
Self :: ReportServerId => 0x11 ,
135
+ Self :: ReadFileRecord => 0x14 ,
136
+ Self :: WriteFileRecord => 0x15 ,
93
137
Self :: MaskWriteRegister => 0x16 ,
94
138
Self :: ReadWriteMultipleRegisters => 0x17 ,
139
+ Self :: ReadFifoQueue => 0x18 ,
140
+ Self :: EncapsulatedInterfaceTransport => 0x2B ,
95
141
Self :: Custom ( code) => code,
96
142
Self :: Disconnect => unreachable ! ( ) ,
97
143
}
0 commit comments