modbustcp

package
v0.0.0-...-d56bec6 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

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

Server is a Modbus TCP Server implementation. A Server listens on a network and awaits a client's request. Servers are typically sensors or actuators in an industrial setting. Server's methods are not all safe for concurrent use.

func NewServer

func NewServer(cfg ServerConfig) (*Server, error)

NewServer returns a Server ready for use. `localhost` in a server address is replaced with `127.0.0.1`

func (*Server) Accept

func (sv *Server) Accept(ctx context.Context) error

Accept begins listening on the server's TCP address. If the server already has a connection this method returns an error. By design Servers can only maintain one connection. File an issue if this does not cover your use case.

func (*Server) Addr

func (sv *Server) Addr() net.Addr

Addr returns the address of the last active connection. If the server has not yet initialized a connection it returns an empty *net.TCPAddr.

func (*Server) DataModel

func (sv *Server) DataModel() peamodbus.DataModel

DataModel returns the active handle the the modbus data model. Changes to the data model are reflected in the server's behavior. There is no concurrent protection for the data model.

func (*Server) Err

func (sv *Server) Err() error

Err returns the error that caused disconnection. Is safe for concurrent use.

func (*Server) HandleNext

func (sv *Server) HandleNext() (err error)

HandleNext reads the next message on the network and handles it automatically. This call is blocking.

func (*Server) IsConnected

func (sv *Server) IsConnected() bool

IsConnected returns true if the server has an active connection. Is safe for concurrent use.

type ServerConfig

type ServerConfig struct {
	// Formatted numeric IP with port. i.e: "192.168.1.35:502"
	Address string

	// ConnectTimeout is the maximum amount of time a call to Accept will wait for a connect to complete.
	ConnectTimeout time.Duration

	// DataModel defines the data bank used for data access operations
	// such as read/write operations with coils, discrete inputs, holding registers etc.
	// If nil a default data model will be chosen.
	DataModel peamodbus.DataModel
}

ServerConfig provides configuration parameters to NewServer.

Jump to

Keyboard shortcuts

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