diff --git a/README.md b/README.md index 95b4138072..c5fe405b54 100644 --- a/README.md +++ b/README.md @@ -359,7 +359,6 @@ type: ... uri/device/id: ... register: address: 40070 - length: 2 # read length in words type: holding # holding or input decode: int32 # int16|32|64, uint16|32|64, float32|64 and u|int32s + float32s scale: -1 # floating point factor applied to result, e.g. for kW to W conversion diff --git a/evcc.dist.yaml b/evcc.dist.yaml index 4932271177..43d8f920a2 100644 --- a/evcc.dist.yaml +++ b/evcc.dist.yaml @@ -87,7 +87,6 @@ meters: id: 1 register: # manual register configuration address: 40070 - length: 2 type: holding decode: int32 scale: -1 # reverse direction diff --git a/go.mod b/go.mod index a7ad60552a..5a8cdd7528 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,7 @@ require ( github.com/spf13/viper v1.6.3 github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e github.com/technoweenie/multipartstreamer v1.0.1 // indirect - github.com/volkszaehler/mbmd v0.0.0-20200524120609-c683601720ed + github.com/volkszaehler/mbmd v0.0.0-20200524133250-a64175ed6a8a golang.org/x/crypto v0.0.0-20200429183012-4b2356b1ed79 // indirect golang.org/x/net v0.0.0-20200505041828-1ed23360d12c golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3 // indirect diff --git a/go.sum b/go.sum index a547d8d6c0..64fc9009e4 100644 --- a/go.sum +++ b/go.sum @@ -251,8 +251,8 @@ github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQ github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= -github.com/volkszaehler/mbmd v0.0.0-20200524120609-c683601720ed h1:oC2QZlpY+AbEPn/8TWvO4FiXrk9uHhCyT24b6wwa/JA= -github.com/volkszaehler/mbmd v0.0.0-20200524120609-c683601720ed/go.mod h1:MmglPXoZJOT0r+tWwAjaaRWmuopdQOq2tWxbL9zvuxE= +github.com/volkszaehler/mbmd v0.0.0-20200524133250-a64175ed6a8a h1:OURwSCpbOBMInNnNE7rmyDpvx/mK7CgZo2UhU6HDvRY= +github.com/volkszaehler/mbmd v0.0.0-20200524133250-a64175ed6a8a/go.mod h1:MmglPXoZJOT0r+tWwAjaaRWmuopdQOq2tWxbL9zvuxE= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/provider/modbus.go b/provider/modbus.go index 250a218655..14a4d39de3 100644 --- a/provider/modbus.go +++ b/provider/modbus.go @@ -46,6 +46,29 @@ func NewModbusFromConfig(log *util.Logger, typ string, other map[string]interfac var device meters.Device var op modbus.Operation + if cc.Value != "" && cc.Register.Decode != "" { + log.FATAL.Fatalf("config: modbus cannot have value and register both") + } + + // model + value configured + if cc.Value != "" { + if err := modbus.ParseOperation(device, cc.Value, &op); err != nil { + log.FATAL.Fatalf("config: invalid value %s", cc.Value) + } + + // if sunspec reading configured make sure model is defined or device won't be initalized + if op.SunSpec.Point != "" && cc.Model == "" { + cc.Model = "SunSpec" + } + } + + // register configured + if cc.Register.Decode != "" { + if op.MBMD, err = modbus.RegisterOperation(cc.Register); err != nil { + log.TRACE.Fatal(err) + } + } + // model configured if cc.Model != "" { device, err = modbus.NewDevice(log, cc.Model, *cc.RTU) @@ -65,20 +88,6 @@ func NewModbusFromConfig(log *util.Logger, typ string, other map[string]interfac log.FATAL.Fatal(err) } - // model + value configured - if cc.Value != "" { - if err := modbus.ParseOperation(device, cc.Value, &op); err != nil { - log.FATAL.Fatalf("invalid value %s", cc.Value) - } - } - - // register configured - if cc.Register.Decode != "" { - if op.MBMD, err = modbus.RegisterOperation(cc.Register); err != nil { - log.TRACE.Fatal(err) - } - } - if cc.Scale == 0 { cc.Scale = 1 } diff --git a/util/modbus/modbus.go b/util/modbus/modbus.go index 3d072e5aa0..f4af5ad5e9 100644 --- a/util/modbus/modbus.go +++ b/util/modbus/modbus.go @@ -195,8 +195,7 @@ type Operation struct { func ParseOperation(dev meters.Device, measurement string, op *Operation) (err error) { // if measurement cannot be parsed it could be SunSpec model/block/point if op.MBMD.IEC61850, err = meters.MeasurementString(measurement); err != nil { - opSunSpec := &SunSpecOperation{} - opSunSpec.Model, opSunSpec.Block, opSunSpec.Point, err = ParsePoint(measurement) + op.SunSpec.Model, op.SunSpec.Block, op.SunSpec.Point, err = ParsePoint(measurement) return err }