Sandor.Oros
Sandor.Oros

Reputation: 63

C# & Siemens S7 communication with Sharp7 library - GetAgBlockInfo parameters?

For this function:

public int GetAgBlockInfo(int BlockType, int BlockNumber, ref S7BlockInfo Block);

What is the parameter for BlockType if I would like to use this fc to read DB? I've tried: S7Consts.S7AreaDB, 132, 0x41, 65

Upvotes: 0

Views: 1444

Answers (1)

Tolga Cakir
Tolga Cakir

Reputation: 755

You can use DBRead method if you want to read any Data Block.

Firstly configure your device and data block: https://github.com/fbarresi/Sharp7/blob/master/README.md

Then you can read data block like this:

var _s7Client = new S7Client();
int connectionResult = _s7Client.ConnectTo("192.168.0.1",0,1);//write your PLC IP address
if(connectionResult == 0)
{
    var buffer = new byte[6];
    int readResult = _s7Client.DBRead(1, 0, buffer.Length, buffer); //parameters: dbNumber, startingAddress, readLength, buffer

    if(readResult == 0)
    {
        byte x = S7.GetByteAt(buffer,0); //parameters: buffer, position
        string y = S7.GetCharsAt(buffer, 2, 4); //parameters: buffer, position, length(byte)
    }
    else
    {
        //read error
    }
}
else
{
    //connection error
}


Upvotes: 0

Related Questions