-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbfield.go
369 lines (314 loc) · 10.9 KB
/
bfield.go
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
package modbus
import (
"github.com/aldas/go-modbus-client/packet"
"time"
)
// BField is distinct field be requested and extracted from response
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
type BField struct {
Field
// note: this struct exists solely to provide fluent methods to set fields
}
// ServerAddress sets modbus server address for Field. Usage `[network://]host:port`
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (f *BField) ServerAddress(serverAddress string) *BField {
f.Field.ServerAddress = serverAddress
return f
}
// FunctionCode sets FunctionCode for Field
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (f *BField) FunctionCode(functionCode uint8) *BField {
f.Field.FunctionCode = functionCode
return f
}
// RequestInterval sets RequestInterval for Field
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (f *BField) RequestInterval(requestInterval time.Duration) *BField {
f.Field.RequestInterval = Duration(requestInterval)
return f
}
// UnitID sets UnitID for Field
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (f *BField) UnitID(unitID uint8) *BField {
f.Field.UnitID = unitID
return f
}
// Protocol sets Protocol for Field
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (f *BField) Protocol(protocol ProtocolType) *BField {
f.Field.Protocol = protocol
return f
}
// ByteOrder sets word and byte order for Field to be used when extracting values from response
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (f *BField) ByteOrder(byteOrder packet.ByteOrder) *BField {
f.Field.ByteOrder = byteOrder
return f
}
// Name sets name/identifier for Field to be used to uniquely identify value when extracting values from response
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (f *BField) Name(name string) *BField {
f.Field.Name = name
return f
}
// Add adds field into Builder
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (b *Builder) Add(field *BField) *Builder {
b.fields = append(b.fields, field.Field)
return b
}
// Bit add bit (0-15) field to Builder to be requested and extracted
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (b *Builder) Bit(registerAddress uint16, bit uint8) *BField {
return &BField{
Field{
ServerAddress: b.config.ServerAddress,
FunctionCode: b.config.FunctionCode,
UnitID: b.config.UnitID,
Protocol: b.config.Protocol,
RequestInterval: b.config.Interval,
Type: FieldTypeBit,
Address: registerAddress,
Bit: bit,
},
}
}
// Coil adds discrete/coil field to Builder to be requested and extracted by FC1/FC2.
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (b *Builder) Coil(address uint16) *BField {
return &BField{
Field{
ServerAddress: b.config.ServerAddress,
FunctionCode: b.config.FunctionCode,
UnitID: b.config.UnitID,
Protocol: b.config.Protocol,
RequestInterval: b.config.Interval,
Type: FieldTypeCoil,
Address: address,
},
}
}
// Byte add byte field to Builder to be requested and extracted
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (b *Builder) Byte(registerAddress uint16, fromHighByte bool) *BField {
return &BField{
Field{
ServerAddress: b.config.ServerAddress,
FunctionCode: b.config.FunctionCode,
UnitID: b.config.UnitID,
Protocol: b.config.Protocol,
RequestInterval: b.config.Interval,
Type: FieldTypeByte,
Address: registerAddress,
FromHighByte: fromHighByte,
},
}
}
// Uint8 add uint8 field to Builder to be requested and extracted
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (b *Builder) Uint8(registerAddress uint16, fromHighByte bool) *BField {
return &BField{
Field{
ServerAddress: b.config.ServerAddress,
FunctionCode: b.config.FunctionCode,
UnitID: b.config.UnitID,
Protocol: b.config.Protocol,
RequestInterval: b.config.Interval,
Type: FieldTypeUint8,
Address: registerAddress,
FromHighByte: fromHighByte,
},
}
}
// Int8 add int8 field to Builder to be requested and extracted
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (b *Builder) Int8(registerAddress uint16, fromHighByte bool) *BField {
return &BField{
Field{
ServerAddress: b.config.ServerAddress,
FunctionCode: b.config.FunctionCode,
UnitID: b.config.UnitID,
Protocol: b.config.Protocol,
RequestInterval: b.config.Interval,
Type: FieldTypeInt8,
Address: registerAddress,
FromHighByte: fromHighByte,
},
}
}
// Uint16 add uint16 field to Builder to be requested and extracted
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (b *Builder) Uint16(registerAddress uint16) *BField {
return &BField{
Field{
ServerAddress: b.config.ServerAddress,
FunctionCode: b.config.FunctionCode,
UnitID: b.config.UnitID,
Protocol: b.config.Protocol,
RequestInterval: b.config.Interval,
Type: FieldTypeUint16,
Address: registerAddress,
},
}
}
// Int16 add int16 field to Builder to be requested and extracted
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (b *Builder) Int16(registerAddress uint16) *BField {
return &BField{
Field{
ServerAddress: b.config.ServerAddress,
FunctionCode: b.config.FunctionCode,
UnitID: b.config.UnitID,
Protocol: b.config.Protocol,
RequestInterval: b.config.Interval,
Type: FieldTypeInt16,
Address: registerAddress,
},
}
}
// Uint32 add uint32 field to Builder to be requested and extracted
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (b *Builder) Uint32(registerAddress uint16) *BField {
return &BField{
Field{
ServerAddress: b.config.ServerAddress,
FunctionCode: b.config.FunctionCode,
UnitID: b.config.UnitID,
Protocol: b.config.Protocol,
RequestInterval: b.config.Interval,
Type: FieldTypeUint32,
Address: registerAddress,
},
}
}
// Int32 add int32 field to Builder to be requested and extracted
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (b *Builder) Int32(registerAddress uint16) *BField {
return &BField{
Field{
ServerAddress: b.config.ServerAddress,
FunctionCode: b.config.FunctionCode,
UnitID: b.config.UnitID,
Protocol: b.config.Protocol,
RequestInterval: b.config.Interval,
Type: FieldTypeInt32,
Address: registerAddress,
},
}
}
// Uint64 add uint64 field to Builder to be requested and extracted
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (b *Builder) Uint64(registerAddress uint16) *BField {
return &BField{
Field{
ServerAddress: b.config.ServerAddress,
FunctionCode: b.config.FunctionCode,
UnitID: b.config.UnitID,
Protocol: b.config.Protocol,
RequestInterval: b.config.Interval,
Type: FieldTypeUint64,
Address: registerAddress,
},
}
}
// Int64 add int64 field to Builder to be requested and extracted
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (b *Builder) Int64(registerAddress uint16) *BField {
return &BField{
Field{
ServerAddress: b.config.ServerAddress,
FunctionCode: b.config.FunctionCode,
UnitID: b.config.UnitID,
Protocol: b.config.Protocol,
RequestInterval: b.config.Interval,
Type: FieldTypeInt64,
Address: registerAddress,
},
}
}
// Float32 add float32 field to Builder to be requested and extracted
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (b *Builder) Float32(registerAddress uint16) *BField {
return &BField{
Field{
ServerAddress: b.config.ServerAddress,
FunctionCode: b.config.FunctionCode,
UnitID: b.config.UnitID,
Protocol: b.config.Protocol,
RequestInterval: b.config.Interval,
Type: FieldTypeFloat32,
Address: registerAddress,
},
}
}
// Float64 add float64 field to Builder to be requested and extracted
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (b *Builder) Float64(registerAddress uint16) *BField {
return &BField{
Field{
ServerAddress: b.config.ServerAddress,
FunctionCode: b.config.FunctionCode,
UnitID: b.config.UnitID,
Protocol: b.config.Protocol,
RequestInterval: b.config.Interval,
Type: FieldTypeFloat64,
Address: registerAddress,
},
}
}
// String add string field to Builder to be requested and extracted
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (b *Builder) String(registerAddress uint16, length uint8) *BField {
return &BField{
Field{
ServerAddress: b.config.ServerAddress,
FunctionCode: b.config.FunctionCode,
UnitID: b.config.UnitID,
Protocol: b.config.Protocol,
RequestInterval: b.config.Interval,
Type: FieldTypeString,
Length: length,
Address: registerAddress,
},
}
}
// Bytes add raw bytes field to Builder to be requested and extracted. byteLength is length in bytes (1 register is 2 bytes)
//
// Deprecated: use `modbus.Field` struct and methods `Builder.AddAll(fields Fields)` and `Builder.AddField(field Field)`
func (b *Builder) Bytes(registerAddress uint16, byteLength uint8) *BField {
return &BField{
Field{
ServerAddress: b.config.ServerAddress,
FunctionCode: b.config.FunctionCode,
UnitID: b.config.UnitID,
Protocol: b.config.Protocol,
RequestInterval: b.config.Interval,
Type: FieldTypeRawBytes,
Length: byteLength,
Address: registerAddress,
},
}
}