首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C#和西门子S7与Sharp7库的通信- GetAgBlockInfo参数?

C#和西门子S7与Sharp7库的通信- GetAgBlockInfo参数?
EN

Stack Overflow用户
提问于 2020-11-02 18:23:09
回答 1查看 221关注 0票数 0

对于此函数:

代码语言:javascript
复制
public int GetAgBlockInfo(int BlockType, int BlockNumber, ref S7BlockInfo Block);

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

EN

回答 1

Stack Overflow用户

发布于 2021-02-02 16:20:55

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

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

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

代码语言:javascript
复制
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
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64643693

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档