Categorygithub.com/fecitycoder/goStep7
modulepackage
0.0.0-20230222094047-b3f217afdf20
Repository: https://github.com/fecitycoder/gostep7.git
Documentation: pkg.go.dev

# README

goStep7

Implementation of Siemens S7 protocol in golang

Overview

Since years, there are tons of driver/connector in both commercial and open source that support to connect to S7 family PLC devices. GoS7 is just simple missing pieces in S7 protocol which implementing in with pure Go(aka golang) with a strongly faith that the low-level communication would be impelement by low-level programming language which proximity to binary and memory.

The minimum supported go version is 1.13.

Functions

AG:

  • Read/Write Data Block (DB) (tested)
  • Read/Write Merkers(MB) (tested)
  • Read/Write IPI (EB) (tested)
  • Read/Write IPU (AB) (tested)
  • Read/Write Timer (TM) (tested)
  • Read/Write Counter (CT) (tested)
  • Multiple Read/Write Area (tested)
  • Get Block Info (tested)

PG:

  • Hot start/Cold start / Stop PLC
  • Get CPU of PLC status (tested)
  • List available blocks in PLC (tested)
  • Set/Clear password for session
  • Get CPU protection and CPU Order code
  • Get CPU/CP Information (tested)
  • Read/Write clock for the PLC Helpers:
  • Get/set value for a byte array for types: value(bit/int/word/dword/uint...), real, time, counter

Supported communication

  • TCP
  • Serial (PPI, MPI) (under construction)

How to:

following is a simple usage to connect with PLC via TCP

const (
	tcpDevice = "127.0.0.1"
	rack      = 0
	slot      = 2
)
// TCPClient
handler := gos7.NewTCPClientHandler(tcpDevice, rack, slot)
handler.Timeout = 200 * time.Second
handler.IdleTimeout = 200 * time.Second
handler.Logger = log.New(os.Stdout, "tcp: ", log.LstdFlags)
// Connect manually so that multiple requests are handled in one connection session
handler.Connect()
defer handler.Close()
//init client
client := gos7.NewClient(handler)
address := 2710
start := 8
size := 2
buffer := make([]byte, 255)
value := 100
//AGWriteDB to address DB2710 with value 100, start from position 8 with size = 2 (for an integer)
var helper gos7.Helper
helper.SetValueAt(buffer, 0, value)  
err := client.AGWriteDB(address, start, size, buffer)
buf := make([]byte, 255)
//AGReadDB to address DB2710, start from position 8 with size = 2
err := client.AGReadDB(address, start, size, buf)
var s7 gos7.Helper
var result uint16
s7.GetValueAt(buf, 0, &result)	 
  

References

Simatic, Simatic S5, Simatic S7, S7-200, S7-300, S7-400, S7-1200, S7-1500 are registered Trademarks of Siemens

License

https://opensource.org/licenses/BSD-3-Clause

Copyright (c) 2018, robinson

# Packages

No description provided by the author

# Functions

CPUError specific CPU error after response.
ErrorText return a string error text from error code integer.
NewClient creates a new s7 client with given backend handler.
NewClient2 creates a new s7 client with given backend packager and transporter.
NewProtocolDataUnit ProtocolDataUnit Constructor.
NewTCPClientHandler allocates a new TCPClientHandler.
TCPClient creator for a TCP client with address, rack and slot, implement from interface client.

# Structs

Helper the helper to get/set value from/to byte array with difference types.
ProtocolDataUnit (PDU) is independent of underlying communication layers.
S7BlockInfo Managed Block Info.
S7BlocksList Block List.
S7CpInfo cp info.
S7CpuInfo CPU Info.
S7DataItem which expose as S7DataItem to use in Multiple read/write.
S7Error implements error interface.
S7OrderCode Order Code + Version.
S7Protection See §33.19 of "System Software for S7-300/400 System and Standard Functions".
S7SZL constains header and data.
S7SZLList of available SZL IDs : same as SZL but List items are big-endian adjusted.
SZLHeader See §33.1 of "System Software for S7-300/400 System and Standard Functions" and see SFC51 description too.
TCPClientHandler implements Packager and Transporter interface.

# Interfaces

Client interface s7 client.
CliePDULengthntHandler is the interface that groups the Packager and Transporter methods.
Packager specifies the communication layer.
Transporter specifies the transport layer.