Added info about string support for struct and class. Fixed url for images.

Michal Štefaňák
2025-05-21 13:50:20 +02:00
parent 6374663275
commit 4857e79cff

13
Home.md

@@ -200,8 +200,6 @@ ushort result = (ushort)plc.Read("DB1.DBW0");
This method reads all the bytes from a specified DB needed to fill a struct in C#, and returns the struct that contains the values.
It is recommended to use when you want to read many variables in a single data block in some continuous memory range.
The "read struct" and "write struct" methods do not support strings.
```csharp
public object ReadStruct(Type structType, int db, int startByteAdr = 0)
@@ -214,7 +212,7 @@ public void WriteStruct(object structValue, int db, int startByteAdr = 0)
Example:
Define a DataBlock in the plc like:
![struct](https://github.com/killnine/s7netplus/blob/master/Documentation/struct.png)
![struct](https://github.com/killnine/s7netplus/blob/main/Documentation/struct.png)
Then add a struct into your .Net application that is similiar to the DB in the plc:
```csharp
@@ -242,13 +240,13 @@ then add the code to read or write the complete struct
// reads a struct from DataBlock 1 at StartAddress 0
testStruct myTestStruct = (testStruct) plc.ReadStruct(typeof(testStruct), 1, 0);
```
String support is secured with adding attribute S7StringAttribute to your struct property.
## Read a class / Write a class
This method reads all the bytes from a specified DB needed to fill a class in C#. The class is passed as reference and values are assigned by using reflection.
It is recommended to use when you want to read many variables in a single data block in some continuous memory range.
The "read class" and "write class" methods do not support strings.
```csharp
public void ReadClass(object sourceClass, int db, int startByteAdr = 0)
@@ -260,7 +258,7 @@ public void WriteClass(object classValue, int db, int startByteAdr = 0)
Example:
Define a DataBlock in the plc like:
![struct](https://github.com/killnine/s7netplus/blob/master/Documentation/struct.png)
![struct](https://github.com/killnine/s7netplus/blob/main/Documentation/struct.png)
Then add a struct into your .Net application that is similiar to the DB in the plc:
```csharp
@@ -293,6 +291,9 @@ then add the code to read or write the complete class
TestClass myTestClass = new TestClass();
plc.ReadClass(myTestClass, 1, 0);
```
String support is secured with adding attribute S7StringAttribute to your class property.
## Read multiple variables
This method reads multiple variables in a single request. The variables can be located in the same or in different data blocks.