chore: introduce CoilOn const (#1927)
This commit is contained in:
parent
3c0e429190
commit
7a54e50a3c
6 changed files with 12 additions and 11 deletions
|
|
@ -112,7 +112,7 @@ func (wb *PhoenixEMEth) Enabled() (bool, error) {
|
|||
func (wb *PhoenixEMEth) Enable(enable bool) error {
|
||||
var u uint16
|
||||
if enable {
|
||||
u = 0xFF00
|
||||
u = modbus.CoilOn
|
||||
}
|
||||
|
||||
_, err := wb.conn.WriteSingleCoil(phxEMEthRegEnable, u)
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ func (wb *PhoenixEVEth) Enabled() (bool, error) {
|
|||
func (wb *PhoenixEVEth) Enable(enable bool) error {
|
||||
var u uint16
|
||||
if enable {
|
||||
u = 0xFF00
|
||||
u = modbus.CoilOn
|
||||
}
|
||||
|
||||
_, err := wb.conn.WriteSingleCoil(phxEVEthRegEnable, u)
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ func (wb *PhoenixEVSer) Enabled() (bool, error) {
|
|||
func (wb *PhoenixEVSer) Enable(enable bool) error {
|
||||
var u uint16
|
||||
if enable {
|
||||
u = 0xFF00
|
||||
u = modbus.CoilOn
|
||||
}
|
||||
|
||||
_, err := wb.conn.WriteSingleCoil(phxEVSerRegEnable, u)
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ func (wb *Wallbe) Enabled() (bool, error) {
|
|||
func (wb *Wallbe) Enable(enable bool) error {
|
||||
var u uint16
|
||||
if enable {
|
||||
u = 0xFF00
|
||||
u = modbus.CoilOn
|
||||
}
|
||||
|
||||
_, err := wb.conn.WriteSingleCoil(wbRegEnable, u)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/modbus"
|
||||
gridx "github.com/grid-x/modbus"
|
||||
"github.com/volkszaehler/mbmd/meters"
|
||||
"github.com/volkszaehler/mbmd/meters/rs485"
|
||||
"github.com/volkszaehler/mbmd/meters/sunspec"
|
||||
|
|
@ -256,7 +257,7 @@ func (m *Modbus) IntSetter(param string) func(int64) error {
|
|||
uval := uint16(int64(m.scale) * val)
|
||||
|
||||
switch op.FuncCode {
|
||||
case modbus.WriteSingleRegister:
|
||||
case gridx.FuncCodeWriteSingleRegister:
|
||||
_, err = m.conn.WriteSingleRegister(op.OpCode, uval)
|
||||
default:
|
||||
err = fmt.Errorf("unknown function code %d", op.FuncCode)
|
||||
|
|
|
|||
|
|
@ -8,20 +8,20 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/grid-x/modbus"
|
||||
"github.com/volkszaehler/mbmd/meters"
|
||||
"github.com/volkszaehler/mbmd/meters/rs485"
|
||||
"github.com/volkszaehler/mbmd/meters/sunspec"
|
||||
)
|
||||
|
||||
// WriteSingleRegister 16-bit wise write access
|
||||
const WriteSingleRegister = 6 // modbus.FuncCodeWriteSingleRegister
|
||||
|
||||
type WireFormat int
|
||||
|
||||
const (
|
||||
TcpFormat WireFormat = iota
|
||||
RtuFormat
|
||||
AsciiFormat
|
||||
|
||||
CoilOn uint16 = 0xFF00
|
||||
)
|
||||
|
||||
// Settings contains the ModBus settings
|
||||
|
|
@ -254,11 +254,11 @@ func RegisterOperation(r Register) (rs485.Operation, error) {
|
|||
|
||||
switch strings.ToLower(r.Type) {
|
||||
case "holding":
|
||||
op.FuncCode = rs485.ReadHoldingReg
|
||||
op.FuncCode = modbus.FuncCodeReadHoldingRegisters
|
||||
case "input":
|
||||
op.FuncCode = rs485.ReadInputReg
|
||||
op.FuncCode = modbus.FuncCodeReadInputRegisters
|
||||
case "writesingle":
|
||||
op.FuncCode = WriteSingleRegister // modbus.FuncCodeWriteSingleRegister
|
||||
op.FuncCode = modbus.FuncCodeWriteSingleRegister
|
||||
default:
|
||||
return rs485.Operation{}, fmt.Errorf("invalid register type: %s", r.Type)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue