modbuspv

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 21, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PvUnknown represents unknown type
	PvUnknown = iota
	// PvU16 represents uint16
	PvU16
	// PvU32 represents uint32
	PvU32
	// PvU64 represents uint64
	PvU64
	// PvI16 represents int16
	PvI16
	// PvI32 represents int32
	PvI32
	// PvI64 represents int64
	PvI64
	// PvF32 represents float32
	PvF32
	// PvF64 represents float64
	PvF64
	// PvBool represents bool
	PvBool
)

Variables

View Source
var (
	// DecoderMap assign pvDecoder to each PvType
	DecoderMap = map[PvType]pvDecoder{
		PvUnknown: pvUnknownDecoder,
		PvU16:     pvU16Decoder,
		PvU32:     pvU32Decoder,
		PvU64:     pvU64Decoder,
		PvI32:     pvI32Decoder,
		PvI64:     pvI64Decoder,
		PvF32:     pvF32Decoder,
		PvF64:     pvF64Decoder,
		PvBool:    pvBoolDecoder,
	}
)
View Source
var (
	// EncoderMap assign pvEncoder to each PvType
	EncoderMap = map[PvType]pvEncoder{
		PvUnknown: pvUnknownEncoder,
		PvU16:     pvU16Encoder,
		PvU32:     pvU32Encoder,
		PvU64:     pvU64Encoder,
		PvI32:     pvI32Encoder,
		PvI64:     pvI64Encoder,
		PvF32:     pvF32Encoder,
		PvF64:     pvF64Encoder,
		PvBool:    pvBoolEncoder,
	}
)
View Source
var (
	// ErrTimeout means timeout
	ErrTimeout = errors.New("timeout")
)
View Source
var (
	// ErrUnknownPvType means unknown pv type
	ErrUnknownPvType = errors.New("Unknown pv type")
)
View Source
var (
	// RegisterLengthMap gives quantity in modbus registers functions for each PvType
	RegisterLengthMap = map[PvType]uint16{
		PvUnknown: 0,
		PvU16:     1,
		PvU32:     2,
		PvU64:     4,
		PvI16:     1,
		PvI32:     2,
		PvI64:     4,
		PvF32:     2,
		PvF64:     4,
		PvBool:    1,
	}
)

Functions

func PvI16Encoder

func PvI16Encoder(data Payload) ([]byte, error)

PvI16Encoder encodes int16 payload to byte array

Types

type ModbusPV

type ModbusPV interface {
	Name() string
	Writable() bool
	PvType() PvType
	Get(context.Context) (Payload, error)
	Put(context.Context, Payload) error
}

ModbusPV is an interface for pv getter and putter

func NewModbusPV

func NewModbusPV(name string, handler modbus.ClientHandler, pvType PvType, offset uint16, writable bool) ModbusPV

NewModbusPV returns a ModbusPV

type Payload

type Payload = interface{}

Payload is the payload in pv

func PvI16Decoder

func PvI16Decoder(data []byte) (Payload, error)

PvI16Decoder decodes byte array to int16 payload

type PvType

type PvType uint16

PvType is enum for pv value type

Jump to

Keyboard shortcuts

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