Skip to content
This repository has been archived by the owner on Jun 25, 2019. It is now read-only.

Fix floatformat #34

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/github.com/gonium/gosdm630/modbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package sdm630
import (
"encoding/binary"
"fmt"
"github.com/goburrow/modbus"
"log"
"math"
"os"
"time"

"github.com/goburrow/modbus"
)

const (
Expand Down Expand Up @@ -174,7 +175,8 @@ func NewModbusEngine(
mbclient := modbus.NewClient(rtuclient)

return &ModbusEngine{
client: mbclient, handler: rtuclient,
client: mbclient,
handler: rtuclient,
verbose: verbose,
status: status,
}
Expand Down Expand Up @@ -276,7 +278,7 @@ func (q *ModbusEngine) Scan() {
// Check if a SDM device responds: try to query L1 voltage
voltage_L1, err := q.retrieveOpCode(devid, ReadInputReg, OpCodeSDML1Voltage)
if err == nil {
log.Printf("Device %d: SDM type device found, L1 voltage: %.2f\r\n", devid, voltage_L1)
log.Printf("Device %d: SDM type device found, L1 voltage: %.2f\r\n", devid, rtuToFloat64(voltage_L1))
dev := Device{
BusId: devid,
DeviceType: METERTYPE_SDM,
Expand All @@ -286,14 +288,25 @@ func (q *ModbusEngine) Scan() {
// Check if a Janitza device responds: try to query L1 voltage
voltage_L1, err := q.retrieveOpCode(devid, ReadHoldingReg, OpCodeJanitzaL1Voltage)
if err == nil {
log.Printf("Device %d: Janitza type device found, L1 voltage: %.2f\r\n", devid, voltage_L1)
log.Printf("Device %d: Janitza type device found, L1 voltage: %.2f\r\n", devid, rtuToFloat64(voltage_L1))
dev := Device{
BusId: devid,
DeviceType: METERTYPE_JANITZA,
}
devicelist = append(devicelist, dev)
} else {
log.Printf("Device %d: n/a\r\n", devid)
// Check if a Janitza device responds: try to query L1 voltage
voltage_L1, err := q.retrieveOpCode(devid, ReadHoldingReg, OpCodeDZGL1Voltage)
if err == nil {
log.Printf("Device %d: DZG type device found, L1 voltage: %.2f\r\n", devid, rtuToFloat64(voltage_L1))
dev := Device{
BusId: devid,
DeviceType: METERTYPE_DZG,
}
devicelist = append(devicelist, dev)
} else {
log.Printf("Device %d: n/a\r\n", devid)
}
}
}
// give the bus some time to recover before querying the next device
Expand Down