modbus

package
v4.1.5 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 14 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(id, name string) (any, error)

func (*Adapter) Mount added in v4.0.19

func (adapter *Adapter) Mount(device string) error

func (*Adapter) Set

func (adapter *Adapter) Set(id, name string, value any) error

func (*Adapter) Sync

func (adapter *Adapter) Sync(id string) (map[string]any, error)

func (*Adapter) Tunnel added in v4.0.19

func (adapter *Adapter) Tunnel() connect.Tunnel

func (*Adapter) Unmount added in v4.0.19

func (adapter *Adapter) Unmount(device string) error

type Bit

type Bit struct {
	Name string `json:"name"` //名称
	Bit  int    `json:"bit"`  //偏移
}

type Calculator

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

type Device

type Device struct {
	Id string `json:"id" xorm:"pk"`

	//modbus站号
	//ModbusStation uint8 `json:"modbus_station,omitempty"`
	Station Station `json:"station,omitempty" xorm:"json"`
	// contains filtered or unexported fields
}

type Filter

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

}

type Mapper

type Mapper struct {
	Coils            []*PointBit  `json:"coils,omitempty"`
	DiscreteInputs   []*PointBit  `json:"discrete_inputs,omitempty"`
	HoldingRegisters []*PointWord `json:"holding_registers,omitempty"`
	InputRegisters   []*PointWord `json:"input_registers,omitempty"`
}

func (*Mapper) Lookup added in v4.1.5

func (p *Mapper) Lookup(name string) (pt Point, code uint8, address uint16)

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 added in v4.1.5

type Point interface {
	Encode(data any) ([]byte, error)
	Parse(address uint16, buf []byte) (any, error)
}

type PointBit added in v4.1.5

type PointBit struct {
	Name    string `json:"name"`    //名称
	Address uint16 `json:"address"` //偏移
}

func (*PointBit) Encode added in v4.1.5

func (p *PointBit) Encode(data any) ([]byte, error)

func (*PointBit) Parse added in v4.1.5

func (p *PointBit) Parse(address uint16, buf []byte) (any, error)

type PointWord added in v4.1.5

type PointWord struct {
	Name      string  `json:"name"`              //名称
	Type      string  `json:"type"`              //类型
	Address   uint16  `json:"address"`           //偏移
	BigEndian bool    `json:"be,omitempty"`      //大端模式
	Rate      float64 `json:"rate,omitempty"`    //倍率
	Correct   float64 `json:"correct,omitempty"` //纠正
	Bits      []*Bit  `json:"bits,omitempty"`    //位,1 2 3...
}

func (*PointWord) Encode added in v4.1.5

func (p *PointWord) Encode(data any) ([]byte, error)

func (*PointWord) Parse added in v4.1.5

func (p *PointWord) Parse(address uint16, buf []byte) (any, error)

type Poller

type Poller struct {
	Code    uint8  `json:"code"`
	Address uint16 `json:"address"`
	Length  uint16 `json:"length"` //长度
}

func (*Poller) Parse

func (p *Poller) Parse(mapper *Mapper, buf []byte, values map[string]any) error

type RTU

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

RTU Modbus-RTU协议

func NewRTU

func NewRTU(tunnel connect.Tunnel, 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 Station added in v4.0.19

type Station struct {
	Slave uint8 `json:"slave"`
}

type TCP

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

TCP Modbus-TCP协议

func NewTCP

func NewTCP(tunnel connect.Tunnel, 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