After a lot of searches and reading documents, I found out Siemens still developing the MSSql Server Module, and now, it isn't completed.
The data will be inside the Receivebuffer: InstLsql_Microsoft.statRcvData.bytes[]
. But you have to search for your information.
But still, the best way to read and write on PLC Registers is using S7netplus
library (A .NET Library for Siemens S7 Connectivity).
S7.Net Plus is a continuation of the work done on the S7.Net project by Juergen1969. I found the library simple and effective, but the project has languished unchanged since late 2009.
Download and install on C# Project:
PM> Install-Package S7netplus -Version 0.4.0
To create an instance of the driver you need to use this constructor:
public Plc(CpuType cpu, string ip, Int16 rack, Int16 slot)
Example:
This code creates a Plc object for a S7-300 plc at the IP address 127.0.0.1, for a plc in rack 0 with the cpu in slot 2:
Plc plc = new Plc(CpuType.S7300, "127.0.0.1", 0, 2);
Connecting to the PLC
public void Open()
For example this line of code open the connection:
plc.Open();
Disconnecting from the PLC
public void Close()
For example this closes the connection:
plc.Close();
Read bytes / Write bytes
The library offers several methods to read variables. The basic one and the most used is ReadBytes.
public byte[] ReadBytes(DataType dataType, int db, int startByteAdr, int count)
public void WriteBytes(DataType dataType, int db, int startByteAdr, byte[] value)
This reads all the bytes you specify from a given memory location. This method handles multiple requests automatically in case the number of bytes exceeds the maximum bytes that can be transferred in a single request.
dataType: you have to specify the memory location with the enum DataType
public enum DataType
{
Input = 129,
Output = 130,
Memory = 131,
DataBlock = 132,
Timer = 29,
Counter = 28
}
db: the address of the dataType, for example, if you want to read DB1, this field is “1”; if you want to read T45, this field is 45.
startByteAdr: the address of the first byte that you want to read, for example, if you want to read DB1.DBW200, this is 200.
count: contains how many bytes you want to read.
Value[]: array of bytes to be written to the plc.
Example: This method reads the first 200 bytes of DB1:
var bytes = plc.ReadBytes(DataType.DataBlock, 1, 0, 200);
More Documention is here:
S7.Net documentation