cmbus

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandUint16

func RandUint16() uint16

func ToStdLogger

func ToStdLogger(l logrus.FieldLogger, level logrus.Level, prefix string, flags int) (*stdlog.Logger, io.Closer, error)

ToStdLogger converts logrus.FieldLogger into *log.Logger in one call. It uses logrus's built-in WriterLevel (so formatter/hooks apply). IMPORTANT: call the returned closer.Close() when you no longer need the logger.

Types

type InstanceConfig

type InstanceConfig struct {
	IsSerial bool
	Channel  models.Channel
	Serial   models.Serial

	URL string `mapstructure:"url"`
}

ModbusConfig:单个 modbus 实例的配置 ModbusConfig: configuration for a single modbus instance.

type ModbusFactory

type ModbusFactory struct{}

ModbusFactory:实现 Factory 接口 ModbusFactory: implements pluginapi.Factory.

func (*ModbusFactory) New

New:根据配置创建实例(真正启动在 Init 中完成) New: create an instance from config (real start happens in Init).

func (*ModbusFactory) Type

func (f *ModbusFactory) Type() string

type ModbusInstance

type ModbusInstance struct {
	Status models.InstanceStatus
	// contains filtered or unexported fields
}

ModbusInstance:具体插件实例,实现 pluginapi.Instance ModbusInstance: concrete plugin instance implementing pluginapi.Instance.

func (*ModbusInstance) Close

func (m *ModbusInstance) Close() error

Close: stop poller and close client.

func (*ModbusInstance) Get

func (m *ModbusInstance) Get() any

func (*ModbusInstance) HandleCoils

func (eh *ModbusInstance) HandleCoils(req *modbus.CoilsRequest) (res []bool, err error)

Coil handler method. This method gets called whenever a valid modbus request asking for a coil operation is received by the server. It exposes 100 read/writable coils at addresses 0-99, except address 80 which is read-only. (read them with ./modbus-cli --target tcp://localhost:5502 rc:0+99, write to register n with ./modbus-cli --target tcp://localhost:5502 wr:n:<true|false>)

func (*ModbusInstance) HandleDiscreteInputs

func (eh *ModbusInstance) HandleDiscreteInputs(req *modbus.DiscreteInputsRequest) (res []bool, err error)

Discrete input handler method. Note that we're returning ErrIllegalFunction unconditionally. This will cause the client to receive "illegal function", which is the modbus way of reporting that this server does not support/implement the discrete input type.

func (*ModbusInstance) HandleHoldingRegisters

func (eh *ModbusInstance) HandleHoldingRegisters(req *modbus.HoldingRegistersRequest) (res []uint16, err error)

Holding register handler method. This method gets called whenever a valid modbus request asking for a holding register operation (either read or write) received by the server.

func (*ModbusInstance) HandleInputRegisters

func (eh *ModbusInstance) HandleInputRegisters(req *modbus.InputRegistersRequest) (res []uint16, err error)

Input register handler method. This method gets called whenever a valid modbus request asking for an input register operation is received by the server. Note that input registers are always read-only as per the modbus spec.

func (*ModbusInstance) ID

func (m *ModbusInstance) ID() string

func (*ModbusInstance) Init

func (m *ModbusInstance) Init(parent context.Context, env *pluginapi.HostEnv) error

Init:用 parent ctx + HostEnv 初始化实例并启动轮询协程 Init: initialize instance with parent ctx + HostEnv and start poller goroutine.

func (*ModbusInstance) Type

func (m *ModbusInstance) Type() string

func (*ModbusInstance) UpdateConfig

func (m *ModbusInstance) UpdateConfig(raw pluginapi.InstanceConfig) error

UpdateConfig:支持运行时配置更新(包括 URL、端口等),必要时重启 Modbus 客户端 UpdateConfig: support runtime config updates (including URL/port), restarting client if needed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL