-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoint.go
More file actions
49 lines (41 loc) · 1.22 KB
/
Copy pathpoint.go
File metadata and controls
49 lines (41 loc) · 1.22 KB
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
package modbusorm
// OriginByte the origin byte
type OriginByte []byte
// PointDataType point data type
type PointDataType uint8
const (
PointDataTypeU16 PointDataType = iota
PointDataTypeS16
PointDataTypeU32
PointDataTypeS32
)
// OrderType order type
type OrderType uint8
const (
OrderTypeDefault OrderType = iota // default
OrderTypeBigEndian // high byte first
OrderTypeLittleEndian // low byte first
)
// Point point table
type Point map[string]PointDetails
type PointDetails struct {
// address, like 900, represents read/write from 900th register
Addr uint16
// quantity, like 2, represents 2 registers
Quantity uint16
// coefficient, like 0.1, represents the value should be multiplied by 0.1
Coefficient float64
// offset, like -10, represents the value should be subtracted by 10
Offset float64
// data type, like U16, represents the data type is unsigned 16 bits
DataType PointDataType
// order type, like LittleEndian, represents the byte order is low byte first
OrderType OrderType
}
// GetCoefficient get coefficient, if coefficient not set, return 1
func (p *PointDetails) GetCoefficient() float64 {
if p.Coefficient == 0 {
return 1
}
return p.Coefficient
}