• 大小: 4.3MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-02
  • 语言: C#
  • 标签: 111  

资源简介

本人已经验证,与PLC1500通讯成功,可以读写PLC参数,

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpcUaHelper;
namespace WindowsFormsApp1

    public partial class Form1 : Form
    {  private OpcUaClient opcUaClient = new OpcUaClient();//实例化一个客户端对象
        UInt16 data_send; Boolean data_send1;
        public Form1()
        {
            InitializeComponent();
        }


      
        private void Form1_Load(object sender EventArgs e)
        {
              opcUaClient.ConnectServer(“opc.tcp://192.168.0.1:4840“);//连接一个服务器
            //opcUaClient.Disconnect();//关闭服务器连接
            //opcUaClient.UserIdentity = new Opc.Ua.UserIdentity(“admin“ “123456“);//服务器的需要密码时

           
        }
        /// 
        /// 读取节点代码如下
        /// 

        /// 
        /// 
        private void button1_Click(object sender EventArgs e)
        {
            try
            {
                UInt16 value = opcUaClient.ReadNode(“ns=3;s=\“数据块_1\“.\“ac\““);
                
                //  bool a = opcUaClient.ReadNode(“ns=3;s=PLC_1/Memory/Tag_1“);
                //textBox1.Text = “nihao“;
                //MessageBox.Show(); // 显示测试数据To;
                 textBox1.Text = Convert.ToString(value).ToUpper();
               // textBox1.Text = opcUaClient.ReadNode(“ns=3;s=Tag_1“);
            }
           catch (Exception ex)
            {
               // 使用了opc ua的错误处理机制来处理错误,网络不通或是读取拒绝
                Opc.Ua.Client.Controls.ClientUtils.HandleException(Text ex);
            }
        }

        private void button2_Click(object sender EventArgs e)
        {
            try
            {

                data_send = Convert.ToUInt16( textBox2.Text10);
               
                bool IsSuccess = opcUaClient.WriteNode(“ns=3;s=\“数据块_1\“.\“ac\““ data_send);
                MessageBox.Show(IsSuccess.ToString()); // 显示True,如果成功的话
            }
            catch (Exception ex)
            {
                // 使用了opc ua的错误处理机制来处理错误,网络不通或是读取拒绝
                Opc.Ua.Client.Controls.ClientUtils.HandleException(Text ex);
            }
        }

        private void label3_Click(object sender EventArgs e)
        {

        }

        private void button4_Click(object sender EventArgs e)
        {
            try
            {
                bool value1 = opcUaClient.ReadNode(“ns=3;s=\“Tag_3\““);

               
                textBox4.Text = Convert.ToString(value1).ToUpper();
               
            }
            catch (Exception ex)
            {
                // 使用了opc ua的错误处理机制来处理错误,网络不通或是读取拒绝
                Opc.Ua.Client.Controls.ClientUtils.HandleException(Text ex);
            }
        }

        private void button3_Click(objec

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-10-05 15:11  OPC_success2版\
     目录           0  2018-10-05 15:11  OPC_success2版\WindowsFormsApp1\
     目录           0  2018-10-05 15:11  OPC_success2版\WindowsFormsApp1\.vs\
     目录           0  2018-10-05 15:11  OPC_success2版\WindowsFormsApp1\.vs\WindowsFormsApp1\
     目录           0  2018-10-05 15:11  OPC_success2版\WindowsFormsApp1\.vs\WindowsFormsApp1\DesignTimeBuild\
     文件         218  2018-06-27 14:10  OPC_success2版\WindowsFormsApp1\.vs\WindowsFormsApp1\DesignTimeBuild\.dtbcache
     目录           0  2018-10-05 15:11  OPC_success2版\WindowsFormsApp1\.vs\WindowsFormsApp1\v15\
     文件       57344  2018-06-27 14:10  OPC_success2版\WindowsFormsApp1\.vs\WindowsFormsApp1\v15\.suo
     目录           0  2018-10-05 15:11  OPC_success2版\WindowsFormsApp1\.vs\WindowsFormsApp1\v15\Server\
     目录           0  2018-10-05 15:11  OPC_success2版\WindowsFormsApp1\.vs\WindowsFormsApp1\v15\Server\sqlite3\
     文件           0  2018-06-13 16:11  OPC_success2版\WindowsFormsApp1\.vs\WindowsFormsApp1\v15\Server\sqlite3\db.lock
     文件     1175552  2018-06-27 14:08  OPC_success2版\WindowsFormsApp1\.vs\WindowsFormsApp1\v15\Server\sqlite3\storage.ide
     文件       32768  2018-06-27 14:08  OPC_success2版\WindowsFormsApp1\.vs\WindowsFormsApp1\v15\Server\sqlite3\storage.ide-shm
     文件     4185952  2018-06-27 14:08  OPC_success2版\WindowsFormsApp1\.vs\WindowsFormsApp1\v15\Server\sqlite3\storage.ide-wal
     目录           0  2018-10-05 15:11  OPC_success2版\WindowsFormsApp1\packages\
     目录           0  2018-10-05 15:11  OPC_success2版\WindowsFormsApp1\packages\OpcUaHelper.1.0.2\
     目录           0  2018-10-05 15:11  OPC_success2版\WindowsFormsApp1\packages\OpcUaHelper.1.0.2\lib\
     文件      116736  2018-02-04 19:40  OPC_success2版\WindowsFormsApp1\packages\OpcUaHelper.1.0.2\lib\Opc.Ua.Client.dll
     文件      583168  2018-02-04 19:40  OPC_success2版\WindowsFormsApp1\packages\OpcUaHelper.1.0.2\lib\Opc.Ua.ClientControls.dll
     文件      121344  2018-02-04 19:40  OPC_success2版\WindowsFormsApp1\packages\OpcUaHelper.1.0.2\lib\Opc.Ua.Configuration.dll
     文件     3962880  2018-02-04 19:40  OPC_success2版\WindowsFormsApp1\packages\OpcUaHelper.1.0.2\lib\Opc.Ua.Core.dll
     文件      175616  2018-02-04 19:40  OPC_success2版\WindowsFormsApp1\packages\OpcUaHelper.1.0.2\lib\OpcUaHelper.dll
     文件       34286  2018-02-04 19:40  OPC_success2版\WindowsFormsApp1\packages\OpcUaHelper.1.0.2\lib\OpcUaHelper.xml
     文件     1319726  2018-06-13 16:20  OPC_success2版\WindowsFormsApp1\packages\OpcUaHelper.1.0.2\OpcUaHelper.1.0.2.nupkg
     目录           0  2018-10-05 15:11  OPC_success2版\WindowsFormsApp1\WindowsFormsApp1\
     文件        1147  2018-06-13 16:11  OPC_success2版\WindowsFormsApp1\WindowsFormsApp1.sln
     文件         189  2018-06-13 16:10  OPC_success2版\WindowsFormsApp1\WindowsFormsApp1\App.config
     目录           0  2018-10-05 15:11  OPC_success2版\WindowsFormsApp1\WindowsFormsApp1\bin\
     目录           0  2018-10-05 15:11  OPC_success2版\WindowsFormsApp1\WindowsFormsApp1\bin\Debug\
     文件      116736  2018-02-04 19:40  OPC_success2版\WindowsFormsApp1\WindowsFormsApp1\bin\Debug\Opc.Ua.Client.dll
     文件      583168  2018-02-04 19:40  OPC_success2版\WindowsFormsApp1\WindowsFormsApp1\bin\Debug\Opc.Ua.ClientControls.dll
............此处省略36个文件信息

评论

共有 条评论