modbus

package
v0.0.0-...-3a8cc73 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CRC16

func CRC16(bs []byte) uint16

CRC16 Calculate Cyclical Redundancy Checking.

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

func (*Adapter) Get

func (adapter *Adapter) Get(device *types.Device, name string) (any, error)

func (*Adapter) Set

func (adapter *Adapter) Set(device *types.Device, name string, value any) error

func (*Adapter) Sync

func (adapter *Adapter) Sync(device *types.Device) (map[string]any, error)

type Calculator

type Calculator struct {
	Name       string `json:"name"`       //赋值
	Expression string `json:"expression"` //表达式
}

type Filter

type Filter struct {
	Name       string `json:"name"`       //字段
	Expression string `json:"expression"` //表达式

}

type Mapper

type Mapper struct {
	Code    uint8    `json:"code,omitempty"`
	Address uint16   `json:"address,omitempty"`
	Size    uint16   `json:"size"`   //长度
	Points  []*Point `json:"points"` //数据点
}

func (*Mapper) Encode

func (m *Mapper) Encode(name string, data any) (*Point, []byte, error)

func (*Mapper) Parse

func (m *Mapper) Parse(buf []byte, ret map[string]any)

type Modbus

type Modbus interface {
	Read(station, code uint8, addr, size uint16) ([]byte, error)
	Write(station, code uint8, addr uint16, buf []byte) error
}

type ParallelTCP

type ParallelTCP struct {
	// contains filtered or unexported fields
}

ParallelTCP Modbus-TCP协议

func NewParallelTCP

func NewParallelTCP(tunnel connect.Conn, opts string) *ParallelTCP

func (*ParallelTCP) OnData

func (m *ParallelTCP) OnData(buf []byte)

func (*ParallelTCP) Read

func (m *ParallelTCP) Read(slave uint8, code uint8, addr uint16, size uint16) ([]byte, error)

func (*ParallelTCP) Write

func (m *ParallelTCP) Write(slave uint8, code uint8, addr uint16, buf []byte) error

type Point

type Point struct {
	Name      string  `json:"name"`           //名称
	Type      string  `json:"type"`           //类型
	Offset    int     `json:"offset"`         //偏移
	Bits      int     `json:"bits,omitempty"` //位,1 2 3...
	BigEndian bool    `json:"be,omitempty"`   //大端模式
	Rate      float64 `json:"rate,omitempty"` //倍率
}

type Product

type Product struct {
	Id   string `json:"id" xorm:"pk"`
	Name string `json:"name,omitempty"` //名称
	Desc string `json:"desc,omitempty"` //说明

	Mappers     []*Mapper     `json:"mappers" xorm:"json"`
	Filters     []*Filter     `json:"filters" xorm:"json"`
	Calculators []*Calculator `json:"calculators" xorm:"json"`
	Created     time.Time     `json:"created" xorm:"created"` //创建时间
}

func GetProduct

func GetProduct(id string) (*Product, error)

type RTU

type RTU struct {
	// contains filtered or unexported fields
}

RTU Modbus-RTU协议

func NewRTU

func NewRTU(tunnel connect.Conn, opts types.Options) *RTU

func (*RTU) Read

func (m *RTU) Read(station uint8, code uint8, addr uint16, size uint16) ([]byte, error)

func (*RTU) Write

func (m *RTU) Write(station uint8, code uint8, addr uint16, buf []byte) error

type TCP

type TCP struct {
	// contains filtered or unexported fields
}

TCP Modbus-TCP协议

func NewTCP

func NewTCP(tunnel connect.Conn, opts types.Options) *TCP

func (*TCP) Read

func (m *TCP) Read(station uint8, code uint8, addr uint16, size uint16) ([]byte, error)

func (*TCP) Write

func (m *TCP) Write(station uint8, code uint8, addr uint16, buf []byte) error

Jump to

Keyboard shortcuts

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