Documentation
¶
Index ¶
- func CPUError(err uint) int
- func ErrorText(err int) string
- type Client
- type ClientHandler
- 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
- type Transporter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client interface {
/***************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)
}
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.
type ClientHandler ¶
type ClientHandler interface {
Packager
Transporter
}
CliePDULengthntHandler is the interface that groups the Packager and Transporter methods.
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
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 (*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
type Transporter ¶
Transporter specifies the transport layer.