Documentation ¶
Index ¶
Constants ¶
const ( // ReadCoils is Modbus function code 1. ReadCoils uint8 = iota + 1 // ReadDiscreteInputs is Modbus function code 2. ReadDiscreteInputs // ReadHoldingRegisters is Modbus function code 3. ReadHoldingRegisters // ReadInputRegisters is Modbus function code 4. ReadInputRegisters // WriteSingleCoil is Modbus function code 5. WriteSingleCoil // WriteSingleRegister is Modbus function code 6. WriteSingleRegister // WriteMultipleCoils is Modbus function code 15. WriteMultipleCoils = 15 + 1 // WriteMultipleRegisters is Modbus function code 16. WriteMultipleRegisters )
Variables ¶
var ( // IllegalFunctionError with exception code 1, is returned when the // function received is not an allowable action fwith the slave. IllegalFunctionError = Error{Code: 1, /* contains filtered or unexported fields */} // IllegalAddressError with exception code 2, is returned when the // address received is not an allowable address fwith the slave. IllegalAddressError = Error{Code: 2, /* contains filtered or unexported fields */} // IllegalDataValueError with exception code 3, is returned if the // request contains an value that is not allowable fwith the slave. IllegalDataValueError = Error{Code: 3, /* contains filtered or unexported fields */} // SlaveDeviceFailureError with exception code 4, is returned when // the server isn't able to handle the request. SlaveDeviceFailureError = Error{Code: 4, /* contains filtered or unexported fields */} // AcknowledgeError with exception code 5, is returned when the // server has received the request successfully, but needs a long time // to process the request. AcknowledgeError = Error{Code: 5, /* contains filtered or unexported fields */} // SlaveDeviceBusyError with exception 6, is returned when master is // busy processing a long-running command. SlaveDeviceBusyError = Error{Code: 6, /* contains filtered or unexported fields */} // NegativeAcknowledgeError with exception code 7, is returned for an // unsuccessful programming request using function code 13 or 14. NegativeAcknowledgeError = Error{Code: 7, /* contains filtered or unexported fields */} // MemoryParityError with exception code 8 is returned to indicate that // the extended file area failed to pass a consistency check. May only // returned for requests with function code 20 or 21. MemoryParityError = Error{Code: 8, /* contains filtered or unexported fields */} // the gateway was unable to allocate an internal communication path // from the input port to the output port for processing the request. GatewayPathUnavailableError = Error{Code: 10, /* contains filtered or unexported fields */} // GatewayTargetDeviceFailedToRespondError with exception code 11 // indicates that the device is not present on the network. GatewayTargetDeviceFailedToRespondError = Error{Code: 11, /* contains filtered or unexported fields */} )
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct { // Code contains the Modbus exception code. Code uint8 // contains filtered or unexported fields }
Error represesents a Modbus protocol error.
type MBAP ¶
type MBAP struct { // TransactionID identifies a request/response transaction. TransactionID uint16 // ProtocolID defines the protocol, for Modbus it's always 0. ProtocolID uint16 // Length shows how much bytes are following. Length uint16 // UnitID or slave id identifies a slave. UnitID uint8 }
MBAP is the Modbus Application Header. Only Modbus TCP/IP message have an MBAP header. The MBAP header has 4 fields with a total length of 7 bytes.
func (*MBAP) MarshalBinary ¶
MarshalBinary marshals a MBAP to it binary form.
func (*MBAP) UnmarshalBinary ¶
UnmarshalBinary unmarshals a binary representation of MBAP.
type ReadHandler ¶
type ReadHandler struct {
// contains filtered or unexported fields
}
ReadHandler can be used to respond on Modbus request with function codes 1, 2, 3 and 4.
func NewReadHandler ¶
func NewReadHandler(h ReadHandlerFunc) *ReadHandler
NewReadHandler creates a new ReadHandler.
func (ReadHandler) ServeModbus ¶
func (h ReadHandler) ServeModbus(w io.Writer, req Request)
ServeModbus writes a Modbus response.
type ReadHandlerFunc ¶
ReadHandlerFunc is an adapter to allow the use of ordinary functions as handlers for Modbus read functions.
type Request ¶
Request is a Modbus request.
func (*Request) UnmarshalBinary ¶
UnmarshalBinary unmarshals binary representation of Request.
type Response ¶
type Response struct { MBAP FunctionCode uint8 Data []byte // contains filtered or unexported fields }
Response is a Modbus response.
func NewErrorResponse ¶
NewErrorResponse creates a error response.
func NewResponse ¶
NewResponse creates a Response for a Request.
func (*Response) MarshalBinary ¶
MarshalBinary marshals a Response to it binary form.
type Server ¶
Server is a Modbus server listens on a port and responds on incoming Modbus requests.
func (*Server) SetTimeout ¶
SetTimeout sets the timeout, which is the maximum duraion a request can take.
type Signedness ¶
type Signedness int
Signedness controls the signedness of values for Writehandler's. A value can be unsigned (capabale of representing only non-negative integers) or signed (capable of representing negative integers as well).
const ( // Unsigned set signedness to unsigned. Unsigned Signedness = iota // Signed sets signedness to signed. Signed )
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value is a value an integer ranging from range of -32768 through 65535.
func NewValue ¶
NewValue creates a Value. It returns an error when given value is outside range of -32768 through 65535.
func (*Value) MarshalBinary ¶
MarshalBinary marshals a Value into byte slice with length of 2 bytes.
func (*Value) Set ¶
Set sets the value. It returns an error when given value is outside range of -32768 through 65535.
func (*Value) UnmarshalBinary ¶
func (v *Value) UnmarshalBinary(d []byte, s Signedness) error
UnmarshalBinary value from a byte slice.
type WriteHandler ¶
type WriteHandler struct {
// contains filtered or unexported fields
}
WriteHandler can be used to respond on Modbus request with function codes 5 and 6.
func NewWriteHandler ¶
func NewWriteHandler(h WriteHandlerFunc, s Signedness) *WriteHandler
NewWriteHandler creates a new WriteHandler.
func (WriteHandler) ServeModbus ¶
func (h WriteHandler) ServeModbus(w io.Writer, req Request)
ServeModbus handles a Modbus request and returns a response.
type WriteHandlerFunc ¶
WriteHandlerFunc is an adapter to allow the use of ordinary functions as handlers for Modbus write functions.