Skip to content

S7MultiVar

Federico Barresi edited this page Jan 11, 2019 · 1 revision

The class S7MultiVar allows to fill the S7DataItem[] and performs a ReadMultivar or WriteMultivar without using unsafe code.

The best way to understand the use of this class is analyzing an example.

The process is simple:

  1. Instantiate the class.

  2. Add the vars reference (i.e. your buffer) specifying the kind of element that we want read or write.

  3. Call Read or Write method.

Read example

// Multi Reader Instance specifying Client
S7MultiVar Reader = new S7MultiVar(Client); 

// Our buffers
byte[] DB_A = new byte[1024];
byte[] DB_B = new byte[1024];
byte[] DB_C = new byte[1024];

// Our DB number references
int DBNumber_A = 1; // DB1
int DBNumber_B = 1; // DB2
int DBNumber_C = 1; // DB3

// Add Items def. specifying 16 bytes to read starting from 0
Reader.Add(S7Consts.S7AreaDB, S7Consts.S7WLByte, DBNumber_A, 0, 16, ref DB_A);
Reader.Add(S7Consts.S7AreaDB, S7Consts.S7WLByte, DBNumber_B, 0, 16, ref DB_B);
Reader.Add(S7Consts.S7AreaDB, S7Consts.S7WLByte, DBNumber_C, 0, 16, ref DB_C); 

// Performs the Read
int Result = Reader.Read();

If everything is ok into DB_A, DB_B, DB_C we will find the first 16 bytes of DB1, DB2 and DB3.

Remarks

  1. Reader.Result[] will contain the single outcome of the items, it’s possible that some items were read and some other not.
  2. The parameters of Add() are the same of Read/WriteArea, you can read/write non only DB but also E/A/MK/T/C and also bits.