Documentation
¶
Overview ¶
Package modbus implements a proof-of-concept thread-safe Modbus client that operates on batches of requests.
The client is designed to work on high-latency connections where an average delay between a Modbus request and the response to it gets up to a few seconds by using Modbus functions 3 and 16 to combine requests which can be merged into one. See doc of BatchRead/BatchWrite for details.
The client can also optimize batch writes by difference against an older set of values. See doc of BatchWrite for details.
Algorithm ¶
1. For write operations: if differential optimization is enabled, exclude all operations whose register and value match the older written data.
2. Sort operations by register number in ascending order.
3. If out of two consecutive operations A and B the following condition holds true:
A.register + A.quantity = B.register
and the total quantity after merge does not exceed 2047 for reads and 123 for writes, merge operations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrTooManyRegisters = errors.New("too many registers in an operation")
ErrTooManyRegisters is returned when a number of registers exceeds 123 for writes, and 2047 for reads.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
modbus.Client
modbus.ClientHandler
// contains filtered or unexported fields
}
Client is an optimizing Modbus client that operates on chains of requests. It can only execute functions 3 and 16.
Client is only thread-safe if Client and ClientHandler are untouched.
func NewClient ¶
func NewClient(handler modbus.ClientHandler) *Client
NewClient builds a Modbus client from ClientHandler.
func (*Client) BatchRead ¶
BatchRead optimizes a batch of read operations, performs them with function 3 and returns a map of Modbus registers with their corresponding values.
See package documentation for the optimization algoritm.
func (*Client) BatchWrite ¶
BatchWrite optimizes a batch of write operations, performs them with function 16 and returns on the first error encountered.
If oldData is not nil, BatchWrite will perform differential optimization. See package documentation for the optimization algorithm.
Only use differential optimization if it is well-known that the slave registers values never change between BatchWrite invocations.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
Package types provides the most common data types for use with Modbus.
|
Package types provides the most common data types for use with Modbus. |