Documentation
¶
Index ¶
- type Actor
- func (a *Actor) MaskWriteRegister(address, andMask, orMask uint16) ([]byte, error)
- func (a *Actor) ReadCoils(address, quantity uint16) ([]byte, error)
- func (a *Actor) ReadDiscreteInputs(address, quantity uint16) ([]byte, error)
- func (a *Actor) ReadFIFOQueue(address uint16) ([]byte, error)
- func (a *Actor) ReadHoldingRegisters(address, quantity uint16) ([]byte, error)
- func (a *Actor) ReadInputRegisters(address, quantity uint16) ([]byte, error)
- func (a *Actor) ReadWriteMultipleRegisters(readAddress, readQuantity, writeAddress, writeQuantity uint16, value []byte) ([]byte, error)
- func (a *Actor) Run(ctx context.Context) error
- func (a *Actor) WriteMultipleCoils(address, quantity uint16, value []byte) ([]byte, error)
- func (a *Actor) WriteMultipleRegisters(address, quantity uint16, value []byte) ([]byte, error)
- func (a *Actor) WriteSingleCoil(address, value uint16) ([]byte, error)
- func (a *Actor) WriteSingleRegister(address, value uint16) ([]byte, error)
- type ActorOption
- func WithInboxSize(size int) ActorOption
- func WithOnRequest(handler func(functionCode byte, slaveId byte, address uint16, quantity uint16)) ActorOption
- func WithOnResponse(...) ActorOption
- func WithOnStart(handler func(protocol ModbusProtocol, address string, slaveId byte)) ActorOption
- func WithRS485Config(enabled bool, delayRts time.Duration, delayCustom time.Duration) ActorOption
- func WithSerialConfig(baud int, dataBits int, stopBits int, parity string) ActorOption
- func WithTimeout(timeout time.Duration) ActorOption
- type ModbusProtocol
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Actor ¶
Actor is an actor that handles Modbus communication using the specified protocol and configuration.
It processes Modbus requests sequentially and can be configured with various options such as mailbox size, timeouts, serial settings, and an optional observer for monitoring requests and responses.
func NewActor ¶
func NewActor(name string, protocol ModbusProtocol, address string, slaveId byte, opts ...ActorOption) *Actor
NewActor creates a new Actor with the specified protocol, address, slave ID, and optional configuration options.
func (*Actor) MaskWriteRegister ¶
func (*Actor) ReadDiscreteInputs ¶
func (*Actor) ReadHoldingRegisters ¶
func (*Actor) ReadInputRegisters ¶
func (*Actor) ReadWriteMultipleRegisters ¶
func (*Actor) Run ¶
Run starts the Actor and processes incoming requests. It establishes a connection to the Modbus device based on the configured protocol and handles requests sequentially. The actor will continue running until the context is canceled or an unrecoverable error occurs.
func (*Actor) WriteMultipleCoils ¶
func (*Actor) WriteMultipleRegisters ¶
func (*Actor) WriteSingleCoil ¶
type ActorOption ¶
type ActorOption func(*Actor)
ActorOption defines a function type for configuring the Actor. It allows for flexible configuration of the actor's behavior and settings when creating a new instance.
func WithInboxSize ¶
func WithInboxSize(size int) ActorOption
WithInboxSize sets the size of the actor's inbox. A larger inbox allows for more concurrent requests to be queued, but may increase memory usage. The default mailbox size is 64.
func WithOnRequest ¶
func WithOnRequest(handler func(functionCode byte, slaveId byte, address uint16, quantity uint16)) ActorOption
WithOnRequest allows the caller to provide a callback function that will be invoked before a Modbus request is executed. This can be used for logging, metrics collection, or other side effects related to outgoing Modbus requests.
func WithOnResponse ¶
func WithOnResponse(handler func(functionCode byte, slaveId byte, res []byte, err error, duration time.Duration)) ActorOption
WithOnResponse allows the caller to provide a callback function that will be invoked after a Modbus response is received. This can be used for logging, metrics collection, or other side effects related to incoming Modbus responses, including any errors that may have occurred.
func WithOnStart ¶
func WithOnStart(handler func(protocol ModbusProtocol, address string, slaveId byte)) ActorOption
WithOnStart allows the caller to provide a callback function that will be invoked when the Actor starts and establishes a connection to the Modbus device. This can be used for logging, metrics, or other side effects related to the actor's startup.
func WithRS485Config ¶
WithRS485Config configures RS485 settings for RTU protocol. If enabled, it allows setting delays before and after sending data to accommodate RS485 transceiver timing requirements.
func WithSerialConfig ¶
func WithSerialConfig(baud int, dataBits int, stopBits int, parity string) ActorOption
WithSerialConfig configures serial communication settings for RTU and ASCII protocols. It allows setting the baud rate, data bits, stop bits, and parity. These settings are essential for establishing a proper serial connection with Modbus devices.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ActorOption
WithTimeout sets the timeout duration for Modbus requests. This timeout applies to all requests made by the Actor and determines how long it will wait for a response before considering the request failed.
type ModbusProtocol ¶
type ModbusProtocol int
ModbusProtocol defines the type of Modbus protocol to use (TCP, RTU, ASCII).
const ( TCP ModbusProtocol = iota RTU ASCII )