modbus

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Provides helpers for interacting with modbus devices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents a modbus connection.

When the connection is unresponsive, the client will attempt to reconnect.

func Connect

func Connect(addr string) (*Client, error)

Connect connects to the given address using modbus tcp.

func (*Client) Close

func (c *Client) Close() error

func (*Client) ReadFloat32

func (c *Client) ReadFloat32(address uint16) (float32, error)

func (*Client) ReadFloat64

func (c *Client) ReadFloat64(address uint16) (float64, error)

func (*Client) ReadInt16

func (c *Client) ReadInt16(address uint16) (int16, error)

func (*Client) ReadInt32

func (c *Client) ReadInt32(address uint16) (int32, error)

func (*Client) ReadInt64

func (c *Client) ReadInt64(address uint16) (int64, error)

func (*Client) ReadInto

func (c *Client) ReadInto(address uint16, v interface{}) error

ReadInto reads the specified holding register into the given variable.

func (*Client) ReadString

func (c *Client) ReadString(address, words uint16) (string, error)

func (*Client) ReadUint16

func (c *Client) ReadUint16(address uint16) (uint16, error)

func (*Client) ReadUint32

func (c *Client) ReadUint32(address uint16) (uint32, error)

func (*Client) ReadUint64

func (c *Client) ReadUint64(address uint16) (uint64, error)

func (*Client) SetSlaveID

func (c *Client) SetSlaveID(id byte)

SetSlaveID sets the slave id (device address) of following modbus requests.

type Mockbus

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

func NewMockbus

func NewMockbus(i int) *Mockbus

NewMockbus creates a new mockbus instance.

The parameter specifies the number of registers that can be used starting from 0.

func (*Mockbus) AddHoldingRegisterEntries

func (m *Mockbus) AddHoldingRegisterEntries(entries map[uint16]interface{}) error

func (*Mockbus) AddHoldingRegisterEntry

func (m *Mockbus) AddHoldingRegisterEntry(addr uint16, data interface{}) error

func (*Mockbus) ReadHoldingRegisters

func (m *Mockbus) ReadHoldingRegisters(address, quantity uint16) ([]byte, error)

func (*Mockbus) ReadHoldingRegistersUint

func (m *Mockbus) ReadHoldingRegistersUint(address, quantity uint16) ([]uint16, error)

Jump to

Keyboard shortcuts

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