Documentation
¶
Index ¶
- func CPUError(err uint) int
- func ErrorText(err int) string
- type Client
- func NewClient(handler ClientHandler) Client
- func NewClient2(packager Packager, transporter Transporter) Client
- func TCPClient(address string, rack int, slot int) Client
- func TCPClientWithConnectType(address string, rack int, slot int, connectType int) Client
- func TCPClientWithTimeout(address string, rack int, slot int, timeout time.Duration) Client
- func TCPClientWithTimeouts(address string, rack int, slot int, connectTimeout time.Duration, ...) Client
- type ClientErrorRecord
- type ClientHandler
- type ClientStatus
- type Helper
- func (s7 *Helper) GetBoolAt(b byte, pos uint) bool
- func (s7 *Helper) GetCharsAt(buffer []byte, pos int, Size int) string
- func (s7 *Helper) GetCounter(value uint16) int
- func (s7 *Helper) GetCounterAt(buffer []uint16, index int) int
- func (s7 *Helper) GetDTLAt(buffer []byte, pos int) time.Time
- func (s7 *Helper) GetDateAt(buffer []byte, pos int) time.Time
- func (s7 *Helper) GetDateTimeAt(Buffer []byte, Pos int) time.Time
- func (s7 *Helper) GetLDTAt(buffer []byte, pos int) time.Time
- func (s7 *Helper) GetLRealAt(buffer []byte, pos int) float64
- func (s7 *Helper) GetLTODAt(Buffer []byte, Pos int) time.Time
- func (s7 *Helper) GetRealAt(buffer []byte, pos int) float32
- func (s7 *Helper) GetS5TimeAt(buffer []byte, pos int) time.Duration
- func (s7 *Helper) GetStringAt(buffer []byte, pos int) string
- func (s7 *Helper) GetTODAt(buffer []byte, pos int) time.Time
- func (s7 *Helper) GetValueAt(buffer []byte, pos int, value interface{})
- func (s7 *Helper) GetWStringAt(buffer []byte, pos int) string
- func (s7 *Helper) SetBoolAt(b byte, bitPos uint, data bool) byte
- func (s7 *Helper) SetCharsAt(buffer []byte, pos int, value string)
- func (s7 *Helper) SetCounterAt(buffer []uint16, pos int, value int) []uint16
- func (s7 *Helper) SetDTLAt(buffer []byte, pos int, value time.Time) []byte
- func (s7 *Helper) SetDateAt(buffer []byte, pos int, value time.Time)
- func (s7 *Helper) SetDateTimeAt(buffer []byte, pos int, value time.Time)
- func (s7 *Helper) SetLDTAt(buffer []byte, pos int, value time.Time)
- func (s7 *Helper) SetLRealAt(Buffer []byte, Pos int, Value float64)
- func (s7 *Helper) SetLTODAt(buffer []byte, pos int, value time.Time)
- func (s7 *Helper) SetRealAt(buffer []byte, pos int, value float32)
- func (s7 *Helper) SetS5TimeAt(buffer []byte, pos int, value time.Duration) []byte
- func (s7 *Helper) SetStringAt(buffer []byte, pos int, maxLen int, value string) []byte
- func (s7 *Helper) SetTODAt(buffer []byte, pos int, value time.Time)
- func (s7 *Helper) SetValueAt(buffer []byte, pos int, data interface{})
- func (s7 *Helper) SetWStringAt(buffer []byte, pos int, maxLen int, value string) []byte
- func (s7 *Helper) ToCounter(value int) uint16
- type Packager
- type ProtocolDataUnit
- type S7BlockInfo
- type S7BlocksList
- type S7CpInfo
- type S7CpuInfo
- type S7DataItem
- type S7Error
- type S7OrderCode
- type S7Protection
- type S7SZL
- type S7SZLList
- type SZLHeader
- type TCPClientHandler
- func NewTCPClientHandler(address string, rack int, slot int) *TCPClientHandler
- func NewTCPClientHandlerWithConnectType(address string, rack int, slot int, connectType int) *TCPClientHandler
- func NewTCPClientHandlerWithTimeout(address string, rack int, slot int, timeout time.Duration) *TCPClientHandler
- func NewTCPClientHandlerWithTimeouts(address string, rack int, slot int, connectTimeout time.Duration, ...) *TCPClientHandler
- func (mb *TCPClientHandler) Close() error
- func (mb *TCPClientHandler) Connect() error
- func (mb *TCPClientHandler) ConnectContext(ctx context.Context) error
- func (mb *TCPClientHandler) GetPduLength() (int, error)
- func (mb *TCPClientHandler) IsConnected() bool
- func (mb *TCPClientHandler) RemoteAddress() string
- func (mb *TCPClientHandler) Send(request []byte) (response []byte, err error)
- func (mb *TCPClientHandler) Verify(request []byte, response []byte) (err error)
- type Transporter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client interface {
io.Closer
/***************start API AG (Automatisationsgerät)***************/
//Read data blocks from PLC
AGReadDB(dbNumber int, start int, size int, buffer []byte) (err error)
//write data blocks into PLC
AGWriteDB(dbNumber int, start int, size int, buffer []byte) (err error)
//Read Merkers area from PLC
AGReadMB(start int, size int, buffer []byte) (err error)
//Write Merkers from into PLC
AGWriteMB(start int, size int, buffer []byte) (err error)
//Read IPI from PLC
AGReadEB(start int, size int, buffer []byte) (err error)
//Write IPI into PLC
AGWriteEB(start int, size int, buffer []byte) (err error)
//Read IPU from PLC
AGReadAB(start int, size int, buffer []byte) (err error)
//Write IPU into PLC
AGWriteAB(start int, size int, buffer []byte) (err error)
//Read timer from PLC
AGReadTM(start int, size int, buffer []byte) (err error)
//Write timer into PLC
AGWriteTM(start int, size int, buffer []byte) (err error)
//Read counter from PLC
AGReadCT(start int, size int, buffer []byte) (err error)
//Write counter into PLC
AGWriteCT(start int, size int, buffer []byte) (err error)
//multi read area
AGReadMulti(dataItems []S7DataItem, itemsCount int) (err error)
//multi write area
AGWriteMulti(dataItems []S7DataItem, itemsCount int) (err error)
/*block*/
DBFill(dbnumber int, fillchar int) error
DBGet(dbnumber int, usrdata []byte, size int) error
//general read function with S7 sytax
Read(variable string, buffer []byte) (value interface{}, err error)
//Get block infor in AG area, refer an S7BlockInfor pointer
GetAgBlockInfo(blocktype int, blocknum int) (info S7BlockInfo, err error)
/***************start API PG (Programmiergerät)***************/
/*control*/
//Hotstart PLC, Puts the CPU in RUN mode performing an HOT START.
PLCHotStart() error
//Cold start PLC, change CPU into runmode performing and COLD START
PLCColdStart() error
//change CPU to stop mode
PLCStop() error
//return CPU status: running/stopped
PLCGetStatus() (status int, err error)
/*directory*/
//list all blocks in PLC, return a Blockslist which contains list of OB, DB, ...
PGListBlocks() (list S7BlocksList, err error)
/*security*/
//set the session password for PLC to meet its security level
SetSessionPassword(password string) error
//clear the password set for current session
ClearSessionPassword() error
//return the CPU protection level info, refer to: §33.19 of "System Software for S7-300/400 System and Standard Functions"
//return S7Protection and its properties.
GetProtection() (protection S7Protection, err error)
/*system information*/
//get CPU order code, return S7OrderCode
GetOrderCode() (info S7OrderCode, err error)
//get CPU info, return S7CpuInfo and its properties
GetCPUInfo() (info S7CpuInfo, err error)
//get CP info, return S7CpInfo and its properties
GetCPInfo() (info S7CpInfo, err error)
/*datetime*/
//read clock on PLC, return a time
PGClockRead(datetime time.Time) error
//write clock to PLC with datetime input
PGClockWrite() (dt time.Time, err error)
// GetClientStatus returns the current status of the client connection, including connection state, last activity times, byte counts, and error records.
GetClientStatus() (status *ClientStatus, err error)
}
Client interface s7 client
func NewClient ¶
func NewClient(handler ClientHandler) Client
NewClient creates a new s7 client with given backend handler.
func NewClient2 ¶
func NewClient2(packager Packager, transporter Transporter) Client
NewClient2 creates a new s7 client with given backend packager and transporter.
func TCPClient ¶
TCPClient creator for a TCP client with address, rack and slot, implement from interface client
func TCPClientWithConnectType ¶
TCPClientWithConnectType creator for a TCP client with address, rack, slot and connect type, implement from interface client
func TCPClientWithTimeout ¶
type ClientErrorRecord ¶
type ClientHandler ¶
type ClientHandler interface {
Packager
Transporter
}
CliePDULengthntHandler is the interface that groups the Packager and Transporter methods.
type ClientStatus ¶
type ClientStatus struct {
IsConnected bool // Indicates whether the client is currently connected to the PLC.
ConnectTime time.Time // Indicates the time when the client was last connected to the PLC.
DisconnectTime time.Time // Indicates the time when the client was last disconnected from the PLC.
LastSendTime time.Time // Indicates the time of the last send operation on the connection.
LastRecvTime time.Time // Indicates the time of the last receive operation on the connection.
SendBytes int64 // Indicates the number of bytes sent to the PLC since the last connection was established.
RecvBytes int64 // Indicates the number of bytes received from the PLC since the last connection was established.
TotalSendBytes int64 // Indicates the total number of bytes sent to the PLC since the client was created.
TotalRecvBytes int64 // Indicates the total number of bytes received from the PLC since the client was created.
LastError *ClientErrorRecord // Indicates the last error encountered during communication with the PLC.
Last10Errors []*ClientErrorRecord // A slice that stores the last 10 errors encountered during communication with the PLC.
AvgRespTime uint32 // Indicates the average response time for requests sent to the PLC, in microseconds.
MinRespTime uint32 // Indicates the minimum response time for requests sent to the PLC, in microseconds.
MaxRespTime uint32 // Indicates the maximum response time for requests sent to the PLC, in microseconds.
RemoteAddress string // Indicates the remote address of the PLC to which the client is connected. tcp only
}
ClientStatus represents the status of a client connection.
func (*ClientStatus) String ¶
func (status *ClientStatus) String() string
type Helper ¶
type Helper struct{}
Helper the helper to get/set value from/to byte array with difference types
func (*Helper) GetCharsAt ¶
GetCharsAt Get Array of char (S7 ARRAY OF CHARS)
func (*Helper) GetCounter ¶
GetCounter Get S7 Counter
func (*Helper) GetCounterAt ¶
GetCounterAt Get S7 Counter at a index
func (*Helper) GetDateTimeAt ¶
GetDateTimeAt DateTime (S7 DATE_AND_TIME)
func (*Helper) GetLRealAt ¶
GetLRealAt 64 bit floating point number (S7 LReal) (Range of float64)
func (*Helper) GetS5TimeAt ¶
Get S5Time
func (*Helper) GetStringAt ¶
GetStringAt Get String
func (*Helper) GetValueAt ¶
GetValueAt set a value at a position of a byte array, which based on builtin function: https://golang.org/pkg/encoding/binary/#Write
func (*Helper) GetWStringAt ¶
GetWStringAt Get WString
func (*Helper) SetBoolAt ¶
SetBoolAt sets a boolean (bit) within a byte at bit position without changing the other bits it returns the resulted byte
func (*Helper) SetCharsAt ¶
SetCharsAt Get Array of char (S7 ARRAY OF CHARS)
func (*Helper) SetCounterAt ¶
SetCounterAt set a counter at a postion
func (*Helper) SetDateTimeAt ¶
SetDateTimeAt DateTime (S7 DATE_AND_TIME)
func (*Helper) SetLRealAt ¶
SetLRealAt 64 bit floating point number (S7 LReal) (Range of float64)
func (*Helper) SetS5TimeAt ¶
SetS5TimeAt Set S5Time
func (*Helper) SetStringAt ¶
SetStringAt Set String (S7 String)
func (*Helper) SetValueAt ¶
SetValueAt set a value at a position of a byte array, which based on builtin function: https://golang.org/pkg/encoding/binary/#Read
func (*Helper) SetWStringAt ¶
SetWStringAt Set String (WString)
type Packager ¶
type Packager interface {
//reserve for future use
Verify(request []byte, response []byte) (err error)
}
Packager specifies the communication layer.
type ProtocolDataUnit ¶
type ProtocolDataUnit struct {
Data []byte
}
ProtocolDataUnit (PDU) is independent of underlying communication layers.
func NewProtocolDataUnit ¶
func NewProtocolDataUnit(data []byte) ProtocolDataUnit
NewProtocolDataUnit ProtocolDataUnit Constructor
type S7BlockInfo ¶
type S7BlockInfo struct {
BlkType int
BlkNumber int
BlkLang int
BlkFlags int
MC7Size int // The real size in bytes
LoadSize int
LocalData int
SBBLength int
CheckSum int
Version int
// Chars info
CodeDate string
IntfDate string
Author string
Family string
Header string
}
S7BlockInfo Managed Block Info
type S7BlocksList ¶
type S7BlocksList struct {
OBList []int
FBList []int
FCList []int
SFBList []int
SFCList []int
DBList []int
SDBList []int
}
S7BlocksList Block List
type S7CpuInfo ¶
type S7CpuInfo struct {
ModuleTypeName string
SerialNumber string
ASName string
Copyright string
ModuleName string
}
S7CpuInfo CPU Info
type S7DataItem ¶
type S7DataItem struct {
Area int
WordLen int
DBNumber int
Start int
Bit int
Amount int
Data []byte
Error string
}
S7DataItem which expose as S7DataItem to use in Multiple read/write
type S7OrderCode ¶
type S7OrderCode struct {
Code string // such as "6ES7 151-8AB01-0AB0"
V1 byte // Version 1st digit
V2 byte // Version 2nd digit
V3 byte // Version 3th digit
}
S7OrderCode Order Code + Version
type S7Protection ¶
type S7Protection struct {
// contains filtered or unexported fields
}
S7Protection See §33.19 of "System Software for S7-300/400 System and Standard Functions"
type S7SZLList ¶
S7SZLList of available SZL IDs : same as SZL but List items are big-endian adjusted
type SZLHeader ¶
SZLHeader See §33.1 of "System Software for S7-300/400 System and Standard Functions" and see SFC51 description too
type TCPClientHandler ¶
type TCPClientHandler struct {
// contains filtered or unexported fields
}
TCPClientHandler implements Packager and Transporter interface.
func NewTCPClientHandler ¶
func NewTCPClientHandler(address string, rack int, slot int) *TCPClientHandler
NewTCPClientHandler allocates a new TCPClientHandler.
func NewTCPClientHandlerWithConnectType ¶
func NewTCPClientHandlerWithConnectType(address string, rack int, slot int, connectType int) *TCPClientHandler
NewTCPClientHandlerWithConnectType allocates a new TCPClientHandler with connection type.
func NewTCPClientHandlerWithTimeouts ¶
func NewTCPClientHandlerWithTimeouts(address string, rack int, slot int, connectTimeout time.Duration, readTimeout time.Duration) *TCPClientHandler
NewTCPClientHandlerWithTimeouts allocates a new TCPClientHandler with separate connect timeout and read/write timeout.
func (*TCPClientHandler) Close ¶
func (mb *TCPClientHandler) Close() error
Close closes current connection.
func (*TCPClientHandler) Connect ¶
func (mb *TCPClientHandler) Connect() error
Connect establishes a new connection to the address in Address. Connect and Close are exported so that multiple requests can be done with one session
func (*TCPClientHandler) ConnectContext ¶
ConnectContext establishes a new connection to the address in Address. It is the same as Connect but accepts a context that can be used to cancel or set a deadline on the TCP dial and subsequent protocol handshake.
func (*TCPClientHandler) GetPduLength ¶ added in v1.0.3
func (*TCPClientHandler) IsConnected ¶
func (mb *TCPClientHandler) IsConnected() bool
IsConnected reports whether the underlying TCP connection is active.
func (*TCPClientHandler) RemoteAddress ¶
func (mb *TCPClientHandler) RemoteAddress() string
RemoteAddress returns the current remote endpoint for TCP transport.