Skip to content

Commit

Permalink
Support ABB initilization
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Aug 26, 2019
1 parent f9762f5 commit 3f3392f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
6 changes: 5 additions & 1 deletion meters/rs485/abb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package rs485
import (
"math"

"github.com/grid-x/modbus"
. "github.com/volkszaehler/mbmd/meters"
)

func init() {
Register(NewABBProducer)
}


type signedness int

const (
Expand Down Expand Up @@ -69,6 +69,10 @@ func (p *ABBProducer) Description() string {
return "ABB A/B-Series meters"
}

func (p *ABBProducer) Initialize(client modbus.Client, descriptor *DeviceDescriptor) error {
return initializeMID(client, descriptor)
}

// wrapTransform validates if reading result is undefined and returns NaN in that case
func wrapTransform(byteCount uint16, sign signedness, transform RTUTransform) RTUTransform {
var nan []byte
Expand Down
19 changes: 1 addition & 18 deletions meters/rs485/janitza.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package rs485

import (
"encoding/binary"
"fmt"

"github.com/grid-x/modbus"
. "github.com/volkszaehler/mbmd/meters"
)
Expand Down Expand Up @@ -59,21 +56,7 @@ func (p *JanitzaProducer) Description() string {
}

func (p *JanitzaProducer) Initialize(client modbus.Client, descriptor *DeviceDescriptor) error {
// serial
if bytes, err := client.ReadHoldingRegisters(0x8900, 2); err == nil {
descriptor.Serial = fmt.Sprintf("%4d", binary.BigEndian.Uint32(bytes))
}
// firmware
if bytes, err := client.ReadHoldingRegisters(0x8908, 8); err == nil {
descriptor.Version = string(bytes)
}
// type
if bytes, err := client.ReadHoldingRegisters(0x8960, 6); err == nil {
descriptor.Model = string(bytes)
}

// assume success
return nil
return initializeMID(client, descriptor)
}

func (p *JanitzaProducer) snip(iec Measurement) Operation {
Expand Down
20 changes: 20 additions & 0 deletions meters/rs485/rs485.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rs485

import (
"encoding/binary"
"fmt"
"time"

Expand Down Expand Up @@ -119,3 +120,22 @@ func (d *rs485) Query(client modbus.Client) (res []meters.MeasurementResult, err

return res, nil
}

// MID meters initialization method used by Janitza and ABB
func initializeMID(client modbus.Client, descriptor *meters.DeviceDescriptor) error {
// serial
if bytes, err := client.ReadHoldingRegisters(0x8900, 2); err == nil {
descriptor.Serial = fmt.Sprintf("%4d", binary.BigEndian.Uint32(bytes))
}
// firmware
if bytes, err := client.ReadHoldingRegisters(0x8908, 8); err == nil {
descriptor.Version = string(bytes)
}
// type
if bytes, err := client.ReadHoldingRegisters(0x8960, 6); err == nil {
descriptor.Model = string(bytes)
}

// assume success
return nil
}

0 comments on commit 3f3392f

Please sign in to comment.