modbus

package
v0.0.0-...-bd59d96 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const (
	Tcp Protocol = iota
	Rtu
	Ascii
	Udp

	CoilOn uint16 = 0xFF00
)

Variables

This section is empty.

Functions

func Lock

func Lock()

func Unlock

func Unlock()

Types

type Connection

type Connection struct {
	meters.Connection
	// contains filtered or unexported fields
}

Connection is a logical modbus connection per slave ID sharing a physical connection

func NewConnection

func NewConnection(uri, device, comset string, baudrate int, proto Protocol, slaveID uint8) (*Connection, error)

NewConnection creates physical modbus device from config

func (*Connection) Addr

func (c *Connection) Addr() string

func (*Connection) Clone

func (c *Connection) Clone(slaveID uint8) *Connection

func (*Connection) ConnectDelay

func (c *Connection) ConnectDelay(delay time.Duration)

TODO resolve conflicts

func (*Connection) Delay

func (c *Connection) Delay(delay time.Duration)

func (*Connection) Logger

func (c *Connection) Logger(logger meters.Logger)

func (*Connection) MaskWriteRegister

func (c *Connection) MaskWriteRegister(address, andMask, orMask uint16) (results []byte, err error)

func (Connection) Printf

func (l Connection) Printf(format string, v ...interface{})

Printf implements modbus.Logger interface. Must always be called while being wrapped in WithLogger, hence the lock is held.

func (*Connection) ReadCoils

func (c *Connection) ReadCoils(address, quantity uint16) ([]byte, error)

func (*Connection) ReadDiscreteInputs

func (c *Connection) ReadDiscreteInputs(address, quantity uint16) (results []byte, err error)

func (*Connection) ReadFIFOQueue

func (c *Connection) ReadFIFOQueue(address uint16) (results []byte, err error)

func (*Connection) ReadHoldingRegisters

func (c *Connection) ReadHoldingRegisters(address, quantity uint16) ([]byte, error)

func (*Connection) ReadInputRegisters

func (c *Connection) ReadInputRegisters(address, quantity uint16) ([]byte, error)

func (*Connection) ReadWriteMultipleRegisters

func (c *Connection) ReadWriteMultipleRegisters(readAddress, readQuantity, writeAddress, writeQuantity uint16, value []byte) (results []byte, err error)

func (*Connection) Timeout

func (c *Connection) Timeout(timeout time.Duration)

TODO resolve conflicts

func (Connection) WithLogger

func (l Connection) WithLogger(logger modbus.Logger, fun func() ([]byte, error)) ([]byte, error)

func (*Connection) WriteMultipleCoils

func (c *Connection) WriteMultipleCoils(address, quantity uint16, value []byte) (results []byte, err error)

func (*Connection) WriteMultipleRegisters

func (c *Connection) WriteMultipleRegisters(address, quantity uint16, value []byte) ([]byte, error)

func (*Connection) WriteSingleCoil

func (c *Connection) WriteSingleCoil(address, value uint16) ([]byte, error)

func (*Connection) WriteSingleRegister

func (c *Connection) WriteSingleRegister(address, value uint16) ([]byte, error)

type Protocol

type Protocol int

type Register

type Register struct {
	Address  uint16 // Length  uint16
	Type     string
	Decode   string // TODO deprecated, use Encoding
	Encoding string
	BitMask  string
}

Register contains the ModBus register configuration

func (Register) DecodeFunc

func (r Register) DecodeFunc() (func([]byte) float64, error)

func (Register) EncodeFunc

func (r Register) EncodeFunc() (func(float64) ([]byte, error), error)

func (Register) Error

func (r Register) Error() error

func (Register) FuncCode

func (r Register) FuncCode() (uint8, error)

func (Register) Length

func (r Register) Length() (uint16, error)

func (Register) Operation

func (r Register) Operation() (RegisterOperation, error)

Operation creates a modbus operation from a register definition

type RegisterOperation

type RegisterOperation struct {
	FuncCode uint8
	Addr     uint16
	Length   uint16
}

type Settings

type Settings struct {
	ID                  uint8
	SubDevice           int
	URI, Device, Comset string
	Baudrate            int
	UDP                 bool
	RTU                 *bool // indicates RTU over TCP if true
}

Settings contains the ModBus settings

func (Settings) Protocol

func (s Settings) Protocol() Protocol

Protocol identifies the wire format from the RTU setting

func (*Settings) String

func (s *Settings) String() string

type SunSpecOperation

type SunSpecOperation struct {
	Model, Block int
	Point        string
}

SunSpecOperation is a sunspec modbus operation

func ParsePoint

func ParsePoint(selector string) (SunSpecOperation, error)

ParsePoint parses sunspec point from string

type TcpSettings

type TcpSettings struct {
	URI string
	ID  uint8
	RTU *bool `mapstructure:"rtu"`
}

Settings contains the ModBus TCP settings RTU field is included for compatibility with modbus.tpl which renders rtu: false for TCP TODO remove RTU field (https://github.com/evcc-io/evcc/issues/3360)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL