0

对于此功能:

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

如果我想使用这个 fc 来读取 DB,BlockType 的参数是什么?我试过:S7Consts.S7AreaDB, 132, 0x41, 65

4

1 回答 1

1

如果要读取任何数据块,可以使用DBRead方法。

首先配置您的设备和数据块:https ://github.com/fbarresi/Sharp7/blob/master/README.md

然后你可以像这样读取数据块:

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
}


于 2021-02-02T08:20:55.353 回答