wrap7

package module
v0.0.0-...-b294854 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: GPL-3.0, LGPL-3.0 Imports: 14 Imported by: 0

README

wrap7

Go-Wrapper for Snap7

When using as go module it is necessary to first enter vendor directory

"cd vendor/git.archium.org/archium_public/wrap7"

and execute Makefile as root:

"sudo make"

to download and install snap7-full-1.4.2.

Be aware to edit Makefile to your system requirements! And consider better to install Snap7 in the /usr/lib tree!

Documentation

Overview

wrap7 project wrap7.go

wrap7 project wrap7.go

wrap7 project wrap7.go

Index

Constants

View Source
const (
	PINGER_COUNT                 = 10       // Die Anzahl an Pings, die der Pinger zur Auswertung heranzieht. Pinger-Counts kosten richtig viel Zeit. Leider ist ein Ping alleine viel zu ungenau.
	PINGER_TIMEOUT               = "1000ms" // Sobald der Pinger innerhalb dieser Zeitspanne keinen Erfolg hat, liefert er 0ms Pingzeit und 100% Paketloss zur?ck.
	PINGER_CRITICAL_LOSS_PERCENT = 100
)
View Source
const (
	BlockTypeOB  = 0x38
	BlockTypeDB  = 0x41
	BlockTypeSDB = 0x42
	BlockTypeFC  = 0x43
	BlockTypeSFC = 0x44
	BlockTypeFB  = 0x45
	BlockTypeSFB = 0x46
)
View Source
const MAXPDULENGTH int = 960

Diese Konstante gibt es doppelt. Sie muß auch im C-Code angepaßt werden!

View Source
const MULTIREADWRITE_BUFFERS = 10 // Wievele Buffers und Items MultiRead und MultiWrite anlegen soll.

Variables

View Source
var (
	S7AreaDB = (int)(C.S7AreaDB)
	S7AreaMK = (int)(C.S7AreaMK)
	S7AreaPE = (int)(C.S7AreaPE)
	S7AreaPA = (int)(C.S7AreaPA)
	S7AreaTM = (int)(C.S7AreaTM)
	S7AreaCT = (int)(C.S7AreaCT)

	S7WLBit     = (int)(C.S7WLBit)
	S7WLByte    = (int)(C.S7WLByte)
	S7WLWord    = (int)(C.S7WLWord)
	S7WLDWord   = (int)(C.S7WLDWord)
	S7WLReal    = (int)(C.S7WLReal)
	S7WLCounter = (int)(C.S7WLCounter)
	S7WLTimer   = (int)(C.S7WLTimer)
)
View Source
var (
	SrvAreaPE = (int)(C.srvAreaPE)
	SrvAreaPA = (int)(C.srvAreaPA)
	SrvAreaMK = (int)(C.srvAreaMK)
	SrvAreaCT = (int)(C.srvAreaCT)
	SrvAreaTM = (int)(C.srvAreaTM)
	SrvAreaDB = (int)(C.srvAreaDB)
)
View Source
var EventCallBackLength = (int)(C.EventCallBackLength)

Functions

func ABRead

func ABRead(client C.S7Object, Start, Amount int) (int, []byte)

func ABWrite

func ABWrite(client C.S7Object, Start, Amount int, gobuffer *[]byte) (int, []byte)

func BfDBInfo

func BfDBInfo(MyClient S7Object, maxdbnr int)

func BfDBList

func BfDBList(MyClient S7Object, startDB, endDB int) []int

func BfDBgetSize

func BfDBgetSize(MyClient S7Object, dbnr int) int

func Bit2Pos

func Bit2Pos(n int) (pos uint)

Sets the bit at pos in the integer n. pos = 0 is first.

func ByteDBuffer

func ByteDBuffer(i *uint8) []byte

func ByteDBuffer2

func ByteDBuffer2(j uint8) []byte

func ByteDBuffer3

func ByteDBuffer3(j uint8) *[]byte

func CTRead

func CTRead(client C.S7Object, Start, Amount int) (int, []byte)

func CTWrite

func CTWrite(client C.S7Object, Start, Amount int, gobuffer *[]byte) (int, []byte)

func CharDBuffer

func CharDBuffer(c *rune) []byte

func CharDBuffer2

func CharDBuffer2(z rune) []byte

func CharDBuffer3

func CharDBuffer3(z rune) *[]byte

func ClearBit

func ClearBit(n int, pos uint) int

Clears the bit at pos in n. pos = 0 is first.

func CliConnect

func CliConnect(client S7Object, ip net.IP, rack uint8, slot uint8)

CliConnect connects to SPS-client

func CliDestroy

func CliDestroy(client *S7Object)

func CliDisconnect

func CliDisconnect(client S7Object)

CliDisconnect disconnects SPS-client from SPS

func CliDisconnectAndDestroy

func CliDisconnectAndDestroy(client S7Object)

func DBRead

func DBRead(client C.S7Object, DBNumber, Start, Amount int) (int, []byte)

func DBWrite

func DBWrite(client C.S7Object, DBNumber, Start, Amount int, gobuffer *[]byte) (int, []byte)

func DBufferByte

func DBufferByte(b *[]byte) uint8

func DBufferByte2

func DBufferByte2(b []byte) uint8

func DBufferByte3

func DBufferByte3(b byte) uint8

func DBufferChar

func DBufferChar(b *[]byte) rune

func DBufferChar2

func DBufferChar2(b []byte) rune

func DBufferChar3

func DBufferChar3(b byte) rune

func DBufferDInt

func DBufferDInt(b *[]byte) int32

func DBufferDInt2

func DBufferDInt2(b []byte) int32

func DBufferDWord

func DBufferDWord(b *[]byte) uint32

func DBufferDWord2

func DBufferDWord2(b []byte) uint32

func DBufferDateNTime

func DBufferDateNTime(b *[]byte) time.Time

DBufferDateNTime wird für die drei Datentypen Date_and_Time, Date und Time benötigt

func DBufferDateNTime2

func DBufferDateNTime2(b []byte) time.Time

func DBufferInt

func DBufferInt(b *[]byte) int16

func DBufferInt2

func DBufferInt2(b []byte) int16

func DBufferReal

func DBufferReal(b *[]byte) float32

func DBufferReal2

func DBufferReal2(b []byte) float32

func DBufferString

func DBufferString(b *[]byte) string

func DBufferString2

func DBufferString2(b []byte) string

func DBufferWord

func DBufferWord(b *[]byte) uint16

func DBufferWord2

func DBufferWord2(b []byte) uint16

func DIntDBuffer

func DIntDBuffer(i *int32) []byte

func DIntDBuffer2

func DIntDBuffer2(j int32) []byte

func DIntDBuffer3

func DIntDBuffer3(j int32) *[]byte

func DWordDBuffer

func DWordDBuffer(i *uint32) []byte

func DWordDBuffer2

func DWordDBuffer2(j uint32) []byte

func DWordDBuffer3

func DWordDBuffer3(j uint32) *[]byte

func DateNTimeDBuffer

func DateNTimeDBuffer(t *time.Time, strictZeroTime bool) (b []byte)

DateNTimeDBuffer wird für die drei Datentypen Date_and_Time, Date und Time benötigt

func DateNTimeDBuffer2

func DateNTimeDBuffer2(d time.Time, strictZeroTime bool) []byte

func DateNTimeDBuffer3

func DateNTimeDBuffer3(d time.Time, strictZeroTime bool) *[]byte

func Disconnect

func Disconnect(client S7Object)

FIXME: Remove me sometimes Disconnect is a wrapper for CliDisconnect for compatibility purpose, has to be removed in a later version or wrap7

func EBRead

func EBRead(client C.S7Object, Start, Amount int) (int, []byte)

func EBWrite

func EBWrite(client C.S7Object, Start, Amount int, gobuffer *[]byte) (int, []byte)

func HasBit

func HasBit(n int, pos uint) bool

Check if bit at pos n is set. pos = 0 is first.

func IntDBuffer

func IntDBuffer(i *int16) []byte

func IntDBuffer2

func IntDBuffer2(j int16) []byte

func IntDBuffer3

func IntDBuffer3(j int16) *[]byte

func MBRead

func MBRead(client C.S7Object, Start, Amount int) (int, []byte)

func MBWrite

func MBWrite(client C.S7Object, Start, Amount int, gobuffer *[]byte) (int, []byte)

func MeasureSPSTypeLength

func MeasureSPSTypeLength(s DataTypeType) int8

Gets Wordlength of S7-Type

func MeasureSPSTypeLength(s string) int8 {
	switch strings.ToLower(s) {
	case "int":
		return 2
	case "dint":
		return 4
	case "real":
		return 4
	case "date_and_time":
		return 8
	case "date": // Nicht verifiziert
		return 2
	case "time": // Nicht verifiziert
		return 4
	case "bool":
		return 1
	case "char":
		return 1
	case "byte":
		return 1
	case "word": // Nicht verifiziert
		return 2
	case "dword": // Nicht verifiziert
		return 4
	default: // Nur im Fehlerfall
		return -1
	}
}

func MultiRead

func MultiRead(client C.S7Object, items []MultiReadWriteItem) (int, [][]byte)

MultiRead liest ein Array von Werten aus der SPS

func MultiWrite

func MultiWrite(client C.S7Object, items []MultiReadWriteItem, buffers *[][]byte) (int, [][]byte)

MultiWrite schreibt ein Array von Werten in die SPS. Auf den ersten Blick ist ein Rücklesen der Werte in MultiWrite nun ein überflüssiger Overhead. Machen wir dies hier aber nicht, müßte in Fällen, wo mit dem veränderten Speicher weitergearbeitet werden soll, ein weiteres MultiRead folgen. Dies können wir hier einsparen, wenn wir den veränderten Speicher hier zurückgeben. Wir bleiben somit auch synchron zur MultiRead-Funktion

func ParseDate

func ParseDate(ds string) (time.Time, error)

ParseDate kann der Funktion DateNTimeDBuffer vorgeschaltet werden

func ParseDateTime

func ParseDateTime(dts string) (time.Time, error)

ParseDateTime kann der Funktion DateNTimeDBuffer vorgeschaltet werden

func ParseHexForByteWordAndDWord

func ParseHexForByteWordAndDWord(hs string) (int, error)

func ParseTime

func ParseTime(dt string) (time.Time, error)

ParseTime kann der Funktion DateNTimeDBuffer vorgeschaltet werden

func Pos2Bit

func Pos2Bit(pos uint) (n int)

... and reverse

func ReadArea

func ReadArea(client C.S7Object, Area, DBNumber, Start, Amount, WordLen int) (int, []byte)

func RealDBuffer

func RealDBuffer(r *float32) []byte

func RealDBuffer2

func RealDBuffer2(f float32) []byte

func RealDBuffer3

func RealDBuffer3(f float32) *[]byte

func RegisterEventCallBack

func RegisterEventCallBack(server *S7Object)

func SetBit

func SetBit(n int, pos uint) int

Sets the bit at pos in the integer n. pos = 0 is first.

func SrvDestroy

func SrvDestroy(server *S7Object)

func SrvErrorText

func SrvErrorText(errorCode int, spsServerText *rune, eventCallBackLength int)

func SrvLockArea

func SrvLockArea(server *S7Object, area int, index uint16)

func SrvRegisterArea

func SrvRegisterArea(server *S7Object, area int, index uint16, buffer []byte, length int)

func SrvStart

func SrvStart(server *S7Object) int

func SrvStop

func SrvStop(server *S7Object)

func SrvUnlockArea

func SrvUnlockArea(server *S7Object, area int, index uint16)

func SrvUnregisterArea

func SrvUnregisterArea(server *S7Object, area int, index uint16)

func StringDBuffer

func StringDBuffer(s *string) []byte

func StringDBuffer2

func StringDBuffer2(ß string) []byte

func StringDBuffer3

func StringDBuffer3(ß string) *[]byte

func TMRead

func TMRead(client C.S7Object, Start, Amount int) (int, []byte)

func TMWrite

func TMWrite(client C.S7Object, Start, Amount int, gobuffer *[]byte) (int, []byte)

func WordDBuffer

func WordDBuffer(i *uint16) []byte

func WordDBuffer2

func WordDBuffer2(j uint16) []byte

func WordDBuffer3

func WordDBuffer3(j uint16) *[]byte

func WriteArea

func WriteArea(client C.S7Object, Area, DBNumber, Start, Amount, WordLen int, gobuffer *[]byte) (int, []byte)

Types

type ConditionType

type ConditionType string
const (
	CONDITION_RUNNING ConditionType = "running"
	CONDITION_STOPPED ConditionType = "stopped"
	CONDITION_UNKNOWN ConditionType = "unknown"
)

func GetPlcStatus

func GetPlcStatus(client C.S7Object) (int, int8, ConditionType)

type DataTypeType

type DataTypeType string
const (
	DTTint      DataTypeType = "int"
	DTTdint     DataTypeType = "dint"
	DTTreal     DataTypeType = "real"
	DTTdatetime DataTypeType = "date_and_time"
	DTTdate     DataTypeType = "date"
	DTTtime     DataTypeType = "time"
	DTTbool     DataTypeType = "bool"
	DTTbyte     DataTypeType = "byte"
	DTTchar     DataTypeType = "char"
	DTTword     DataTypeType = "word"
	DTTdword    DataTypeType = "dword"
)

type MultiReadWriteItem

type MultiReadWriteItem struct {
	Area, WordLen, DBNumber, Start, Amount int
}

type S7Object

type S7Object = C.S7Object

func CliConditionalCreateAndConnect

func CliConditionalCreateAndConnect(ip net.IP, rack uint8, slot uint8) (S7Object, error)

CliConditionalCreateAndConnect creates a SPS-client after successfull ping and connects to SPS

func CliCreate

func CliCreate() S7Object

CliCreate creates a SPS-client

func CliCreateAndConnect

func CliCreateAndConnect(ip net.IP, rack uint8, slot uint8) S7Object

CliCreateAndConnect creates a SPS-client and connect to SPS

func CreateAndConnect

func CreateAndConnect(ip net.IP, rack uint8, slot uint8) S7Object

FIXME: Remove me sometimes CreateAndConnect is a wrapper for CliDisconnect for compatibility purpose, has to be removed in a later version or wrap7

func SrvCreate

func SrvCreate() S7Object

Server Functions

type TS7BlockInfo

type TS7BlockInfo struct {
	BlkType   int // Block Type (OB, DB)
	BlkNumber int // Block number
	BlkLang   int // Block Language
	BlkFlags  int // Block flags
	MC7Size   int // The real size in bytes
	LoadSize  int // Load memory size
	LocalData int // Local data
	SBBLength int // SBB Length
	CheckSum  int // Checksum
	Version   int // Block version
	// Chars info
	CodeDate string // Code date
	IntfDate string // Interface date
	Author   string // Author
	Family   string // Family
	Header   string // Header
}

func GetAgBlockInfo

func GetAgBlockInfo(client C.S7Object, blockType, blockNum int) (int, TS7BlockInfo)

type TS7BlocksList

type TS7BlocksList struct {
	OBCount, FBCount, FCCount, SFBCount, SFCCount, DBCount, SDBCount int
}

func ListBlocks

func ListBlocks(client C.S7Object) (int, TS7BlocksList)

type TS7CpInfo

type TS7CpInfo struct {
	MaxPduLength, MaxConnections, MaxMpiRate, MaxBusRate int // MaxPduLengt zu MaxPduLength korrigiert
}

func GetCpInfo

func GetCpInfo(client C.S7Object) (int, TS7CpInfo)

type TS7OrderCode

type TS7OrderCode struct {
	Code       string
	V1, V2, V3 int
}

func GetOrderCode

func GetOrderCode(client C.S7Object) (int, TS7OrderCode)

type TSCpuInfo

type TSCpuInfo struct {
	ModuleTypeName, SerialNumber, ASName, Copyright, ModuleName string
}

func GetCpuInfo

func GetCpuInfo(client C.S7Object) (int, TSCpuInfo)

Jump to

Keyboard shortcuts

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