Categorygithub.com/shiyuecamus/gs7
repositorypackage
1.0.4
Repository: https://github.com/shiyuecamus/gs7.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# 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()
  
  
  if _, err := c.Connect().Wait(); err != nil {
    logger.Errorf("Failed to connect PLC, host: %s, port: %d, error: %s", host, port, err)
    return
  }
  defer c.Disconnect()
	
  // 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

abbreviationAreaDB NumberByte indexBit indexPLC Data typeGo Data TypeByteLengthPLC
DB1.X0.1/DB1.BIT0.1DB101Bitbool1/8S1200
QX1.6/QBIT1.6Q016Bitbool1/8S1200
QB1/QBYTE1Q010Byteuint81S1200
IX2.5/IBIT2.5I025Bitbool1/8S1200
IW2/IWORD2I020Worduint162S1200
MX3.2/MBIT3.2M032Bitbool1/8S1200
MI3/MINT3M030Intint162S1200
VX1.3/VBIT1.3V130Bitbool1/8200Smart
VI4/VINT4V140Intint162200Smart
T0T000Timertime.Duration2S1200
C2C020Counteruint162S1200
DB4.B4/DB4.BYTE4DB440Byteuint81S1200
DB4.C0/DB4.CHAR0DB400Charint81S1200
DB3.S2/DB3.STRING2DB320StringStringNS1200
DB1.I8/DB1.INT8DB180Intint162S1200
DB2.W12/DB1.WORD12DB2120Worduint162S1200
DB1.DI0/DB1.DINT0DB100DIntint324S1200
DB1.DW0/DB1.DWAORD0DB100DWorduint324S1200
DB3.R2/DB3.REAL2DB320Realfloat324S1200
DB1.T2/DB1.TIME2DB120Timetime.Duration4S1200
DB1.ST2/DB1.STIME2DB120S5Timetime.Duration2S1200
DB1.D2/DB1.DATE2DB120Datetime.Time2S1200
DB1.DT6/DB1.DATETIME6DB160DateTimetime.Time8S1200
DB1.DTL2/DB1.DATETIMELONG2DB120DateTimeLongtime.Time12S1200
DB1.TOD2/DB1.TIMEOFDAY2DB120TimeOfDaytime.Time4S1200

🌽 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:

NumberDependencyVersionLicenseDateCopyright
1gnet2.3.5Apache-2.02019-presentAndy Pan
2cast1.6.0MIT2014Steve Francia
3zap1.27.0MIT2016-2017Uber Technologies

Sponsor

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

wechat wechat