mb

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultRandValue 单位ms
	// 默认随机值上限,它影响当超时请求入ready队列时,
	// 当队列满,会启动一个随机时间rand.Intn(v)*1ms 延迟入队
	// 用于需要重试的延迟重试时间
	DefaultRandValue = 50
	// DefaultReadyQueuesLength 默认就绪列表长度
	DefaultReadyQueuesLength = 128
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	modbus.Client
	// contains filtered or unexported fields
}

Client 客户端

func NewClient

func NewClient(p modbus.ClientProvider, opts ...Option) *Client

NewClient 创建新的client

func (*Client) AddGatherJob

func (sf *Client) AddGatherJob(r Request) error

AddGatherJob 增加采集任务

func (*Client) Close

func (sf *Client) Close() error

Close 关闭

func (*Client) Start

func (sf *Client) Start() error

Start 启动

type Handler

type Handler interface {
	ProcReadCoils(slaveID byte, address, quality uint16, valBuf []byte)
	ProcReadDiscretes(slaveID byte, address, quality uint16, valBuf []byte)
	ProcReadHoldingRegisters(slaveID byte, address, quality uint16, valBuf []byte)
	ProcReadInputRegisters(slaveID byte, address, quality uint16, valBuf []byte)
	ProcResult(err error, result *Result)
}

Handler 处理函数

type NopProc

type NopProc struct{}

func (NopProc) ProcReadCoils

func (NopProc) ProcReadCoils(byte, uint16, uint16, []byte)

func (NopProc) ProcReadDiscretes

func (NopProc) ProcReadDiscretes(byte, uint16, uint16, []byte)

func (NopProc) ProcReadHoldingRegisters

func (NopProc) ProcReadHoldingRegisters(byte, uint16, uint16, []byte)

func (NopProc) ProcReadInputRegisters

func (NopProc) ProcReadInputRegisters(byte, uint16, uint16, []byte)

func (NopProc) ProcResult

func (NopProc) ProcResult(_ error, result *Result)

type Option

type Option func(client *Client)

Option 可选项

func WitchHandler

func WitchHandler(h Handler) Option

WitchHandler 配置handler

func WitchPanicHandle

func WitchPanicHandle(f func(interface{})) Option

WitchPanicHandle 发生panic回调,主要用于调试

func WitchRetryRandValue

func WitchRetryRandValue(v int) Option

WitchRetryRandValue 单位ms 默认随机值上限,它影响当超时请求入ready队列时, 当队列满,会启动一个随机时间rand.Intn(v)*1ms 延迟入队 用于需要重试的延迟重试时间

func WithReadyQueueSize

func WithReadyQueueSize(size int) Option

WithReadyQueueSize 就绪队列长度

type Request

type Request struct {
	SlaveID  byte          // 从机地址
	FuncCode byte          // 功能码
	Address  uint16        // 请求数据用实际地址
	Quantity uint16        // 请求数量
	ScanRate time.Duration // 扫描速率scan rate
	Retry    byte          // 失败重试次数
	// contains filtered or unexported fields
}

Request 请求

type Result

type Result struct {
	SlaveID  byte          // 从机地址
	FuncCode byte          // 功能码
	Address  uint16        // 请求数据用实际地址
	Quantity uint16        // 请求数量
	ScanRate time.Duration // 扫描速率scan rate
	TxCnt    uint64        // 发送计数
	ErrCnt   uint64        // 发送错误计数
}

Result 某个请求的结果与参数

Jump to

Keyboard shortcuts

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