mbserver

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ValueTypeBool = iota
	ValueTypeUint8
	ValueTypeInt8
	ValueTypeUint16
	ValueTypeInt16
	ValueTypeUint32
	ValueTypeInt32
	ValueTypeUint64
	ValueTypeInt64
	ValueTypeUint
	ValueTypeInt
	ValueTypeFloat32
	ValueTypeFloat64
)
View Source
const (
	AccessRead = iota
	AccessWrite
	AccessReadWrite
)

Variables

This section is empty.

Functions

func AccessText

func AccessText(access int) string

func ValueTypeText

func ValueTypeText(valueType int) string

Types

type Device

type Device struct {
	ModelId string `json:"modelId"`
	Id      string `json:"id"`
}

type DeviceUnit

type DeviceUnit struct {
	Id         string         `json:"id"`
	ModelId    string         `json:"modelId"`
	ModelName  string         `json:"modelName"`
	Properties []PropertyUnit `json:"properties"`
}

type HandlerFunc

type HandlerFunc func(id string, propertyValues []PropertyValue)

type Model

type Model struct {
	Id         string     `json:"id"`
	Name       string     `json:"name"` // 可选
	Properties []Property `json:"properties"`
}

type Property

type Property struct {
	Name        string `json:"name"`
	Description string `json:"description"` // 可选
	ValueType   int    `json:"valueType"`
	Access      int    `json:"access"`
}

type PropertyUnit

type PropertyUnit struct {
	Name         string `json:"name"`
	Description  string `json:"description"`
	Type         string `json:"type"`
	Access       string `json:"access"`
	StartAddress uint16 `json:"address"`
	Quantity     uint16 `json:"quantity"`
	HumanAddress string `json:"humanAddress"`
}

type PropertyValue

type PropertyValue struct {
	Name  string
	Value interface{}
}

type Server

type Server interface {
	Start() error                                                      // 启动服务监听
	Stop() error                                                       // 停止
	SetProperty(id string, property string, value interface{}) error   // 设置设备属性
	SetOnWriteHandler(func(id string, propertyValues []PropertyValue)) // 寄存器写入回调函数
}

func NewServer

func NewServer(conf *ServerConfig) Server

type ServerConfig

type ServerConfig struct {
	URL           string `json:"url"` // 仅适用于 Modbus TCP, 示例:127.0.0.1:502【暂不支持 Modbus TCP 协议】
	serial.Config        // 串口配置

	Models  []Model  `json:"models"`  // 模型列表(注意属性顺序)
	Devices []Device `json:"devices"` // 设备列表(注意设备顺序)
}

type Storage

type Storage struct {
	EnableSort bool // 是否启用属性排序(r、rw、w)
	// contains filtered or unexported fields
}

func NewStorage

func NewStorage() *Storage

func (*Storage) ConvUint16Slice

func (c *Storage) ConvUint16Slice(uint16Slice []uint16, valueType int) (interface{}, error)

func (*Storage) DeviceMap

func (s *Storage) DeviceMap() interface{}

func (*Storage) GetProperty

func (s *Storage) GetProperty(id string, property string) (interface{}, error)

func (*Storage) Initialize

func (s *Storage) Initialize(models []Model, devices []Device) error

func (*Storage) Read

func (s *Storage) Read(address uint16, quantity uint16) ([]uint16, error)

func (*Storage) RegisterInfo

func (s *Storage) RegisterInfo(address uint16) (id string, property string, err error)

func (*Storage) SetProperty

func (s *Storage) SetProperty(id string, property string, v interface{}) error

func (*Storage) Uint16Slice

func (c *Storage) Uint16Slice(v interface{}, valueType int) ([]uint16, error)

func (*Storage) Write

func (s *Storage) Write(address uint16, values []uint16) error

Directories

Path Synopsis
crc

Jump to

Keyboard shortcuts

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