Documentation ¶
Index ¶
- Variables
- func MeasurementStrings() []string
- func NewASCIIClientHandler(device string, baudrate int, comset string) *modbus.ASCIIClientHandler
- func NewASCIIOverTCPClientHandler(device string) *modbus.ASCIIOverTCPClientHandler
- func NewClientHandler(device string, baudrate int, comset string) *modbus.RTUClientHandler
- func NewRTUOverTCPClientHandler(device string) *modbus.RTUOverTCPClientHandler
- func NewRTUOverUDPClientHandler(device string) *modbus.RTUOverUDPClientHandler
- func NewTCPClientHandler(device string) *modbus.TCPClientHandler
- type ASCII
- func (b *ASCII) Clone(deviceID byte) Connection
- func (b *ASCII) Close()
- func (b *ASCII) ConnectDelay(delay time.Duration)
- func (b *ASCII) Logger(l Logger)
- func (b *ASCII) ModbusClient() modbus.Client
- func (b *ASCII) Slave(deviceID uint8)
- func (b *ASCII) String() string
- func (b *ASCII) Timeout(timeout time.Duration) time.Duration
- type ASCIIOverTCP
- func (b *ASCIIOverTCP) Clone(deviceID byte) Connection
- func (b *ASCIIOverTCP) Close()
- func (b *ASCIIOverTCP) ConnectDelay(delay time.Duration)
- func (b *ASCIIOverTCP) Logger(l Logger)
- func (b *ASCIIOverTCP) ModbusClient() modbus.Client
- func (b *ASCIIOverTCP) Slave(deviceID uint8)
- func (b *ASCIIOverTCP) String() string
- func (b *ASCIIOverTCP) Timeout(timeout time.Duration) time.Duration
- type Connection
- func NewASCII(device string, baudrate int, comset string) Connection
- func NewASCIIOverTCP(address string) Connection
- func NewMock(address string) Connection
- func NewRTU(device string, baudrate int, comset string) Connection
- func NewRTUOverTCP(address string) Connection
- func NewRTUOverUDP(address string) Connection
- func NewTCP(address string) Connection
- type Device
- type DeviceDescriptor
- type Logger
- type Manager
- type Measurement
- type MeasurementResult
- type Mock
- func (b *Mock) Clone(_ byte) Connection
- func (b *Mock) Close()
- func (b *Mock) ConnectDelay(_ time.Duration)
- func (b *Mock) Logger(l Logger)
- func (b *Mock) ModbusClient() modbus.Client
- func (b *Mock) Slave(_ uint8)
- func (b *Mock) String() string
- func (b *Mock) Timeout(timeout time.Duration) time.Duration
- type MockClient
- func (c *MockClient) MaskWriteRegister(address, andMask, orMask uint16) (results []byte, err error)
- func (c *MockClient) ReadCoils(address, quantity uint16) (results []byte, err error)
- func (c *MockClient) ReadDiscreteInputs(address, quantity uint16) (results []byte, err error)
- func (c *MockClient) ReadFIFOQueue(address uint16) (results []byte, err error)
- func (c *MockClient) ReadHoldingRegisters(address, quantity uint16) (results []byte, err error)
- func (c *MockClient) ReadInputRegisters(address, quantity uint16) (results []byte, err error)
- func (c *MockClient) ReadWriteMultipleRegisters(readAddress, readQuantity, writeAddress, writeQuantity uint16, value []byte) (results []byte, err error)
- func (c *MockClient) WriteMultipleCoils(address, quantity uint16, value []byte) (results []byte, err error)
- func (c *MockClient) WriteMultipleRegisters(address, quantity uint16, value []byte) (results []byte, err error)
- func (c *MockClient) WriteSingleCoil(address, value uint16) (results []byte, err error)
- func (c *MockClient) WriteSingleRegister(address, value uint16) (results []byte, err error)
- type RTU
- func (b *RTU) Clone(deviceID byte) Connection
- func (b *RTU) Close()
- func (b *RTU) ConnectDelay(delay time.Duration)
- func (b *RTU) Logger(l Logger)
- func (b *RTU) ModbusClient() modbus.Client
- func (b *RTU) Slave(deviceID uint8)
- func (b *RTU) String() string
- func (b *RTU) Timeout(timeout time.Duration) time.Duration
- type RTUOverTCP
- func (b *RTUOverTCP) Clone(deviceID byte) Connection
- func (b *RTUOverTCP) Close()
- func (b *RTUOverTCP) ConnectDelay(delay time.Duration)
- func (b *RTUOverTCP) Logger(l Logger)
- func (b *RTUOverTCP) ModbusClient() modbus.Client
- func (b *RTUOverTCP) Slave(deviceID uint8)
- func (b *RTUOverTCP) String() string
- func (b *RTUOverTCP) Timeout(timeout time.Duration) time.Duration
- type RTUOverUDP
- func (b *RTUOverUDP) Clone(deviceID byte) Connection
- func (b *RTUOverUDP) Close()
- func (b *RTUOverUDP) ConnectDelay(delay time.Duration)
- func (b *RTUOverUDP) Logger(l Logger)
- func (b *RTUOverUDP) ModbusClient() modbus.Client
- func (b *RTUOverUDP) Slave(deviceID uint8)
- func (b *RTUOverUDP) String() string
- func (b *RTUOverUDP) Timeout(timeout time.Duration) time.Duration
- type TCP
- func (b *TCP) Clone(deviceID byte) Connection
- func (b *TCP) Close()
- func (b *TCP) ConnectDelay(delay time.Duration)
- func (b *TCP) Logger(l Logger)
- func (b *TCP) ModbusClient() modbus.Client
- func (b *TCP) Slave(deviceID uint8)
- func (b *TCP) String() string
- func (b *TCP) Timeout(timeout time.Duration) time.Duration
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNaN indicates a NaN reading result ErrNaN = errors.New("NaN value") // ErrPartiallyOpened indicates a partially opened device ErrPartiallyOpened = errors.New("Device partially opened") )
Functions ¶
func MeasurementStrings ¶
func MeasurementStrings() []string
MeasurementStrings returns a slice of all String values of the enum
func NewASCIIClientHandler ¶
func NewASCIIClientHandler(device string, baudrate int, comset string) *modbus.ASCIIClientHandler
NewASCIIClientHandler creates a serial line ASCII modbus handler
func NewASCIIOverTCPClientHandler ¶
func NewASCIIOverTCPClientHandler(device string) *modbus.ASCIIOverTCPClientHandler
NewASCIIOverTCPClientHandler creates a TCP modbus handler
func NewClientHandler ¶
func NewClientHandler(device string, baudrate int, comset string) *modbus.RTUClientHandler
NewClientHandler creates a serial line RTU modbus handler
func NewRTUOverTCPClientHandler ¶
func NewRTUOverTCPClientHandler(device string) *modbus.RTUOverTCPClientHandler
NewRTUOverTCPClientHandler creates a RTU over TCP modbus handler
func NewRTUOverUDPClientHandler ¶
func NewRTUOverUDPClientHandler(device string) *modbus.RTUOverUDPClientHandler
NewRTUOverUDPClientHandler creates a RTU over TCP modbus handler
func NewTCPClientHandler ¶
func NewTCPClientHandler(device string) *modbus.TCPClientHandler
NewTCPClientHandler creates a TCP modbus handler
Types ¶
type ASCII ¶
type ASCII struct { Client modbus.Client Handler *modbus.ASCIIClientHandler // contains filtered or unexported fields }
ASCII is an ASCII modbus connection
func (*ASCII) Clone ¶
func (b *ASCII) Clone(deviceID byte) Connection
Clone clones the modbus connection.
func (*ASCII) Close ¶
func (b *ASCII) Close()
Close closes the modbus connection. This forces the modbus client to reopen the connection before the next bus operations.
func (*ASCII) ConnectDelay ¶
ConnectDelay sets the the initial delay after connecting before starting communication
func (*ASCII) ModbusClient ¶
ModbusClient returns the RTU modbus client
type ASCIIOverTCP ¶
type ASCIIOverTCP struct { Client modbus.Client Handler *modbus.ASCIIOverTCPClientHandler // contains filtered or unexported fields }
ASCIIOverTCP is an ASCII encoder over a TCP modbus connection
func (*ASCIIOverTCP) Clone ¶
func (b *ASCIIOverTCP) Clone(deviceID byte) Connection
Clone clones the modbus connection.
func (*ASCIIOverTCP) Close ¶
func (b *ASCIIOverTCP) Close()
Close closes the modbus connection. This forces the modbus client to reopen the connection before the next bus operations.
func (*ASCIIOverTCP) ConnectDelay ¶
func (b *ASCIIOverTCP) ConnectDelay(delay time.Duration)
ConnectDelay sets the the initial delay after connecting before starting communication
func (*ASCIIOverTCP) Logger ¶
func (b *ASCIIOverTCP) Logger(l Logger)
Logger sets a logging instance for physical bus operations
func (*ASCIIOverTCP) ModbusClient ¶
func (b *ASCIIOverTCP) ModbusClient() modbus.Client
ModbusClient returns the TCP modbus client
func (*ASCIIOverTCP) Slave ¶
func (b *ASCIIOverTCP) Slave(deviceID uint8)
Slave sets the modbus device id for the following operations
func (*ASCIIOverTCP) String ¶
func (b *ASCIIOverTCP) String() string
String returns the bus connection address (TCP)
type Connection ¶
type Connection interface { // ModbusClient returns the underlying modbus client ModbusClient() modbus.Client // Slave sets the modbus device id for the following operations Slave(deviceID uint8) // Timeout sets the modbus timeout Timeout(timeout time.Duration) time.Duration // ConnectDelay sets the the initial delay after connecting before starting communication ConnectDelay(delay time.Duration) // Close closes the modbus connection. // This forces the modbus client to reopen the connection before the next bus operations. Close() // Clone clones the modbus connection, keeping the underlying transport. Clone(deviceID byte) Connection // Logger sets a logging instance for physical bus operations Logger(l Logger) // String returns the bus device (RTU) or bus connection address (TCP) String() string }
Connection encapsulates a physical modbus connection, either RTU or TCP
func NewASCII ¶
func NewASCII(device string, baudrate int, comset string) Connection
NewASCII creates a RTU modbus client
func NewASCIIOverTCP ¶
func NewASCIIOverTCP(address string) Connection
NewASCIIOverTCP creates a TCP modbus client
func NewRTU ¶
func NewRTU(device string, baudrate int, comset string) Connection
NewRTU creates a RTU modbus client
func NewRTUOverTCP ¶
func NewRTUOverTCP(address string) Connection
NewRTUOverTCP creates a TCP modbus client
func NewRTUOverUDP ¶
func NewRTUOverUDP(address string) Connection
NewRTUOverUDP creates a TCP modbus client
type Device ¶
type Device interface { // Initialize prepares the device for usage. Any setup or initialization should be done here. // It requires that the client has the correct device id applied. Initialize(client modbus.Client) error // Descriptor returns the device descriptor. Since this method does not have // bus access the descriptor should be prepared during initialization. Descriptor() DeviceDescriptor // Probe tests if a basic register, typically VoltageL1, can be read. // It requires that the client has the correct device id applied. Probe(client modbus.Client) (MeasurementResult, error) // Query retrieves all registers that the device supports. // It requires that the client has the correct device id applied. Query(client modbus.Client) ([]MeasurementResult, error) }
Device is a modbus device that can be described, probed and queried
type DeviceDescriptor ¶
type DeviceDescriptor struct { Type string Manufacturer string Model string Options string Version string Serial string SubDevice int }
DeviceDescriptor describes a device
type Logger ¶
type Logger interface {
Printf(format string, v ...interface{})
}
Logger is an injectable logger for grid-x modbus implementation
type Manager ¶
type Manager struct { Conn Connection // contains filtered or unexported fields }
Manager handles devices attached to a connection
func NewManager ¶
func NewManager(conn Connection) *Manager
NewManager creates a new connection manager instance. connection managers operate devices on a connection instance
type Measurement ¶
type Measurement int
Measurement is the type of measurement, i.e. the physical property being measued in common notation
const ( Frequency Measurement Current CurrentL1 CurrentL2 CurrentL3 // phases and sums Voltage VoltageL1 VoltageL2 VoltageL3 Power // synonymous ActivePower PowerL1 PowerL2 PowerL3 ImportPower ImportPowerL1 ImportPowerL2 ImportPowerL3 ExportPower ExportPowerL1 ExportPowerL2 ExportPowerL3 ReactivePower ReactivePowerL1 ReactivePowerL2 ReactivePowerL3 ApparentPower ApparentPowerL1 ApparentPowerL2 ApparentPowerL3 Cosphi CosphiL1 CosphiL2 CosphiL3 THD THDL1 THDL2 THDL3 // energy Sum // synonymous ActiveEnergy SumT1 SumT2 SumL1 SumL2 SumL3 Import ImportT1 ImportT2 ImportL1 ImportL2 ImportL3 Export ExportT1 ExportT2 ExportL1 ExportL2 ExportL3 ReactiveSum ReactiveSumT1 ReactiveSumT2 ReactiveSumL1 ReactiveSumL2 ReactiveSumL3 ReactiveImport ReactiveImportT1 ReactiveImportT2 ReactiveImportL1 ReactiveImportL2 ReactiveImportL3 ReactiveExport ReactiveExportT1 ReactiveExportT2 ReactiveExportL1 ReactiveExportL2 ReactiveExportL3 // DC DCCurrent DCVoltage DCPower HeatSinkTemp // Strings DCCurrentS1 DCVoltageS1 DCPowerS1 DCEnergyS1 DCCurrentS2 DCVoltageS2 DCPowerS2 DCEnergyS2 DCCurrentS3 DCVoltageS3 DCPowerS3 DCEnergyS3 DCCurrentS4 DCVoltageS4 DCPowerS4 DCEnergyS4 // Battery ChargeState BatteryVoltage PhaseAngle )
func MeasurementString ¶
func MeasurementString(s string) (Measurement, error)
MeasurementString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func MeasurementValues ¶
func MeasurementValues() []Measurement
MeasurementValues returns all values of the enum
func (*Measurement) Description ¶
func (m *Measurement) Description() string
Description returns a measurements human-readable name
func (*Measurement) DescriptionAndUnit ¶
func (m *Measurement) DescriptionAndUnit() (string, string)
DescriptionAndUnit returns a measurements human-readable name and its unit
func (Measurement) IsAMeasurement ¶
func (i Measurement) IsAMeasurement() bool
IsAMeasurement returns "true" if the value is listed in the enum definition. "false" otherwise
func (*Measurement) MarshalText ¶
func (m *Measurement) MarshalText() (text []byte, err error)
MarshalText implements encoding.TextMarshaler
func (Measurement) String ¶
func (i Measurement) String() string
type MeasurementResult ¶
type MeasurementResult struct { Measurement Value float64 Timestamp time.Time }
MeasurementResult is the result of modbus read operation
func (MeasurementResult) String ¶
func (r MeasurementResult) String() string
type Mock ¶
Mock mocks a modbus connection
func (*Mock) ConnectDelay ¶
ConnectDelay sets the the initial delay after connecting before starting communication
func (*Mock) ModbusClient ¶
ModbusClient returns the mock modbus client
type MockClient ¶
type MockClient struct {
// contains filtered or unexported fields
}
MockClient is a mock modbus client for testing that is able to simulate devices and errors
func NewMockClient ¶
func NewMockClient(errorRate int32) *MockClient
NewMockClient creates a mock modbus client
func (*MockClient) MaskWriteRegister ¶
func (c *MockClient) MaskWriteRegister(address, andMask, orMask uint16) (results []byte, err error)
MaskWriteRegister implements modbus.Client
func (*MockClient) ReadCoils ¶
func (c *MockClient) ReadCoils(address, quantity uint16) (results []byte, err error)
ReadCoils implements modbus.Client
func (*MockClient) ReadDiscreteInputs ¶
func (c *MockClient) ReadDiscreteInputs(address, quantity uint16) (results []byte, err error)
ReadDiscreteInputs implements modbus.Client
func (*MockClient) ReadFIFOQueue ¶
func (c *MockClient) ReadFIFOQueue(address uint16) (results []byte, err error)
ReadFIFOQueue implements modbus.Client
func (*MockClient) ReadHoldingRegisters ¶
func (c *MockClient) ReadHoldingRegisters(address, quantity uint16) (results []byte, err error)
ReadHoldingRegisters implements modbus.Client
func (*MockClient) ReadInputRegisters ¶
func (c *MockClient) ReadInputRegisters(address, quantity uint16) (results []byte, err error)
ReadInputRegisters implements modbus.Client
func (*MockClient) ReadWriteMultipleRegisters ¶
func (c *MockClient) ReadWriteMultipleRegisters(readAddress, readQuantity, writeAddress, writeQuantity uint16, value []byte) (results []byte, err error)
ReadWriteMultipleRegisters implements modbus.Client
func (*MockClient) WriteMultipleCoils ¶
func (c *MockClient) WriteMultipleCoils(address, quantity uint16, value []byte) (results []byte, err error)
WriteMultipleCoils implements modbus.Client
func (*MockClient) WriteMultipleRegisters ¶
func (c *MockClient) WriteMultipleRegisters(address, quantity uint16, value []byte) (results []byte, err error)
WriteMultipleRegisters implements modbus.Client
func (*MockClient) WriteSingleCoil ¶
func (c *MockClient) WriteSingleCoil(address, value uint16) (results []byte, err error)
WriteSingleCoil implements modbus.Client
func (*MockClient) WriteSingleRegister ¶
func (c *MockClient) WriteSingleRegister(address, value uint16) (results []byte, err error)
WriteSingleRegister implements modbus.Client
type RTU ¶
type RTU struct { Client modbus.Client Handler *modbus.RTUClientHandler // contains filtered or unexported fields }
RTU is an RTU modbus connection
func (*RTU) Clone ¶
func (b *RTU) Clone(deviceID byte) Connection
Clone clones the modbus connection.
func (*RTU) Close ¶
func (b *RTU) Close()
Close closes the modbus connection. This forces the modbus client to reopen the connection before the next bus operations.
func (*RTU) ConnectDelay ¶
ConnectDelay sets the the initial delay after connecting before starting communication
func (*RTU) ModbusClient ¶
ModbusClient returns the RTU modbus client
type RTUOverTCP ¶
type RTUOverTCP struct { Client modbus.Client Handler *modbus.RTUOverTCPClientHandler // contains filtered or unexported fields }
RTUOverTCP is a RTU encoder over a TCP modbus connection
func (*RTUOverTCP) Clone ¶
func (b *RTUOverTCP) Clone(deviceID byte) Connection
Clone clones the modbus connection.
func (*RTUOverTCP) Close ¶
func (b *RTUOverTCP) Close()
Close closes the modbus connection. This forces the modbus client to reopen the connection before the next bus operations.
func (*RTUOverTCP) ConnectDelay ¶
func (b *RTUOverTCP) ConnectDelay(delay time.Duration)
ConnectDelay sets the the initial delay after connecting before starting communication
func (*RTUOverTCP) Logger ¶
func (b *RTUOverTCP) Logger(l Logger)
Logger sets a logging instance for physical bus operations
func (*RTUOverTCP) ModbusClient ¶
func (b *RTUOverTCP) ModbusClient() modbus.Client
ModbusClient returns the TCP modbus client
func (*RTUOverTCP) Slave ¶
func (b *RTUOverTCP) Slave(deviceID uint8)
Slave sets the modbus device id for the following operations
func (*RTUOverTCP) String ¶
func (b *RTUOverTCP) String() string
String returns the bus connection address (TCP)
type RTUOverUDP ¶
type RTUOverUDP struct { Client modbus.Client Handler *modbus.RTUOverUDPClientHandler // contains filtered or unexported fields }
RTUOverUDP is a RTU encoder over a TCP modbus connection
func (*RTUOverUDP) Clone ¶
func (b *RTUOverUDP) Clone(deviceID byte) Connection
Clone clones the modbus connection.
func (*RTUOverUDP) Close ¶
func (b *RTUOverUDP) Close()
Close closes the modbus connection. This forces the modbus client to reopen the connection before the next bus operations.
func (*RTUOverUDP) ConnectDelay ¶
func (b *RTUOverUDP) ConnectDelay(delay time.Duration)
ConnectDelay sets the the initial delay after connecting before starting communication
func (*RTUOverUDP) Logger ¶
func (b *RTUOverUDP) Logger(l Logger)
Logger sets a logging instance for physical bus operations
func (*RTUOverUDP) ModbusClient ¶
func (b *RTUOverUDP) ModbusClient() modbus.Client
ModbusClient returns the TCP modbus client
func (*RTUOverUDP) Slave ¶
func (b *RTUOverUDP) Slave(deviceID uint8)
Slave sets the modbus device id for the following operations
func (*RTUOverUDP) String ¶
func (b *RTUOverUDP) String() string
String returns the bus connection address (TCP)
type TCP ¶
type TCP struct { Client modbus.Client Handler *modbus.TCPClientHandler }
TCP is a TCP modbus connection
func (*TCP) Clone ¶
func (b *TCP) Clone(deviceID byte) Connection
Clone clones the modbus connection.
func (*TCP) Close ¶
func (b *TCP) Close()
Close closes the modbus connection. This forces the modbus client to reopen the connection before the next bus operations.
func (*TCP) ConnectDelay ¶
ConnectDelay sets the the initial delay after connecting before starting communication
func (*TCP) ModbusClient ¶
ModbusClient returns the TCP modbus client