relay

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

README

信科 relay-xk-sdk

Documentation

Index

Constants

View Source
const (
	DefaultBranchesLength = 0x8
	MaxBranchesLength     = 32
	DataLength            = 0x8
	RequestHeader         = 0x55 //发送帧数据头
	ResponseHeader        = 0x22 //接受帧数据头

	//功能码
	RequestReadStatus = 0x10 //读取状态

	RequestOffOne  = 0x11 //断开某路
	RequestOnOne   = 0x12 //吸合某路
	RequestFlipOne = 0x20 //翻转某路

	RequestRunCMD = 0x13 //命令执行

	RequestOffGroup  = 0x14 //组断开
	RequestOnGroup   = 0x15 //组吸合
	RequestFlipGroup = 0x16 //组翻转

	RequestOnPoint  = 0x21 //点动闭合
	RequestOffPoint = 0x22 //点动断开

	RequestFlipOneNil = 0x30 //翻转某路 下位机不返回数据,指0令可以连续发送
	RequestOffOneNil  = 0x31 //断开某路
	RequestOnOneNil   = 0x32 //吸合某路
	RequestRunCMDNil  = 0x33 //命令执行

	RequestOffGroupNil  = 0x34 //组断开
	RequestOnGroupNil   = 0x35 //组吸合
	RequestFlipGroupNil = 0x36 //组翻转

	RequestOnPointNil  = 0x37 //点动闭合
	RequestOffPointNil = 0x38 //点动断开

	RequestReadAddress  = 0x40 //读地址
	RequestWriteAddress = 0x41 //写地址

	RequestReadVariable  = 0x70 //读变量
	RequestWriteVariable = 0x71 //写变量

	ResponseReadStatus         = 0x10 //读取状态
	ResponseCloseOne           = 0x11 //关闭某一路
	ResponseOpenOne            = 0x12 //打开某一路
	ResponseRunCMD             = 0x13 //命令执行
	ResponseCloseGroup         = 0x14 //组断开
	ResponseOpenGroup          = 0x15 //组吸合
	ResponseFlipGroup          = 0x16 //组翻转
	ResponseModelAddress       = 0x40 //返回模块地址
	ResponseReadInnerVariable  = 0x70 //读内部变量
	ResponseWriteInnerVariable = 0x71 //写内部变量
)

Variables

View Source
var (
	ErrPackagerNil    = errors.New("packager 未实例化")
	ErrBranchesLength = errors.New("继电器路数超出范围")
	ErrReturnResult   = errors.New("串口返回数据格式异常")
)

Functions

func Sign

func Sign(data []byte) byte

数据校验位赋值

Types

type Client

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

Client is the interface that groups the Packager and Transporter methods.

func NewClient

func NewClient(handler *ClientHandler, length byte) *Client

NewClient creates a new modbus client with given backend handler.

func NewDefaultClient

func NewDefaultClient(handler *ClientHandler) *Client

func (*Client) FlipGroup

func (c *Client) FlipGroup(i ...byte) error

组翻转

func (*Client) FlipGroupNil

func (c *Client) FlipGroupNil(i ...byte) error

翻转组

func (*Client) FlipOne

func (c *Client) FlipOne(i byte) error

翻转某路

func (*Client) FlipOneNil

func (c *Client) FlipOneNil(i byte) error

翻转某路

func (*Client) OffAll

func (c *Client) OffAll() error

断开所有

func (*Client) OffGroup

func (c *Client) OffGroup(i ...byte) error

断开组

func (*Client) OffGroupNil

func (c *Client) OffGroupNil(i ...byte) error

断开组

func (*Client) OffOne

func (c *Client) OffOne(i byte) error

断开某路

func (*Client) OffOneNil

func (c *Client) OffOneNil(i byte) error

断开某路

func (*Client) OffPoint

func (c *Client) OffPoint(i byte, t int) error

点动断开某路

func (*Client) OffPointNil

func (c *Client) OffPointNil(i byte, t int) error

点动断开

func (*Client) OnAll

func (c *Client) OnAll() error

吸合所有

func (*Client) OnGroup

func (c *Client) OnGroup(i ...byte) error

闭合组

func (*Client) OnGroupNil

func (c *Client) OnGroupNil(i ...byte) error

吸合组

func (*Client) OnOne

func (c *Client) OnOne(i byte) error

闭合某路

func (*Client) OnOneNil

func (c *Client) OnOneNil(i byte) error

吸合某路

func (*Client) OnPoint

func (c *Client) OnPoint(i byte, t int) error

点动闭合某路

func (*Client) OnPointNil

func (c *Client) OnPointNil(i byte, t int) error

点动闭合

func (*Client) Status

func (c *Client) Status() ([]byte, error)

继电器状态

func (*Client) StatusOne

func (c *Client) StatusOne(i byte) (byte, error)

某路继电器状态

type ClientHandler

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

ClientHandler implements Packager and Transporter interface.

func NewDefaultHandler

func NewDefaultHandler(address string, slave byte) *ClientHandler

NewDefaultHandler allocates and initializes a ClientHandler.

func NewHandler

func NewHandler(address string) *ClientHandler

NewHandler allocates and initializes a RELAYClientHandler.

func (*ClientHandler) Decode

func (mb *ClientHandler) Decode(adu []byte) (pdu *ProtocolDataUnit, err error)

Decode extracts PDU from RELAY frame and verify CRC.

func (*ClientHandler) Encode

func (mb *ClientHandler) Encode(pdu *ProtocolDataUnit) (adu []byte, err error)

Encode encodes PDU in a RELAY frame:

Data Header     : 1 byte
Slave Address   : 1 byte
Function        : 1 byte
Data            : 4 bytes
CRC             : 1 byte

func (*ClientHandler) Send

func (mb *ClientHandler) Send(aduRequest []byte) (aduResponse []byte, err error)

func (*ClientHandler) Verify

func (mb *ClientHandler) Verify(aduRequest []byte, aduResponse []byte) (err error)

Verify verifies response length and slave id.

type Packager

type Packager interface {
	Encode(pdu *ProtocolDataUnit) (adu []byte, err error)
	Decode(adu []byte) (pdu *ProtocolDataUnit, err error)
	Verify(aduRequest []byte, aduResponse []byte) (err error)
}

Packager specifies the communication layer.

type ProtocolDataUnit

type ProtocolDataUnit struct {
	FunctionCode byte
	Data         []byte
}

ProtocolDataUnit (PDU) is independent of underlying communication layers.

type Transporter

type Transporter interface {
	Send(aduRequest []byte) (aduResponse []byte, err error)
}

Transporter specifies the transport layer.

Jump to

Keyboard shortcuts

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