gs7

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 22 Imported by: 0

README ΒΆ

gs7

Go Version CopyRight-shiyuecamus License

Implementation of Siemens S7 protocol in golang

Implementing underlying communication based on gnet.

🍯 Overview

gs7 is an high-performance and lightweight Siemens s7 protocol communication framework

gs7 all read and write operations support both synchronous and asynchronous

πŸ‡ Features

  • Read DB, I, Q, M, V, Timer, Counter
  • Synchronous and asynchronous read/write
  • Single and batch raw read/write
  • Large amounts of data read/write(exceeding the maximum limit of PLC: PduLength, the request will be automatically divided into multiple requests by the algorithm)
  • Address single read/write
  • Address batch read/write of multiple addresses with discontinuous addresses or addresses not in the same area
  • Convert the read raw bytes to the type in golang
  • Connection retry and automatic reconnection after connection lose
  • Read SZL(System Status List)

πŸ† Supported communication

  • TCP

πŸ“ Quick start

Installation is as easy as:

go get github.com/shiyuecamus/gs7

πŸ‰ Usage

func main() {
  const (
    host = "192.168.0.1"
    port = 102
    rack = 0
    slot = 1
  )
  logger := logging.GetDefaultLogger()

  c := gs7.NewClientBuilder().
    PlcType(common.S1500).
    Host(host).
    Port(port).
    Rack(rack).
    Slot(slot).
    Build()
  
  _, err := c.Connect().Wait()
  if err != nil {
    logger.Errorf("Failed to connect PLC, host: %s, port: %d, error: %s", host, port, err)
    return
  }
  
  // read
  res, err := c.ReadParsed("DB1.X0.0").Wait()
  if err != nil {
    logger.Errorf("Failed to read bit, error: %s", err)
    return
  }
  logger.Infof("Read bit success with value: %s", res)
  
  // write
  err = c.WriteRaw("DB1.X0.0", gs7.Bit(true).ToBytes()).Wait()
  if err != nil {
    logger.Errorf("Failed to read bit, error: %s", err)
    return
  }
  
  // check
  res, err = c.ReadParsed("DB1.X0.0").Wait()
  if err != nil {
    logger.Errorf("Failed to read bit, error: %s", err)
    return
  }
  logger.Infof("Read bit success with value: %s", res)
}

more examples

🍏 Knowledge

Data address, region, type, and length mapping table

abbreviation Area DB Number Byte index Bit index PLC Data type Go Data Type ByteLength PLC
DB1.X0.1/DB1.BIT0.1 DB 1 0 1 Bit bool 1/8 S1200
QX1.6/QBIT1.6 Q 0 1 6 Bit bool 1/8 S1200
QB1/QBYTE1 Q 0 1 0 Byte uint8 1 S1200
IX2.5/IBIT2.5 I 0 2 5 Bit bool 1/8 S1200
IW2/IWORD2 I 0 2 0 Word uint16 2 S1200
MX3.2/MBIT3.2 M 0 3 2 Bit bool 1/8 S1200
MI3/MINT3 M 0 3 0 Int int16 2 S1200
VX1.3/VBIT1.3 V 1 3 0 Bit bool 1/8 200Smart
VI4/VINT4 V 1 4 0 Int int16 2 200Smart
T0 T 0 0 0 Timer time.Duration 2 S1200
C2 C 0 2 0 Counter uint16 2 S1200
DB4.B4/DB4.BYTE4 DB 4 4 0 Byte uint8 1 S1200
DB4.C0/DB4.CHAR0 DB 4 0 0 Char int8 1 S1200
DB3.S2/DB3.STRING2 DB 3 2 0 String String N S1200
DB1.I8/DB1.INT8 DB 1 8 0 Int int16 2 S1200
DB2.W12/DB1.WORD12 DB 2 12 0 Word uint16 2 S1200
DB1.DI0/DB1.DINT0 DB 1 0 0 DInt int32 4 S1200
DB1.DW0/DB1.DWAORD0 DB 1 0 0 DWord uint32 4 S1200
DB3.R2/DB3.REAL2 DB 3 2 0 Real float32 4 S1200
DB1.T2/DB1.TIME2 DB 1 2 0 Time time.Duration 4 S1200
DB1.ST2/DB1.STIME2 DB 1 2 0 S5Time time.Duration 2 S1200
DB1.D2/DB1.DATE2 DB 1 2 0 Date time.Time 2 S1200
DB1.DT6/DB1.DATETIME6 DB 1 6 0 DateTime time.Time 8 S1200
DB1.DTL2/DB1.DATETIMELONG2 DB 1 2 0 DateTimeLong time.Time 12 S1200
DB1.TOD2/DB1.TIMEOFDAY2 DB 1 2 0 TimeOfDay time.Time 4 S1200

🌽 License

Distributed under the MIT License. See LICENSE for more information.
@2024 - 2099 shiyuecamus, All Rights Reserved.

❗❗❗ Please strictly abide by the MIT agreement and add the author's copyright license notice when using.

🍠 Dependencies

The dependencies used in this project are as follows:

Number Dependency Version License Date Copyright
1 gnet 2.3.5 Apache-2.0 2019-present Andy Pan
2 cast 1.6.0 MIT 2014 Steve Francia
3 zap 1.27.0 MIT 2016-2017 Uber Technologies

Sponsor

Buy me a cup of coffee.
WeChat (Please note the problem or purpose you encountered

wechat wechat

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (
	DefaultPduLength        = 480
	Localhost        string = "127.0.0.1"
	DefaultPort      int    = 102
)

Variables ΒΆ

This section is empty.

Functions ΒΆ

func DecodeBcd ΒΆ

func DecodeBcd(b byte) int

func EncodeBcd ΒΆ

func EncodeBcd(value int) byte

Types ΒΆ

type BaseReadToken ΒΆ

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

func (*BaseReadToken) Async ΒΆ

func (b *BaseReadToken) Async(ack func(v V, err error))

func (*BaseReadToken) Done ΒΆ

func (b *BaseReadToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*BaseReadToken) Wait ΒΆ

func (b *BaseReadToken) Wait() (V, error)

func (*BaseReadToken) WaitTimeout ΒΆ

func (b *BaseReadToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type BatchParsedReadToken ΒΆ

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

func (*BatchParsedReadToken) Async ΒΆ

func (b *BatchParsedReadToken) Async(ack func(v V, err error))

func (*BatchParsedReadToken) Done ΒΆ

func (b *BatchParsedReadToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*BatchParsedReadToken) Wait ΒΆ

func (b *BatchParsedReadToken) Wait() (V, error)

func (*BatchParsedReadToken) WaitTimeout ΒΆ

func (b *BatchParsedReadToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type BatchRawReadToken ΒΆ

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

func (*BatchRawReadToken) Async ΒΆ

func (b *BatchRawReadToken) Async(ack func(v V, err error))

func (*BatchRawReadToken) Done ΒΆ

func (b *BatchRawReadToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*BatchRawReadToken) Wait ΒΆ

func (b *BatchRawReadToken) Wait() (V, error)

func (*BatchRawReadToken) WaitTimeout ΒΆ

func (b *BatchRawReadToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type Bit ΒΆ

type Bit bool

func BitFromBytes ΒΆ

func BitFromBytes(bs []byte) (b Bit, err error)

func (Bit) String ΒΆ

func (b Bit) String() string

func (Bit) ToBytes ΒΆ

func (b Bit) ToBytes() []byte

type BlockInfoToken ΒΆ

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

func (*BlockInfoToken) Async ΒΆ

func (b *BlockInfoToken) Async(ack func(v V, err error))

func (*BlockInfoToken) Done ΒΆ

func (b *BlockInfoToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*BlockInfoToken) Wait ΒΆ

func (b *BlockInfoToken) Wait() (V, error)

func (*BlockInfoToken) WaitTimeout ΒΆ

func (b *BlockInfoToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type BlockListToken ΒΆ

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

func (*BlockListToken) Async ΒΆ

func (b *BlockListToken) Async(ack func(v V, err error))

func (*BlockListToken) Done ΒΆ

func (b *BlockListToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*BlockListToken) Wait ΒΆ

func (b *BlockListToken) Wait() (V, error)

func (*BlockListToken) WaitTimeout ΒΆ

func (b *BlockListToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type BlockListTypeToken ΒΆ

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

func (*BlockListTypeToken) Async ΒΆ

func (b *BlockListTypeToken) Async(ack func(v V, err error))

func (*BlockListTypeToken) Done ΒΆ

func (b *BlockListTypeToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*BlockListTypeToken) Wait ΒΆ

func (b *BlockListTypeToken) Wait() (V, error)

func (*BlockListTypeToken) WaitTimeout ΒΆ

func (b *BlockListTypeToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type Byte ΒΆ

type Byte uint8

func ByteFromBytes ΒΆ

func ByteFromBytes(bs []byte) (b Byte, err error)

func (Byte) String ΒΆ

func (b Byte) String() string

func (Byte) ToBytes ΒΆ

func (b Byte) ToBytes() []byte

type CatalogToken ΒΆ

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

func (*CatalogToken) Async ΒΆ

func (b *CatalogToken) Async(ack func(v V, err error))

func (*CatalogToken) Done ΒΆ

func (b *CatalogToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*CatalogToken) Wait ΒΆ

func (b *CatalogToken) Wait() (V, error)

func (*CatalogToken) WaitTimeout ΒΆ

func (b *CatalogToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type Char ΒΆ

type Char int8

func CharFromBytes ΒΆ

func CharFromBytes(bs []byte) (c Char, err error)

func (Char) String ΒΆ

func (c Char) String() string

func (Char) ToBytes ΒΆ

func (c Char) ToBytes() []byte

type Client ΒΆ

type Client interface {
	// Connect plc connect
	Connect() *ConnectToken
	// GetStatus get s7 client connection status
	GetStatus() Status
	// IsConnected return plc is connected
	IsConnected() bool
	// IsConnectionOpen return plc is connection open
	IsConnectionOpen() bool
	// Disconnect plc connection close and release
	Disconnect()
	// GetPduLength return plc max pdu length
	GetPduLength() int

	// ReadRaw read raw bytes from address
	ReadRaw(address string) *SingleRawReadToken
	// ReadBatchRaw read batch raw bytes from addresses
	ReadBatchRaw(addresses []string) *BatchRawReadToken
	// ReadParsed read auto parsed data from address
	ReadParsed(address string) *SingleParsedReadToken
	// ReadBatchParsed read batch auto parsed data from address
	ReadBatchParsed(addresses []string) *BatchParsedReadToken
	// WriteRaw write raw bytes to plc address
	WriteRaw(address string, data []byte) *SimpleToken
	// WriteRawBatch write batch raw bytes to plc addresses
	WriteRawBatch(addresses []string, data [][]byte) *SimpleToken
	// BaseRead block read
	// Support exceeds the maximum pdu length.
	// If the maximum pdu length is exceeded, it will be divided into multiple requests
	// And the aggregated results will be returned after the last request
	BaseRead(area common.AreaType, dbNumber int, byteAddr int, bitAddr int, size int) *BaseReadToken
	// BaseWrite block write
	// Support exceeds the maximum pdu length.
	// If the maximum pdu length is exceeded, it will be divided into multiple requests
	BaseWrite(area common.AreaType, dbNumber int, byteAddr int, bitAddr int, data []byte) *SimpleToken
	// DBGet get all data of the data block
	DBGet(dbNumber int) *BaseReadToken
	// DBFill fill the data block to the specified byte
	DBFill(dbNumber int, fillByte byte) *SimpleToken

	// HotRestart Puts the CPU in run mode performing and hot start.
	HotRestart() *SimpleToken
	// ColdRestart change CPU into run mode performing and cold start
	ColdRestart() *SimpleToken
	// StopPlc change CPU to stop mode
	StopPlc() *SimpleToken
	// CopyRamToRom copy Ram to Rom
	CopyRamToRom() *SimpleToken
	// Compress compress
	Compress() *SimpleToken
	// InsertFile insert file
	InsertFile(blockType common.BlockType, blockNumber int) *SimpleToken
	// UploadFile upload file content from PLC to PC
	UploadFile(blockType common.BlockType, blockNumber int) *UploadToken
	// DownloadFile download file content from PC to PLC
	DownloadFile(bytes []byte, blockType common.BlockType, blockNumber int, mC7CodeLength int) *SimpleToken
	// ClockRead read plc clock
	ClockRead() *ClockReadToken
	// ClockSet set plc clock
	ClockSet(t time.Time) *SimpleToken

	// ReadSzl
	// ref: https://support.industry.siemens.com/cs/mdm/109755202?c=22058881035&lc=cs-CZ
	ReadSzl(szlId uint16, szlIndex uint16) *PduToken
	// GetSzlIds get szl ids
	GetSzlIds() *SzlIdsToken
	// GetCatalog get plc catalog(order code and versionοΌ‰
	GetCatalog() *CatalogToken
	// GetPlcStatus get plc mode running status
	GetPlcStatus() *PlcStatusToken
	// GetUnitInfo get plc unit info
	GetUnitInfo() *UnitInfoToken
	// GetCommunicationInfo get plc communication info
	GetCommunicationInfo() *CommunicationInfoToken
	// GetProtectionInfo get plc protection level info
	GetProtectionInfo() *ProtectionInfoToken

	// BlockList list blocks info(block countοΌ‰
	BlockList() *BlockListToken
	// BlockListType list blocks of type
	BlockListType(blockType common.BlockType) *BlockListTypeToken
	// BlockInfo get block info
	BlockInfo(bt common.BlockType, bn int) *BlockInfoToken

	// SetPassword set session pwd
	SetPassword(pwd string) *SimpleToken
	// ClearPassword clear session pwd
	ClearPassword() *SimpleToken
}

type ClientBuilder ΒΆ

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

func NewClientBuilder ΒΆ

func NewClientBuilder() ClientBuilder

func (ClientBuilder) AutoReconnect ΒΆ

func (b ClientBuilder) AutoReconnect(autoReconnect bool) ClientBuilder

func (ClientBuilder) Build ΒΆ

func (b ClientBuilder) Build() Client

func (ClientBuilder) BuildAndConnect ΒΆ

func (b ClientBuilder) BuildAndConnect() *ConnectToken

func (ClientBuilder) ConnectRetry ΒΆ

func (b ClientBuilder) ConnectRetry(connectRetry bool) ClientBuilder

func (ClientBuilder) Host ΒΆ

func (b ClientBuilder) Host(host string) ClientBuilder

func (ClientBuilder) Logger ΒΆ

func (b ClientBuilder) Logger(logger logging.Logger) ClientBuilder

func (ClientBuilder) MaxReconnectBackoff ΒΆ

func (b ClientBuilder) MaxReconnectBackoff(maxReconnectBackoff time.Duration) ClientBuilder

func (ClientBuilder) MaxReconnectTimes ΒΆ

func (b ClientBuilder) MaxReconnectTimes(maxReconnectTimes int) ClientBuilder

func (ClientBuilder) MaxRetries ΒΆ

func (b ClientBuilder) MaxRetries(maxRetries int) ClientBuilder

func (ClientBuilder) MaxRetryBackoff ΒΆ

func (b ClientBuilder) MaxRetryBackoff(maxRetryBackoff time.Duration) ClientBuilder

func (ClientBuilder) OnConnected ΒΆ

func (b ClientBuilder) OnConnected(onConnected func(c Client)) ClientBuilder

func (ClientBuilder) OnUnActive ΒΆ

func (b ClientBuilder) OnUnActive(onUnActive func(c Client, err error)) ClientBuilder

func (ClientBuilder) PduLength ΒΆ

func (b ClientBuilder) PduLength(pduLength int) ClientBuilder

func (ClientBuilder) PlcType ΒΆ

func (b ClientBuilder) PlcType(plcType common.PlcType) ClientBuilder

func (ClientBuilder) Port ΒΆ

func (b ClientBuilder) Port(port int) ClientBuilder

func (ClientBuilder) Rack ΒΆ

func (b ClientBuilder) Rack(rack int) ClientBuilder

func (ClientBuilder) ReconnectInterval ΒΆ

func (b ClientBuilder) ReconnectInterval(interval time.Duration) ClientBuilder

func (ClientBuilder) RetryInterval ΒΆ

func (b ClientBuilder) RetryInterval(interval time.Duration) ClientBuilder

func (ClientBuilder) Slot ΒΆ

func (b ClientBuilder) Slot(slot int) ClientBuilder

func (ClientBuilder) Timeout ΒΆ

func (b ClientBuilder) Timeout(timeout time.Duration) ClientBuilder

type ClockReadToken ΒΆ

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

func (*ClockReadToken) Async ΒΆ

func (b *ClockReadToken) Async(ack func(v V, err error))

func (*ClockReadToken) Done ΒΆ

func (b *ClockReadToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*ClockReadToken) Wait ΒΆ

func (b *ClockReadToken) Wait() (V, error)

func (*ClockReadToken) WaitTimeout ΒΆ

func (b *ClockReadToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type CommunicationInfoToken ΒΆ

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

func (*CommunicationInfoToken) Async ΒΆ

func (b *CommunicationInfoToken) Async(ack func(v V, err error))

func (*CommunicationInfoToken) Done ΒΆ

func (b *CommunicationInfoToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*CommunicationInfoToken) Wait ΒΆ

func (b *CommunicationInfoToken) Wait() (V, error)

func (*CommunicationInfoToken) WaitTimeout ΒΆ

func (b *CommunicationInfoToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type ConnectRequestContext ΒΆ

type ConnectRequestContext struct {
	Request  *core.PDU
	Response chan *core.PDU
	Error    chan error
}

func (*ConnectRequestContext) GetRequest ΒΆ

func (c *ConnectRequestContext) GetRequest() *core.PDU

func (*ConnectRequestContext) GetRequestId ΒΆ

func (c *ConnectRequestContext) GetRequestId() uint16

func (*ConnectRequestContext) GetResponse ΒΆ

func (c *ConnectRequestContext) GetResponse() (res *core.PDU, err error)

func (*ConnectRequestContext) PutError ΒΆ

func (c *ConnectRequestContext) PutError(err error)

func (*ConnectRequestContext) PutResponse ΒΆ

func (c *ConnectRequestContext) PutResponse(data *core.PDU)

type ConnectToken ΒΆ

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

func (*ConnectToken) Async ΒΆ

func (b *ConnectToken) Async(ack func(v V, err error))

func (*ConnectToken) Done ΒΆ

func (b *ConnectToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*ConnectToken) Wait ΒΆ

func (b *ConnectToken) Wait() (V, error)

func (*ConnectToken) WaitTimeout ΒΆ

func (b *ConnectToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type Counter ΒΆ

type Counter uint16

func CounterFromBytes ΒΆ

func CounterFromBytes(bs []byte) (c Counter, err error)

func (Counter) String ΒΆ

func (c Counter) String() string

func (Counter) ToBytes ΒΆ

func (c Counter) ToBytes() []byte

type DInt ΒΆ

type DInt int32

func DIntFromBytes ΒΆ

func DIntFromBytes(bs []byte) (d DInt, err error)

func (DInt) String ΒΆ

func (d DInt) String() string

func (DInt) ToBytes ΒΆ

func (d DInt) ToBytes() []byte

type DWord ΒΆ

type DWord uint32

func DWordFromBytes ΒΆ

func DWordFromBytes(bs []byte) (d DWord, err error)

func (DWord) String ΒΆ

func (d DWord) String() string

func (DWord) ToBytes ΒΆ

func (d DWord) ToBytes() []byte

type Date ΒΆ

type Date time.Time

func DateFromBytes ΒΆ

func DateFromBytes(bs []byte) (d Date, err error)

func (Date) String ΒΆ

func (d Date) String() string

func (Date) ToBytes ΒΆ

func (d Date) ToBytes() []byte

type DateTime ΒΆ

type DateTime time.Time

func DateTimeFromBytes ΒΆ

func DateTimeFromBytes(bs []byte) (d DateTime, err error)

func (DateTime) String ΒΆ

func (d DateTime) String() string

func (DateTime) ToBytes ΒΆ

func (d DateTime) ToBytes() []byte

type DateTimeLong ΒΆ

type DateTimeLong time.Time

func DateTimeLongFromBytes ΒΆ

func DateTimeLongFromBytes(bs []byte) (d DateTimeLong, err error)

func (DateTimeLong) String ΒΆ

func (d DateTimeLong) String() string

func (DateTimeLong) ToBytes ΒΆ

func (d DateTimeLong) ToBytes() []byte

type ErrorToken ΒΆ

type ErrorToken interface {
	// Wait will wait indefinitely for the ErrorToken to complete, ie the Publishing
	// to be sent and confirmed receipt from the broker.
	Wait() error

	// WaitTimeout takes a time.Duration to wait for the flow associated with the
	// ErrorToken to complete, returns true if it returned before the timeout or
	// returns false if the timeout occurred. In the case of a timeout the ErrorToken
	// does not have an error set in case the caller wishes to wait again.
	WaitTimeout(time.Duration) error

	Async(func(error))

	// Done returns a channel that is closed when the flow associated
	// with the ErrorToken completes. Clients should call Error after the
	// channel is closed to check if the flow completed successfully.
	//
	// Done is provided for use in select statements. Simple use cases may
	// use Wait or WaitTimeout.
	Done() <-chan struct{}
}

type Int ΒΆ

type Int int16

func IntFromBytes ΒΆ

func IntFromBytes(bs []byte) (i Int, err error)

func (Int) String ΒΆ

func (i Int) String() string

func (Int) ToBytes ΒΆ

func (i Int) ToBytes() []byte

type OnClose ΒΆ

type OnClose func(c gnet.Conn, err error)

type OnOpen ΒΆ

type OnOpen func(c gnet.Conn)

type PduToken ΒΆ

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

func (*PduToken) Async ΒΆ

func (b *PduToken) Async(ack func(v V, err error))

func (*PduToken) Done ΒΆ

func (b *PduToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*PduToken) Wait ΒΆ

func (b *PduToken) Wait() (V, error)

func (*PduToken) WaitTimeout ΒΆ

func (b *PduToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type PduValidate ΒΆ

type PduValidate func(tpkt common.TPKT) error

type PlcStatusToken ΒΆ

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

func (*PlcStatusToken) Async ΒΆ

func (b *PlcStatusToken) Async(ack func(v V, err error))

func (*PlcStatusToken) Done ΒΆ

func (b *PlcStatusToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*PlcStatusToken) Wait ΒΆ

func (b *PlcStatusToken) Wait() (V, error)

func (*PlcStatusToken) WaitTimeout ΒΆ

func (b *PlcStatusToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type ProtectionInfoToken ΒΆ

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

func (*ProtectionInfoToken) Async ΒΆ

func (b *ProtectionInfoToken) Async(ack func(v V, err error))

func (*ProtectionInfoToken) Done ΒΆ

func (b *ProtectionInfoToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*ProtectionInfoToken) Wait ΒΆ

func (b *ProtectionInfoToken) Wait() (V, error)

func (*ProtectionInfoToken) WaitTimeout ΒΆ

func (b *ProtectionInfoToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type RawInfo ΒΆ added in v0.0.2

type RawInfo struct {
	Value []byte
	Type  common.ParamVariableType
	// contains filtered or unexported fields
}

func (RawInfo) Parse ΒΆ added in v0.0.2

func (r RawInfo) Parse() (res any, err error)

type ReadToken ΒΆ

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

func (*ReadToken) Async ΒΆ

func (b *ReadToken) Async(ack func(v V, err error))

func (*ReadToken) Done ΒΆ

func (b *ReadToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*ReadToken) Wait ΒΆ

func (b *ReadToken) Wait() (V, error)

func (*ReadToken) WaitTimeout ΒΆ

func (b *ReadToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type Real ΒΆ

type Real float32

func RealFromBytes ΒΆ

func RealFromBytes(bs []byte) (r Real, err error)

func (Real) String ΒΆ

func (r Real) String() string

func (Real) ToBytes ΒΆ

func (r Real) ToBytes() []byte

type RequestContext ΒΆ

type RequestContext interface {
	PutError(err error)
	PutResponse(data *core.PDU)
	GetResponse() (data *core.PDU, err error)
	GetRequestId() uint16
	GetRequest() *core.PDU
}

type S5Time ΒΆ

type S5Time time.Duration

func S5TimeFromBytes ΒΆ

func S5TimeFromBytes(bs []byte) (s S5Time, err error)

func (S5Time) String ΒΆ

func (s S5Time) String() string

func (S5Time) ToBytes ΒΆ

func (s S5Time) ToBytes() []byte

type SimpleToken ΒΆ

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

func (*SimpleToken) Async ΒΆ

func (s *SimpleToken) Async(ack func(err error))

func (*SimpleToken) Done ΒΆ

func (s *SimpleToken) Done() <-chan struct{}

func (*SimpleToken) Wait ΒΆ

func (s *SimpleToken) Wait() error

func (*SimpleToken) WaitTimeout ΒΆ

func (s *SimpleToken) WaitTimeout(d time.Duration) error

type SingleParsedReadToken ΒΆ

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

func (*SingleParsedReadToken) Async ΒΆ

func (b *SingleParsedReadToken) Async(ack func(v V, err error))

func (*SingleParsedReadToken) Done ΒΆ

func (b *SingleParsedReadToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*SingleParsedReadToken) Wait ΒΆ

func (b *SingleParsedReadToken) Wait() (V, error)

func (*SingleParsedReadToken) WaitTimeout ΒΆ

func (b *SingleParsedReadToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type SingleRawReadToken ΒΆ

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

func (*SingleRawReadToken) Async ΒΆ

func (b *SingleRawReadToken) Async(ack func(v V, err error))

func (*SingleRawReadToken) Done ΒΆ

func (b *SingleRawReadToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*SingleRawReadToken) Wait ΒΆ

func (b *SingleRawReadToken) Wait() (V, error)

func (*SingleRawReadToken) WaitTimeout ΒΆ

func (b *SingleRawReadToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type StandardRequestContext ΒΆ

type StandardRequestContext struct {
	RequestId uint16
	Request   *core.PDU
	Response  chan *core.PDU
	Error     chan error
}

func (*StandardRequestContext) GetRequest ΒΆ

func (s *StandardRequestContext) GetRequest() *core.PDU

func (*StandardRequestContext) GetRequestId ΒΆ

func (s *StandardRequestContext) GetRequestId() uint16

func (*StandardRequestContext) GetResponse ΒΆ

func (s *StandardRequestContext) GetResponse() (res *core.PDU, err error)

func (*StandardRequestContext) PutError ΒΆ

func (s *StandardRequestContext) PutError(err error)

func (*StandardRequestContext) PutResponse ΒΆ

func (s *StandardRequestContext) PutResponse(data *core.PDU)

type Status ΒΆ

type Status uint32

func (Status) String ΒΆ

func (s Status) String() string

type String ΒΆ

type String string

func StringFromBytes ΒΆ

func StringFromBytes(bs []byte, plcType common.PlcType) (s String, err error)

func (String) String ΒΆ

func (s String) String() string

func (String) ToBytes ΒΆ

func (s String) ToBytes(pduLength int) []byte

type SzlIdsToken ΒΆ

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

func (*SzlIdsToken) Async ΒΆ

func (b *SzlIdsToken) Async(ack func(v V, err error))

func (*SzlIdsToken) Done ΒΆ

func (b *SzlIdsToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*SzlIdsToken) Wait ΒΆ

func (b *SzlIdsToken) Wait() (V, error)

func (*SzlIdsToken) WaitTimeout ΒΆ

func (b *SzlIdsToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type Time ΒΆ

type Time time.Duration

func TimeFromBytes ΒΆ

func TimeFromBytes(bs []byte) (t Time, err error)

func (Time) String ΒΆ

func (t Time) String() string

func (Time) ToBytes ΒΆ

func (t Time) ToBytes() []byte

type TimeOfDay ΒΆ

type TimeOfDay time.Time

func TimeOfDayFromBytes ΒΆ

func TimeOfDayFromBytes(bs []byte) (t TimeOfDay, err error)

func (TimeOfDay) String ΒΆ

func (tod TimeOfDay) String() string

func (TimeOfDay) ToBytes ΒΆ

func (tod TimeOfDay) ToBytes() []byte

type Timer ΒΆ

type Timer time.Duration

func TimerFromBytes ΒΆ

func TimerFromBytes(bs []byte) (t Timer, err error)

func (Timer) String ΒΆ

func (t Timer) String() string

func (Timer) ToBytes ΒΆ

func (t Timer) ToBytes() []byte

type TokenCompleter ΒΆ

type TokenCompleter interface {
	TokenErrorSetter
	// contains filtered or unexported methods
}

func NewToken ΒΆ

func NewToken(tt TokenType) TokenCompleter

type TokenErrorSetter ΒΆ

type TokenErrorSetter interface {
	// contains filtered or unexported methods
}

type TokenType ΒΆ

type TokenType byte
const (
	TtSimple TokenType = iota
	TtConnect
	TtRead
	TtPdu
	TtSingleRawRead
	TtBatchRawRead
	TtSingleParsedRead
	TtBatchParsedRead
	TtUpload
	TtSzlIds
	TtCatalog
	TtPlcStatus
	TtUnitInfo
	TtCommunicationInfo
	TtProtectionInfo
	TtBlockList
	TtBlockListType
	TtBlockInfo
	TtClockRead
	TtBaseRead
)

type UnitInfoToken ΒΆ

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

func (*UnitInfoToken) Async ΒΆ

func (b *UnitInfoToken) Async(ack func(v V, err error))

func (*UnitInfoToken) Done ΒΆ

func (b *UnitInfoToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*UnitInfoToken) Wait ΒΆ

func (b *UnitInfoToken) Wait() (V, error)

func (*UnitInfoToken) WaitTimeout ΒΆ

func (b *UnitInfoToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type UploadToken ΒΆ

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

func (*UploadToken) Async ΒΆ

func (b *UploadToken) Async(ack func(v V, err error))

func (*UploadToken) Done ΒΆ

func (b *UploadToken) Done() <-chan struct{}

Done implements the ValueToken Done method.

func (*UploadToken) Wait ΒΆ

func (b *UploadToken) Wait() (V, error)

func (*UploadToken) WaitTimeout ΒΆ

func (b *UploadToken) WaitTimeout(d time.Duration) (V, error)

WaitTimeout implements the ValueToken WaitTimeout method.

type ValueToken ΒΆ

type ValueToken[V interface{}] interface {
	// Wait will wait indefinitely for the ValueToken to complete, ie the Publishing
	// to be sent and confirmed receipt from the broker.
	Wait() (V, error)

	// WaitTimeout takes a time.Duration to wait for the flow associated with the
	// ValueToken to complete, returns true if it returned before the timeout or
	// returns false if the timeout occurred. In the case of a timeout the ValueToken
	// does not have an error set in case the caller wishes to wait again.
	WaitTimeout(time.Duration) (V, error)

	Async(func(V, error))

	// Done returns a channel that is closed when the flow associated
	// with the ValueToken completes. Clients should call Error after the
	// channel is closed to check if the flow completed successfully.
	//
	// Done is provided for use in select statements. Simple use cases may
	// use Wait or WaitTimeout.
	Done() <-chan struct{}
}

type WString ΒΆ

type WString string

func WStringFromBytes ΒΆ

func WStringFromBytes(bs []byte, plcType common.PlcType) (s WString, err error)

func (WString) String ΒΆ

func (s WString) String() string

func (WString) ToBytes ΒΆ

func (s WString) ToBytes(pduLength int) []byte

type Word ΒΆ

type Word uint16

func WordFromBytes ΒΆ

func WordFromBytes(bs []byte) (w Word, err error)

func (Word) String ΒΆ

func (w Word) String() string

func (Word) ToBytes ΒΆ

func (w Word) ToBytes() []byte

Directories ΒΆ

Path Synopsis

Jump to

Keyboard shortcuts

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