# README
go modbus

Fault-tolerant, fail-fast implementation of Modbus protocol in Go.
Supported functions
Bit access:
- Read Discrete Inputs
- Read Coils
- Write Single Coil
- Write Multiple Coils
16-bit access:
- Read Input Registers
- Read Holding Registers
- Write Single Register
- Write Multiple Registers
- Read/Write Multiple Registers
- Mask Write Register
- Read FIFO Queue
Supported formats
- TCP
- Serial (RTU, ASCII)
Usage
Basic usage:
// Modbus TCP
client := modbus.TCPClient("localhost:502")
// Read input register 9
results, err := client.ReadInputRegisters(8, 1)
// Modbus RTU/ASCII
// Default configuration is 19200, 8, 1, even
client = modbus.RTUClient("/dev/ttyS0")
results, err = client.ReadCoils(2, 1)
Advanced usage:
// Modbus TCP
handler := modbus.NewTCPClientHandler("localhost:502")
handler.Timeout = 10 * time.Second
handler.SlaveId = 0xFF
handler.Logger = log.New(os.Stdout, "test: ", log.LstdFlags)
// Connect manually so that multiple requests are handled in one connection session
err := handler.Connect()
defer handler.Close()
client := modbus.NewClient(handler)
results, err := client.ReadDiscreteInputs(15, 2)
results, err = client.WriteMultipleRegisters(1, 2, []byte{0, 3, 0, 4})
results, err = client.WriteMultipleCoils(5, 10, []byte{4, 3})
// Modbus RTU/ASCII
handler := modbus.NewRTUClientHandler("/dev/ttyUSB0")
handler.BaudRate = 115200
handler.DataBits = 8
handler.Parity = "N"
handler.StopBits = 1
handler.SlaveId = 1
handler.Timeout = 5 * time.Second
err := handler.Connect()
defer handler.Close()
client := modbus.NewClient(handler)
results, err := client.ReadDiscreteInputs(15, 2)
References
# Packages
No description provided by the author
# Functions
ASCIIClient creates ASCII client with default handler and given connect string.
NewASCIIClientHandler allocates and initializes a ASCIIClientHandler.
NewClient creates a new modbus client with given backend handler.
NewClient2 creates a new modbus client with given backend packager and transporter.
NewRTUClientHandler allocates and initializes a RTUClientHandler.
NewTCPClientHandler allocates a new TCPClientHandler.
RTUClient creates RTU client with default handler and given connect string.
TCPClient creates TCP client with default handler and given connect string.
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Bit access.
No description provided by the author
No description provided by the author
16-bit access.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
ASCIIClientHandler implements Packager and Transporter interface.
ModbusError implements error interface.
ProtocolDataUnit (PDU) is independent of underlying communication layers.
RTUClientHandler implements Packager and Transporter interface.
TCPClientHandler implements Packager and Transporter interface.
# Interfaces
No description provided by the author
ClientHandler is the interface that groups the Packager and Transporter methods.
Packager specifies the communication layer.
Transporter specifies the transport layer.