Versions in this module Expand all Collapse all v1 v1.5.1 Sep 4, 2026 Changes in this version + const ExceptionCodeAcknowledge + const ExceptionCodeGatewayPathUnavailable + const ExceptionCodeGatewayTargetDeviceFailedToRespond + const ExceptionCodeIllegalDataAddress + const ExceptionCodeIllegalDataValue + const ExceptionCodeIllegalFunction + const ExceptionCodeMemoryParityError + const ExceptionCodeServerDeviceBusy + const ExceptionCodeServerDeviceFailure + const FuncCodeMaskWriteRegister + const FuncCodeReadCoils + const FuncCodeReadDeviceIdentification + const FuncCodeReadDiscreteInputs + const FuncCodeReadFIFOQueue + const FuncCodeReadHoldingRegisters + const FuncCodeReadInputRegisters + const FuncCodeReadWriteMultipleRegisters + const FuncCodeWriteMultipleCoils + const FuncCodeWriteMultipleRegisters + const FuncCodeWriteSingleCoil + const FuncCodeWriteSingleRegister + var ErrStreamDesynced = errors.New("modbus: response stream out of sync with requests") + type ASCIIClientHandler struct + func NewASCIIClientHandler(address string) *ASCIIClientHandler + func (mb *ASCIIClientHandler) Decode(adu []byte) (pdu *ProtocolDataUnit, err error) + func (mb *ASCIIClientHandler) Encode(pdu *ProtocolDataUnit) (adu []byte, err error) + func (mb *ASCIIClientHandler) Send(ctx context.Context, aduRequest []byte) (aduResponse []byte, err error) + func (mb *ASCIIClientHandler) SetSlave(slaveID byte) + func (mb *ASCIIClientHandler) Verify(aduRequest []byte, aduResponse []byte) (err error) + type ASCIIOverTCPClientHandler struct + func NewASCIIOverTCPClientHandler(address string) *ASCIIOverTCPClientHandler + func (mb *ASCIIOverTCPClientHandler) Decode(adu []byte) (pdu *ProtocolDataUnit, err error) + func (mb *ASCIIOverTCPClientHandler) Encode(pdu *ProtocolDataUnit) (adu []byte, err error) + func (mb *ASCIIOverTCPClientHandler) Send(ctx context.Context, aduRequest []byte) (aduResponse []byte, err error) + func (mb *ASCIIOverTCPClientHandler) SetSlave(slaveID byte) + func (mb *ASCIIOverTCPClientHandler) Verify(aduRequest []byte, aduResponse []byte) (err error) + type Client interface + MaskWriteRegister func(ctx context.Context, address, andMask, orMask uint16) (results []byte, err error) + ReadCoils func(ctx context.Context, address, quantity uint16) (results []byte, err error) + ReadDeviceIdentification func(ctx context.Context, readDeviceIDCode ReadDeviceIDCode) (results map[byte][]byte, err error) + ReadDeviceIdentificationSpecificObject func(ctx context.Context, objectID byte) (results map[byte][]byte, err error) + ReadDiscreteInputs func(ctx context.Context, address, quantity uint16) (results []byte, err error) + ReadFIFOQueue func(ctx context.Context, address uint16) (results []byte, err error) + ReadHoldingRegisters func(ctx context.Context, address, quantity uint16) (results []byte, err error) + ReadInputRegisters func(ctx context.Context, address, quantity uint16) (results []byte, err error) + ReadWriteMultipleRegisters func(ctx context.Context, ...) (results []byte, err error) + WriteMultipleCoils func(ctx context.Context, address, quantity uint16, value []byte) (results []byte, err error) + WriteMultipleRegisters func(ctx context.Context, address, quantity uint16, value []byte) (results []byte, err error) + WriteSingleCoil func(ctx context.Context, address, value uint16) (results []byte, err error) + WriteSingleRegister func(ctx context.Context, address, value uint16) (results []byte, err error) + func ASCIIClient(address string) Client + func ASCIIOverTCPClient(address string) Client + func NewClient(handler ClientHandler) Client + func NewClient2(packager Packager, transporter Transporter) Client + func RTUClient(address string) Client + func RTUOverTCPClient(address string) Client + func RTUOverUDPClient(address string) Client + func TCPClient(address string) Client + type ClientHandler interface + type Connector interface + Close func() error + Connect func(ctx context.Context) error + type DataSizeError struct + ActualBytes int + ExpectedBytes int + func (e *DataSizeError) Error() string + type DialFunc func(ctx context.Context, network, addr string) (net.Conn, error) + type ErrADURequestLength int + func (length ErrADURequestLength) Error() string + type ErrADUResponseLength int + func (length ErrADUResponseLength) Error() string + type ErrTCPHeaderLength int + func (length ErrTCPHeaderLength) Error() string + type Error struct + ExceptionCode byte + FunctionCode byte + func (e *Error) Error() string + type InvalidLengthError struct + func (e *InvalidLengthError) Error() string + type Logger interface + Printf func(format string, v ...any) + type Packager interface + Decode func(adu []byte) (pdu *ProtocolDataUnit, err error) + Encode func(pdu *ProtocolDataUnit) (adu []byte, err error) + SetSlave func(slaveID byte) + Verify func(aduRequest []byte, aduResponse []byte) (err error) + type ProtocolDataUnit struct + Data []byte + FunctionCode byte + type RTUClientHandler struct + func NewRTUClientHandler(address string) *RTUClientHandler + func (mb *RTUClientHandler) Decode(adu []byte) (pdu *ProtocolDataUnit, err error) + func (mb *RTUClientHandler) Encode(pdu *ProtocolDataUnit) (adu []byte, err error) + func (mb *RTUClientHandler) Send(ctx context.Context, aduRequest []byte) (aduResponse []byte, err error) + func (mb *RTUClientHandler) SetSlave(slaveID byte) + func (mb *RTUClientHandler) Verify(aduRequest []byte, aduResponse []byte) (err error) + type RTUOverTCPClientHandler struct + func NewRTUOverTCPClientHandler(address string) *RTUOverTCPClientHandler + func (mb *RTUOverTCPClientHandler) Decode(adu []byte) (pdu *ProtocolDataUnit, err error) + func (mb *RTUOverTCPClientHandler) Encode(pdu *ProtocolDataUnit) (adu []byte, err error) + func (mb *RTUOverTCPClientHandler) Send(ctx context.Context, aduRequest []byte) (aduResponse []byte, err error) + func (mb *RTUOverTCPClientHandler) SetSlave(slaveID byte) + func (mb *RTUOverTCPClientHandler) Verify(aduRequest []byte, aduResponse []byte) (err error) + type RTUOverUDPClientHandler struct + func NewRTUOverUDPClientHandler(address string) *RTUOverUDPClientHandler + func (mb *RTUOverUDPClientHandler) Close() error + func (mb *RTUOverUDPClientHandler) Connect(ctx context.Context) error + func (mb *RTUOverUDPClientHandler) Decode(adu []byte) (pdu *ProtocolDataUnit, err error) + func (mb *RTUOverUDPClientHandler) Encode(pdu *ProtocolDataUnit) (adu []byte, err error) + func (mb *RTUOverUDPClientHandler) Send(ctx context.Context, aduRequest []byte) (aduResponse []byte, err error) + func (mb *RTUOverUDPClientHandler) SetSlave(slaveID byte) + func (mb *RTUOverUDPClientHandler) Verify(aduRequest []byte, aduResponse []byte) (err error) + type ReadDeviceIDCode byte + const ReadDeviceIDCodeBasic + const ReadDeviceIDCodeExtended + const ReadDeviceIDCodeRegular + const ReadDeviceIDCodeSpecific + type TCPClientHandler struct + func NewTCPClientHandler(address string, options ...TCPClientHandlerOption) *TCPClientHandler + func (mb *TCPClientHandler) Close() error + func (mb *TCPClientHandler) Connect(ctx context.Context) error + func (mb *TCPClientHandler) Decode(adu []byte) (pdu *ProtocolDataUnit, err error) + func (mb *TCPClientHandler) Encode(pdu *ProtocolDataUnit) (adu []byte, err error) + func (mb *TCPClientHandler) Send(ctx context.Context, aduRequest []byte) (aduResponse []byte, err error) + func (mb *TCPClientHandler) SetSlave(slaveID byte) + func (mb *TCPClientHandler) Verify(aduRequest []byte, aduResponse []byte) error + type TCPClientHandlerOption func(*TCPClientHandler) + func WithDialer(d DialFunc) TCPClientHandlerOption + func WithTLSConfig(config *tls.Config) TCPClientHandlerOption + type Transporter interface + Send func(ctx context.Context, aduRequest []byte) (aduResponse []byte, err error)