-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodbus.proto
173 lines (161 loc) · 3.87 KB
/
modbus.proto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
syntax = "proto3";
package lebai.modbus;
import "google/protobuf/empty.proto";
import "db.proto";
// Modbus设备类型
enum ModbusKind {
// 机箱IO
ROBOT = 0;
// 法兰IO
FLANGE = 1;
// 拓展IO
EXTRA = 2;
// 法兰ModBus
MODBUS_FLANGE = 3;
// ModBus RTU
MODBUS_RTU = 4;
// ModBus TCP
MODBUS_TCP = 5;
}
// Modbus设备
message Modbus {
// 类型
ModbusKind kind = 12;
// IP地址 或 串口地址
string address = 13;
// TCP端口号
uint32 port = 14;
// ModBus从机地址
uint32 slave_id = 15 [json_name = "slave_id"];
}
message SaveModbusRequest {
string name = 1;
Modbus data = 2;
}
// Modbus寄存器类型
enum ModbusRegisterKind {
// DI
DISCRETE_INPUT = 0;
// DO
COIL = 1;
// AI
INPUT_REGISTER = 2;
// AO
HOLDING_REGISTER = 3;
}
// Modbus寄存器
message ModbusRegister {
ModbusRegisterKind kind = 12;
// ModBus内存地址
uint32 address = 13;
}
message SaveModbusRegisterRequest {
string device = 1;
string name = 2;
ModbusRegister data = 11;
}
message LoadModbusRegisterRequest {
string device = 1;
string name = 2;
}
message LoadModbusRegisterListRequest {
string device = 1;
}
message SetModbusTimeoutRequest {
string device = 1;
// 单次接收超时时间,默认600ms,特殊地0为不超时
uint32 timeout = 11;
}
message SetModbusRetryRequest {
string device = 1;
// 接收超时重试次数,默认0
uint32 timeout = 11;
}
message SetCoilRequest {
string device = 1;
string pin = 2;
bool value = 11;
}
message SetCoilsRequest {
string device = 1;
string pin = 2;
repeated bool values = 11;
}
message GetCoilRequest {
string device = 1;
string pin = 2;
}
message GetCoilResponse {
bool value = 11;
}
message GetCoilsRequest {
string device = 1;
string pin = 2;
uint32 count = 11;
}
message GetCoilsResponse {
repeated bool values = 11;
}
message SetRegisterRequest {
string device = 1;
string pin = 2;
uint32 value = 11;
}
message SetRegistersRequest {
string device = 1;
string pin = 2;
repeated uint32 values = 11;
}
message GetRegisterRequest {
string device = 1;
string pin = 2;
}
message GetRegisterResponse {
uint32 value = 11;
}
message GetRegistersRequest {
string device = 1;
string pin = 2;
uint32 count = 11;
}
message GetRegistersResponse {
repeated uint32 values = 11;
}
// Modbus相关服务
service ModbusService {
// 保存Modbus设备
rpc SaveModbus(SaveModbusRequest) returns (google.protobuf.Empty);
// 查询Modbus设备
rpc LoadModbus(db.LoadRequest) returns (Modbus);
// 查询Modbus设备列表
rpc LoadModbusList(db.LoadListRequest) returns (db.LoadListResponse);
// 保存Modbus寄存器
rpc SaveModbusRegister(SaveModbusRegisterRequest)
returns (google.protobuf.Empty);
// 查询Modbus寄存器
rpc LoadModbusRegister(LoadModbusRegisterRequest) returns (ModbusRegister);
// 查询Modbus寄存器列表
rpc LoadModbusRegisterList(LoadModbusRegisterListRequest)
returns (db.LoadListResponse);
// 设置单次接收超时时间
rpc SetModbusTimeout(SetModbusTimeoutRequest) returns (google.protobuf.Empty);
// 设置接收超时重发次数
rpc SetModbusRetry(SetModbusRetryRequest) returns (google.protobuf.Empty);
// Get DIs
rpc ReadDiscreteInputs(GetCoilsRequest) returns (GetCoilsResponse);
// Get DOs
rpc ReadCoils(GetCoilsRequest) returns (GetCoilsResponse);
// Set DO
rpc WriteSingleCoil(SetCoilRequest) returns (google.protobuf.Empty);
// Set DOs
rpc WriteMultipleCoils(SetCoilsRequest) returns (google.protobuf.Empty);
// Get AIs
rpc ReadInputRegisters(GetRegistersRequest) returns (GetRegistersResponse);
// Get AOs
rpc ReadHoldingRegisters(GetRegistersRequest) returns (GetRegistersResponse);
// Set AO
rpc WriteSingleRegister(SetRegisterRequest) returns (google.protobuf.Empty);
// Set AOs
rpc WriteMultipleRegisters(SetRegistersRequest)
returns (google.protobuf.Empty);
}