mirror of
https://github.com/S7NetPlus/s7netplus.git
synced 2025-12-17 17:06:50 +08:00
Updated Home (markdown)
16
Home.md
16
Home.md
@@ -301,8 +301,8 @@ public void Plc.ReadMultibleVars(List<DataItem> dataItems);
|
|||||||
|
|
||||||
Example: this method reads several variables from a data block
|
Example: this method reads several variables from a data block
|
||||||
|
|
||||||
|
define the data items first
|
||||||
```csharp
|
```csharp
|
||||||
// define the data items first
|
|
||||||
private static DataItem varBit = new DataItem()
|
private static DataItem varBit = new DataItem()
|
||||||
{
|
{
|
||||||
DataType = DataType.DataBlock,
|
DataType = DataType.DataBlock,
|
||||||
@@ -368,19 +368,23 @@ private static DataItem varDateTime = new DataItem()
|
|||||||
StartByteAdr = 138,
|
StartByteAdr = 138,
|
||||||
Value = new object()
|
Value = new object()
|
||||||
};
|
};
|
||||||
|
```
|
||||||
// define a list where the DataItems will be stored in
|
Then define a list where the DataItems will be stored in
|
||||||
|
```csharp
|
||||||
private static List<DataItem> dataItemsRead = new List<DataItem>();
|
private static List<DataItem> dataItemsRead = new List<DataItem>();
|
||||||
|
```
|
||||||
// add the DataItems to the list
|
add the data items to the list
|
||||||
|
```csharp
|
||||||
dataItemsRead.Add(varBit);
|
dataItemsRead.Add(varBit);
|
||||||
dataItemsRead.Add(varByteArray);
|
dataItemsRead.Add(varByteArray);
|
||||||
dataItemsRead.Add(varInt);
|
dataItemsRead.Add(varInt);
|
||||||
dataItemsRead.Add(varReal);
|
dataItemsRead.Add(varReal);
|
||||||
dataItemsRead.Add(varString);
|
dataItemsRead.Add(varString);
|
||||||
dataItemsRead.Add(varDateTime);
|
dataItemsRead.Add(varDateTime);
|
||||||
|
```
|
||||||
|
|
||||||
// open the connection to the plc
|
open the connection to the plc and read the items at once
|
||||||
|
```csharp
|
||||||
myPLC.Open();
|
myPLC.Open();
|
||||||
|
|
||||||
// read the list of variables
|
// read the list of variables
|
||||||
|
|||||||
Reference in New Issue
Block a user