C# 读写ABPLC( Allen Bradley)

1.安装 libplctag.net库

C# 读写ABPLC( Allen Bradley)_第1张图片

GitHub - libplctag/libplctag.NET: This is a .NET wrapper for libplctag.

 

2.PLC IP和tag

C# 读写ABPLC( Allen Bradley)_第2张图片 

 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就可以顺利的读写值了

你可能感兴趣的:(c#,java,c++)