modbus

package
v0.0.0-...-175a4df Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Tcp Protocol = iota
	Rtu
	Ascii

	CoilOn uint16 = 0xFF00
)

Variables

This section is empty.

Functions

func IsRS485

func IsRS485(model string) bool

IsRS485 determines if model is a known MBMD rs485 device model

func NewDevice

func NewDevice(model string, subdevice int) (device meters.Device, err error)

NewDevice creates physical modbus device from config

func ParseOperation

func ParseOperation(dev meters.Device, measurement string, op *Operation) (err error)

ParseOperation parses an MBMD measurement or SunsSpec point definition into a modbus operation

func ParsePoint

func ParsePoint(selector string) (model, block int, point string, err error)

ParsePoint parses sunspec point from string

func RS485FindDeviceOp

func RS485FindDeviceOp(device *rs485.RS485, measurement meters.Measurement) (op rs485.Operation, err error)

RS485FindDeviceOp checks is RS485 device supports operation

func RTUFloat64ToFloat64

func RTUFloat64ToFloat64(b []byte) float64

func RegisterOperation

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

RegisterOperation creates a read operation from a register definition

Types

type Connection

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

Connection decorates a meters.Connection with transparent slave id and error handling

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) ConnectDelay

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

ConnectDelay sets the initial delay after connecting before starting communication

func (*Connection) Delay

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

Delay sets delay so use between subsequent modbus operations

func (*Connection) Logger

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

Logger sets logger implementation

func (*Connection) MaskWriteRegister

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

func (*Connection) MaskWriteRegisterWithSlave

func (mb *Connection) MaskWriteRegisterWithSlave(slaveID uint8, address, andMask, orMask uint16) (results []byte, err error)

MaskWriteRegister wraps the underlying implementation

func (*Connection) ReadCoils

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

func (*Connection) ReadCoilsWithSlave

func (mb *Connection) ReadCoilsWithSlave(slaveID uint8, address, quantity uint16) ([]byte, error)

ReadCoils wraps the underlying implementation

func (*Connection) ReadDiscreteInputs

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

func (*Connection) ReadDiscreteInputsWithSlave

func (mb *Connection) ReadDiscreteInputsWithSlave(slaveID uint8, address, quantity uint16) (results []byte, err error)

ReadDiscreteInputs wraps the underlying implementation

func (*Connection) ReadFIFOQueue

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

func (*Connection) ReadFIFOQueueWithSlave

func (mb *Connection) ReadFIFOQueueWithSlave(slaveID uint8, address uint16) (results []byte, err error)

ReadFIFOQueue wraps the underlying implementation

func (*Connection) ReadHoldingRegisters

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

func (*Connection) ReadHoldingRegistersWithSlave

func (mb *Connection) ReadHoldingRegistersWithSlave(slaveID uint8, address, quantity uint16) ([]byte, error)

ReadHoldingRegisters wraps the underlying implementation

func (*Connection) ReadInputRegisters

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

func (*Connection) ReadInputRegistersWithSlave

func (mb *Connection) ReadInputRegistersWithSlave(slaveID uint8, address, quantity uint16) ([]byte, error)

ReadInputRegisters wraps the underlying implementation

func (*Connection) ReadWriteMultipleRegisters

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

func (*Connection) ReadWriteMultipleRegistersWithSlave

func (mb *Connection) ReadWriteMultipleRegistersWithSlave(slaveID uint8, readAddress, readQuantity, writeAddress, writeQuantity uint16, value []byte) (results []byte, err error)

ReadWriteMultipleRegisters wraps the underlying implementation

func (*Connection) Timeout

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

Timeout sets the connection timeout (not idle timeout)

func (*Connection) WriteMultipleCoils

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

func (*Connection) WriteMultipleCoilsWithSlave

func (mb *Connection) WriteMultipleCoilsWithSlave(slaveID uint8, address, quantity uint16, value []byte) (results []byte, err error)

WriteMultipleCoils wraps the underlying implementation

func (*Connection) WriteMultipleRegisters

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

func (*Connection) WriteMultipleRegistersWithSlave

func (mb *Connection) WriteMultipleRegistersWithSlave(slaveID uint8, address, quantity uint16, value []byte) ([]byte, error)

WriteMultipleRegisters wraps the underlying implementation

func (*Connection) WriteSingleCoil

func (mb *Connection) WriteSingleCoil(address, quantity uint16) ([]byte, error)

func (*Connection) WriteSingleCoilWithSlave

func (mb *Connection) WriteSingleCoilWithSlave(slaveID uint8, address, value uint16) ([]byte, error)

WriteSingleCoil wraps the underlying implementation

func (*Connection) WriteSingleRegister

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

func (*Connection) WriteSingleRegisterWithSlave

func (mb *Connection) WriteSingleRegisterWithSlave(slaveID uint8, address, value uint16) ([]byte, error)

WriteSingleRegister wraps the underlying implementation

type Operation

type Operation struct {
	MBMD    rs485.Operation
	SunSpec SunSpecOperation
}

Operation is a register-based or sunspec modbus operation

type Protocol

type Protocol int

func ProtocolFromRTU

func ProtocolFromRTU(rtu *bool) Protocol

ProtocolFromRTU identifies the wire format from the RTU setting

type Register

type Register struct {
	Address uint16 // Length  uint16
	Type    string
	Decode  string
	BitMask string
}

Register contains the ModBus register configuration

type Settings

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

Settings contains the ModBus settings

func (*Settings) String

func (s *Settings) String() string

type SunSpecOperation

type SunSpecOperation struct {
	Model, Block int
	Point        string
}

SunSpecOperation is a sunspec modbus operation

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/darkmatus/evcc/issues/3360)

Jump to

Keyboard shortcuts

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