https://github.com/mycroes/sally7
C# implementation of Siemens S7 connections with a focus on performance
https://github.com/mycroes/sally7
csharp-library s7-protocol
Last synced: 11 months ago
JSON representation
C# implementation of Siemens S7 connections with a focus on performance
- Host: GitHub
- URL: https://github.com/mycroes/sally7
- Owner: mycroes
- License: mit
- Created: 2018-06-08T18:51:52.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2025-01-27T22:19:27.000Z (about 1 year ago)
- Last Synced: 2025-04-04T07:04:07.989Z (11 months ago)
- Topics: csharp-library, s7-protocol
- Language: C#
- Size: 321 KB
- Stars: 62
- Watchers: 9
- Forks: 23
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Sally7
C# implementation of Siemens S7 connections with a focus on performance

[](https://github.com/mycroes/Sally7/actions/workflows/dotnet.yml)
[](https://www.nuget.org/packages/Sally7)
## What is the S7 protocol?
The **S7** protocol is a proprietary protocol for PLC communication with and between Siemens S7 PLC's.
It's making use of **COTP** (*Connection Oriented Transport Protocol*, ISO 8073 / [RFC 905](https://tools.ietf.org/html/rfc905))
and **TPKT** (*ISO Transport Service on top of the TCP Version 3*, [RFC 1006](https://tools.ietf.org/html/rfc1006)).
The S7 protocol uses **ConnectionRequest** (CC) and **ConnectionConfirm** (CR)
from COTP for connection management and COTP **DataTransfer** (DT) to wrap S7 protocol functions.
A good description is available at [The Siemens S7 Communication - Part 1 General Structure](http://gmiru.com/article/s7comm/)
and [The Siemens S7 Communication - Part 2 Job Requests and Ack Data](http://gmiru.com/article/s7comm-part2/).
## The implementation of Sally7
Sally7 supports the most basic read and write actions to the **DataBlock** area.
All protocols are mapped to `struct`s and `enum`s with the intent to create a project that is easy to comprehend and extend.
## How to get started
### Connect to a PLC
Connect to a S7-1500 PLC at adress 192.168.0.15 on Rack 0, Slot 1
```
var connection = Sally7.Plc.ConnectionFactory.GetConnection(host: "192.168.0.15", cpuType: Sally7.Plc.CpuType.S7_1500, rack: 0, slot: 1);
await connection.OpenAsync();
```
### Read a DataBlockDataItem
Read 10 bytes from DataBlock 87 starting at address 54
```
var dataItem = new DataBlockDataItem
{
DbNumber = 87,
Length = 10,
StartByte = 54
};
await connection.ReadAsync(dataItem);
Console.WriteLine($"Read data: {BitConverter.ToString(dataItem.Value)}");
```