plcconnector

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2021 License: MIT Imports: 26 Imported by: 1

Documentation

Overview

Package plcconnector implements communication with PLC.

Index

Constants

View Source
const (
	// Common
	GetAttrAll  = 0x01
	SetAttrAll  = 0x02
	GetAttrList = 0x03
	SetAttrList = 0x04
	Reset       = 0x05
	MultiServ   = 0x0A
	GetAttr     = 0x0E
	SetAttr     = 0x10
	NextInst    = 0x11
	GetMember   = 0x18

	// Class Specific
	InititateUpload = 0x4B
	ReadTag         = 0x4C
	ReadTemplate    = 0x4C
	WriteTag        = 0x4D
	ReadModifyWrite = 0x4E
	ForwardClose    = 0x4E
	UploadTransfer  = 0x4F
	UnconnectedSend = 0x52
	ReadTagFrag     = 0x52
	WriteTagFrag    = 0x53
	ForwardOpen     = 0x54
	GetInstAttrList = 0x55
	LargeForwOpen   = 0x5B
)

Service

View Source
const (
	IdentityClass = 0x01
	MessageRouter = 0x02
	ConnManager   = 0x06
	FileClass     = 0x37

	ProgramClass  = 0x64
	SymbolClass   = 0x6B
	TemplateClass = 0x6C
	ClockClass    = 0x8B

	PortClass     = 0xF4
	TCPClass      = 0xF5
	EthernetClass = 0xF6
)

Classes

View Source
const (
	TypeBOOL        = 0xC1 // 1
	TypeSINT        = 0xC2 // 1
	TypeINT         = 0xC3 // 2
	TypeDINT        = 0xC4 // 4
	TypeLINT        = 0xC5 // 8
	TypeUSINT       = 0xC6 // 1
	TypeUINT        = 0xC7 // 2
	TypeUDINT       = 0xC8 // 4
	TypeULINT       = 0xC9 // 8
	TypeREAL        = 0xCA // 4
	TypeLREAL       = 0xCB // 8
	TypeSTIME       = 0xCC // synchronous time =DINT
	TypeDATE        = 0xCD // day from 01-01-1972 =UINT
	TypeTIMEOFDAY   = 0xCE // =UDINT
	TypeDATETIME    = 0xCF // =UDINT+UINT
	TypeSTRING      = 0xD0 // =UINT+x*USINT
	TypeBYTE        = 0xD1 // =x*USINT
	TypeWORD        = 0xD2 // =x*UINT
	TypeDWORD       = 0xD3 // =x*UDINT
	TypeLWORD       = 0xD4 // =x*ULINT
	TypeSTRING2     = 0xD5 // =UINT+x*UINT
	TypeFTIME       = 0xD6 // duration high resolution microseconds =DINT
	TypeLTIME       = 0xD7 // duration long microseconds =LINT
	TypeITIME       = 0xD8 // duration short =INT
	TypeSTRINGN     = 0xD9 // =UINT+UINT(n)+x*n
	TypeSHORTSTRING = 0xDA // =USINT+x*USINT
	TypeTIME        = 0xDB // duration miliseconds =DINT
	TypeEPATH       = 0xDC
	TypeENGUNIT     = 0xDD // engineering units
	TypeSTRINGI     = 0xDE

	TypeArray1D = 0x2000
	TypeArray2D = 0x4000
	TypeArray3D = 0x6000
	TypeStruct  = 0x8000
	TypeType    = 0x0FFF

	TypeStructHead = 0x02A00000
)

Data types

View Source
const (
	Success          = 0x00
	PathSegmentError = 0x04
	PathUnknown      = 0x05
	PartialTransfer  = 0x06
	ServNotSup       = 0x08
	AttrListError    = 0x0A
	AttrNotSettable  = 0x0E
	PrivilegeViol    = 0x0F
	NotEnoughData    = 0x13
	AttrNotSup       = 0x14
	TooMuchData      = 0x15
	ObjectNotExist   = 0x16
	InvalidPar       = 0x20
)

Status codes

Variables

This section is empty.

Functions

This section is empty.

Types

type Class

type Class struct {
	Name string
	// contains filtered or unexported fields
}

Class .

func NewClass

func NewClass(n string, attrs int) *Class

NewClass .

func (*Class) SetInstance

func (c *Class) SetInstance(no int, in *Instance)

SetInstance .

type Client

type Client struct {
	Timeout uint16
	// contains filtered or unexported fields
}

Client .

func Connect

func Connect(host string) (*Client, error)

Connect .

func (*Client) Close

func (c *Client) Close() error

Close .

func (*Client) ReadTag

func (c *Client) ReadTag(tag string, count int) (*Tag, error)

ReadTag .

type Identity

type Identity struct {
	Addr         string
	VendorID     int    // UINT
	DeviceType   int    // UINT
	ProductCode  int    // UINT
	Revision     string // UINT
	Status       int    // UINT
	SerialNumber uint   // UDINT
	Name         string // SHORTSTRING
	State        int    // USINT
}

Identity .

func Discover

func Discover() ([]Identity, error)

Discover .

type Instance

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

Instance .

func NewInstance

func NewInstance(noattr int) *Instance

NewInstance .

func (*Instance) SetAttr

func (in *Instance) SetAttr(no int, a *Tag)

SetAttr .

func (*Instance) SetAttrUINT

func (in *Instance) SetAttrUINT(no int, v uint16)

SetAttrUINT .

type JS

type JS struct {
	AC        [5]int                 `json:"ac"`
	Symbols   map[string]jsSymbols   `json:"symbols"`
	Templates map[string]jsTemplates `json:"templates"`
}

JS .

type PLC

type PLC struct {
	Class       map[int]*Class
	DumpNetwork bool // enables dumping network packets
	Name        string
	Verbose     bool // enables debugging output
	Timeout     time.Duration
	// contains filtered or unexported fields
}

PLC .

func Init

func Init(eds string) (*PLC, error)

Init initialize library. Must be called first.

func (*PLC) AddTag

func (p *PLC) AddTag(t Tag)

AddTag adds tag.

func (*PLC) Callback

func (p *PLC) Callback(function func(service int, status int, tag *Tag))

Callback registers function called at receiving communication with PLC. tag may be nil in event of error or reset.

func (*PLC) Close

func (p *PLC) Close()

Close shutdowns server

func (*PLC) CloseHTTP

func (p *PLC) CloseHTTP() error

CloseHTTP shutdowns the HTTP server

func (*PLC) CreateTag

func (p *PLC) CreateTag(typ string, name string)

CreateTag .

func (*PLC) GetClassInstance

func (p *PLC) GetClassInstance(class int, instance int) *Instance

GetClassInstance .

func (*PLC) GetClassInstanceAttr added in v0.1.4

func (p *PLC) GetClassInstanceAttr(class int, instance int, attr int) (*Tag, bool, bool)

GetClassInstanceAttr .

func (*PLC) GetClassInstancesList

func (p *PLC) GetClassInstancesList(class int, instanceFrom int, maxInstances int) ([]int, []*Instance)

GetClassInstancesList .

func (*PLC) ImportJSON

func (p *PLC) ImportJSON(file string) error

ImportJSON .

func (*PLC) ImportMemoryJSON

func (p *PLC) ImportMemoryJSON(file string) error

ImportMemoryJSON .

func (*PLC) NewTag

func (p *PLC) NewTag(i interface{}, n string)

NewTag .

func (*PLC) NewUDT

func (p *PLC) NewUDT(udt string) error

NewUDT .

func (*PLC) Serve

func (p *PLC) Serve(host string) error

Serve listens on the TCP network address host.

func (*PLC) ServeHTTP

func (p *PLC) ServeHTTP(host string) *http.Server

ServeHTTP listens on the TCP network address host.

func (*PLC) UpdateTag

func (p *PLC) UpdateTag(name string, offset int, data []uint8) bool

UpdateTag sets data to the tag

type Tag

type Tag struct {
	Name  string
	Type  int
	Index int
	Dim   [3]int
	// contains filtered or unexported fields
}

Tag .

func TagArrayBool

func TagArrayBool(v []bool, c int, n string) *Tag

TagArrayBool .

func TagArrayDINT

func TagArrayDINT(v []int32, c int, n string) *Tag

TagArrayDINT .

func TagArrayINT

func TagArrayINT(v []int16, c int, n string) *Tag

TagArrayINT .

func TagArrayLINT

func TagArrayLINT(v []int64, c int, n string) *Tag

TagArrayLINT .

func TagArrayLREAL

func TagArrayLREAL(v []float64, c int, n string) *Tag

TagArrayLREAL .

func TagArrayREAL

func TagArrayREAL(v []float32, c int, n string) *Tag

TagArrayREAL .

func TagArraySINT

func TagArraySINT(v []int8, c int, n string) *Tag

TagArraySINT .

func TagArrayUDINT

func TagArrayUDINT(v []uint32, c int, n string) *Tag

TagArrayUDINT .

func TagArrayUINT

func TagArrayUINT(v []uint16, c int, n string) *Tag

TagArrayUINT .

func TagArrayULINT

func TagArrayULINT(v []uint64, c int, n string) *Tag

TagArrayULINT .

func TagArrayUSINT

func TagArrayUSINT(v []uint8, c int, n string) *Tag

TagArrayUSINT .

func TagBOOL

func TagBOOL(v bool, n string) *Tag

TagBOOL .

func TagDINT

func TagDINT(v int32, n string) *Tag

TagDINT .

func TagINT

func TagINT(v int16, n string) *Tag

TagINT .

func TagLINT

func TagLINT(v int64, n string) *Tag

TagLINT .

func TagLREAL

func TagLREAL(v float64, n string) *Tag

TagLREAL .

func TagREAL

func TagREAL(v float32, n string) *Tag

TagREAL .

func TagSINT

func TagSINT(v int8, n string) *Tag

TagSINT .

func TagShortString

func TagShortString(v string, n string) *Tag

TagShortString .

func TagString

func TagString(v string, n string) *Tag

TagString .

func TagStringI

func TagStringI(v string, n string) *Tag

TagStringI .

func TagUDINT

func TagUDINT(v uint32, n string) *Tag

TagUDINT .

func TagUINT

func TagUINT(v uint16, n string) *Tag

TagUINT .

func TagULINT

func TagULINT(v uint64, n string) *Tag

TagULINT .

func TagUSINT

func TagUSINT(v uint8, n string) *Tag

TagUSINT .

func (Tag) BasicType added in v0.1.2

func (t Tag) BasicType() int

func (*Tag) DataBOOL

func (t *Tag) DataBOOL() []bool

DataBOOL returns array of BOOL.

func (*Tag) DataBytes

func (t *Tag) DataBytes() []byte

DataBytes returns array of bytes.

func (*Tag) DataDINT

func (t *Tag) DataDINT() []int32

DataDINT returns array of int32.

func (*Tag) DataDWORD

func (t *Tag) DataDWORD() []int32

DataDWORD returns array of int32.

func (*Tag) DataINT

func (t *Tag) DataINT() []int16

DataINT returns array of int16.

func (*Tag) DataLINT

func (t *Tag) DataLINT() []int64

DataLINT returns array of int64.

func (*Tag) DataREAL

func (t *Tag) DataREAL() []float32

DataREAL returns array of float32.

func (*Tag) DataSINT

func (t *Tag) DataSINT() []int8

DataSINT returns array of int8.

func (*Tag) DataString

func (t *Tag) DataString() string

DataString returns string.

func (Tag) DimString

func (t Tag) DimString() string

DimString .

func (Tag) Dims

func (t Tag) Dims() int

Dims .

func (Tag) ElemLen

func (t Tag) ElemLen() int

ElemLen .

func (Tag) Len

func (t Tag) Len() int

Len .

func (Tag) NString

func (t Tag) NString(n int) string

NString .

func (Tag) NumType added in v0.1.3

func (t Tag) NumType() int

func (Tag) PathString added in v0.1.2

func (t Tag) PathString(n int) string

PathString .

func (*Tag) SetDataBytes

func (t *Tag) SetDataBytes(dt []byte) uint8

SetDataBytes .

func (Tag) TypeString

func (t Tag) TypeString() string

TypeString .

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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