1.安装 libplctag.net库
GitHub - libplctag/libplctag.NET: This is a .NET wrapper for libplctag.
2.PLC IP和tag
3.写入值
var myTag = new TagReal()
{
//Name is the full path to tag.
Name = "HMI_F26[0]",
//Gateway is the IP Address of the PLC or communication module.
Gateway = "192.168.1.11",
//Path is the location in the control plane of the CPU. Almost always "1,0".
Path = "1,0",
PlcType = PlcType.ControlLogix,
Protocol = Protocol.ab_eip,
Timeout = TimeSpan.FromSeconds(5)
};
// write the value to PLC
myTag.Write(float.Parse( tbWritePlC.Text));
4.读取值
var myTag = new TagReal()
{
//Name is the full path to tag.
Name = "HMI_F26[0]",
//Gateway is the IP Address of the PLC or communication module.
Gateway = "192.168.1.11",
//Path is the location in the control plane of the CPU. Almost always "1,0".
Path = "1,0",
PlcType = PlcType.ControlLogix,
Protocol = Protocol.ab_eip,
Timeout = TimeSpan.FromSeconds(5)
};
// Read the value from the PLC
float output = myTag.Read();
tbReadPlC.Text = output.ToString();
5.知道Tag类型和Tagname就可以顺利的读写值了