1、S7地址示例
C#数据类型 | S7数据类型 | 位数 | 地址示例 |
---|---|---|---|
bool | Bool | 1位 | I0.1 Q1.0 M10.1 DB20.DBX2.1 |
byte | Byte/USInt | 8位 | IB2 MB10 DB1.DBB2 |
sbyte | SInt | 8位 | IB2 MB10 DB1.DBB2 |
ushort | Word/UInt | 16位 | MW10 DB1.DBW2 |
short | Int | 16位 | MW10 DB1.DBW2 |
uint | DWord/UDInt | 32位 | MD10 DB1.DBD2 |
int | DInt | 32位 | MD10 DB1.DBD2 |
float | Real | 32位 | MD10 DB1.DBD2 |
2、C# 使用 S7.NET 示例代码
using S7.Net;
Plc plc = new Plc(CpuType.S71500, "192.168.0.1", 0, 1); // IP, Rack, Slot
plc.Open();
// 读写示例
bool bit = (bool)plc.Read("DB1.DBX0.0");
plc.Write("M1.2", true);
byte b = (byte)plc.Read("DB1.DBB5");
plc.Write("DB1.DBB6", (byte)100);
short intValue = (short)plc.Read("DB1.DBW10");
plc.Write("DB1.DBW12", (short)-300);
float realValue = (float)plc.Read("DB1.DBD20");
plc.Write("DB1.DBD24", 3.14159f);
string str = (string)plc.Read("DB1.DBB30", VarType.String, 20);
plc.Close();
3、注意事项
数据对齐:WORD 从偶数字节开始,DINT 从能被 2 整除的地址开始。
本文著作权归作者 [ mydawn ] 享有,未经作者书面授权,禁止转载,封面图片来源于 [ 互联网 ] ,本文仅供个人学习、研究和欣赏使用。如有异议,请联系博主及时处理。