mirror of
https://github.com/S7NetPlus/s7netplus.git
synced 2025-12-18 17:36:49 +08:00
Added info about string support for struct and class. Fixed url for images.
13
Home.md
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:
|
||||
|
||||

|
||||

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

|
||||

|
||||
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user