Skip to content

Commit 47668c2

Browse files
committed
fix ws100
1 parent e3d8901 commit 47668c2

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

meters/rs485/ws100.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (p *WS100Producer) Description() string {
3434
return "B+G e-tech WS100"
3535
}
3636

37-
func (p *WS100Producer) snip(iec Measurement, readlen uint16, sign signedness, transform RTUTransform, scaler ...float64) Operation {
37+
func (p *WS100Producer) snip(iec Measurement, readlen uint16, transform RTUTransform, scaler ...float64) Operation {
3838
snip := Operation{
3939
FuncCode: ReadHoldingReg,
4040
OpCode: p.Opcodes[iec],
@@ -52,12 +52,22 @@ func (p *WS100Producer) snip(iec Measurement, readlen uint16, sign signedness, t
5252

5353
// snip16u creates modbus operation for single register
5454
func (p *WS100Producer) snip16u(iec Measurement, scaler ...float64) Operation {
55-
return p.snip(iec, 1, unsigned, RTUUint16ToFloat64, scaler...)
55+
return p.snip(iec, 1, RTUUint16ToFloat64, scaler...)
5656
}
5757

5858
// snip32u creates modbus operation for double register
5959
func (p *WS100Producer) snip32u(iec Measurement, scaler ...float64) Operation {
60-
return p.snip(iec, 2, unsigned, RTUUint32ToFloat64, scaler...)
60+
return p.snip(iec, 2, RTUUint32ToFloat64, scaler...)
61+
}
62+
63+
// snip16s creates modbus operation for single register (signed)
64+
func (p *WS100Producer) snip16s(iec Measurement, scaler ...float64) Operation {
65+
return p.snip(iec, 1, RTUInt16ToFloat64, scaler...)
66+
}
67+
68+
// snip32s creates modbus operation for double register (signed)
69+
func (p *WS100Producer) snip32s(iec Measurement, scaler ...float64) Operation {
70+
return p.snip(iec, 2, RTUInt32ToFloat64, scaler...)
6171
}
6272

6373
func (p *WS100Producer) Probe() Operation {
@@ -66,13 +76,25 @@ func (p *WS100Producer) Probe() Operation {
6676

6777
func (p *WS100Producer) Produce() (res []Operation) {
6878
for _, op := range []Measurement{
69-
Voltage, Current,
79+
Voltage,
7080
} {
7181
res = append(res, p.snip32u(op, 1000))
7282
}
7383

7484
for _, op := range []Measurement{
75-
Power, ApparentPower, ReactivePower,
85+
Current,
86+
} {
87+
res = append(res, p.snip32s(op, 1000))
88+
}
89+
90+
for _, op := range []Measurement{
91+
Power, ReactivePower,
92+
} {
93+
res = append(res, p.snip32s(op, 1))
94+
}
95+
96+
for _, op := range []Measurement{
97+
ApparentPower,
7698
} {
7799
res = append(res, p.snip32u(op, 1))
78100
}
@@ -92,7 +114,7 @@ func (p *WS100Producer) Produce() (res []Operation) {
92114
for _, op := range []Measurement{
93115
Cosphi,
94116
} {
95-
res = append(res, p.snip16u(op, 1000))
117+
res = append(res, p.snip16s(op, 1000))
96118
}
97119

98120
return res

0 commit comments

Comments
 (0)