c# - C# & Siemens S7 与 Sharp7 库的通信 - GetAgBlockInfo 参数?
问题描述
对于此功能:
public int GetAgBlockInfo(int BlockType, int BlockNumber, ref S7BlockInfo Block);
如果我想使用这个 fc 来读取 DB,BlockType 的参数是什么?我试过:S7Consts.S7AreaDB, 132, 0x41, 65
解决方案
如果要读取任何数据块,可以使用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
}
推荐阅读
- matlab - 使用 Hamming/Hanning 滤波器平滑二进制掩码
- visual-studio - 发布后asp.net core 2.0中缺少views文件夹
- android - 如何检测用户正在使用语音转文本?
- java - Spring-boot 应用程序不会在主上下文 bean 初始化中关闭子管理上下文
- python - 有没有办法从python中的不同列表中提取相应的项目?
- nginx - Nginx代理高IO读取
- php - 自定义 HTTP 服务器 - 在我的网站中提供状态机制
- java - OpenGL绘制纹理错误
- reactjs - 使用 Jest 和 Enzyme 测试 React 代码时如何处理 DOM 请求?
- r - 如何将数字的多个变量更改为r中的因子?