• 大小: 50.42MB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2022-08-25
  • 语言: C#
  • 标签: CSharp  OPC  

资源简介

OPC数据共享,可用于通讯,C#源代码实现,加快通讯模块的开发

资源截图

代码片段和文件信息

using System;
using System.Windows.Forms;
using Opc;
using Opc.Da;
using OpcCom;
namespace opcTest
{
    public partial class Form1 : Form
    {
        private Opc.Da.Server m_server = null;//定义数据存取服务器
        private Opc.Da.Subscription subscription = null;//定义组对象(订阅者)
        private Opc.Da.SubscriptionState state = null;//定义组(订阅者)状态,相当于OPC规范中组的参数
        private Opc.IDiscovery m_discovery = new ServerEnumerator();//定义枚举基于COM服务器的接口,用来搜索所有的此类服务器。

        public Form1()
        {
            InitializeComponent();
            textBox1.Text = “192.168.1.5“;
            button2.Enabled = false;
            button3.Enabled = false;
        }

        private void button1_Click(object sender EventArgs e)
        {
            //查询服务器
            try
            {
                Opc.Server[] servers = m_discovery.GetAvailableServers(Specification.COM_DA_20 textBox1.Text null);
                if (servers != null)
                {
                    foreach (Opc.Da.Server server in servers)
                    {
                        comboBox1.Items.Add(server.Name);
                    }
                }
                comboBox1.SelectedIndex = 0;
                listBox1.Items.Add(“查询服务器成功.请选择OPC进行连接“);

                button1.Enabled = false;
                button2.Enabled = true;
            }
            catch (Exception ex)
            {

                listBox1.Items.Add(ex.Message);
            }


        }


        private void button2_Click(object sender EventArgs e)
        {
            //连接
            if (button2.Text==“释放“)
            {
                //结束:释放各资源
                button2.Text = “连接“;
                listBox1.Items.Add(“释放成功.不能进行读取数据请重新连接“);
                button3.Enabled = false;
                try
                {
                    subscription.Dispose();//强制.NET资源回收站回收该subscription的所有资源。         
                    m_server.Disconnect();//断开服务器连接
                }
                catch (Exception ex)
                {
                    listBox1.Items.Add(ex.Message);
                }
            }
            else
            {
                try
                {
                    Opc.Server[] servers = m_discovery.GetAvailableServers(Specification.COM_DA_20 textBox1.Text null);
                    if (servers != null)
                    {
                        foreach (Opc.Da.Server server in servers)
                        {
                            if (String.Compare(server.Name comboBox1.Text true) == 0)//为true忽略大小写
                            {
                                m_server = server;//建立连接。
                                break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {

                    listBox1.Items.Add(ex.Message);
                    return;
              

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       6294  2013-05-10 12:13  bank_pepole\Backup\OPC_Client\Form1.cs

     文件      10059  2013-05-10 12:13  bank_pepole\Backup\OPC_Client\Form1.Designer.cs

     文件       5814  2013-05-10 12:13  bank_pepole\Backup\OPC_Client\Form1.resx

     文件       5975  2013-05-10 13:33  bank_pepole\Backup\OPC_Client\OPC_Client.csproj

     文件        564  2013-05-10 13:33  bank_pepole\Backup\OPC_Client\OPC_Client.csproj.user

     文件        468  2012-12-12 14:43  bank_pepole\Backup\OPC_Client\Program.cs

     文件       1383  2013-05-10 12:09  bank_pepole\Backup\OPC_Client\Properties\AssemblyInfo.cs

     文件       2864  2012-12-12 14:43  bank_pepole\Backup\OPC_Client\Properties\Resources.Designer.cs

     文件       5612  2012-12-12 14:43  bank_pepole\Backup\OPC_Client\Properties\Resources.resx

     文件       1092  2012-12-12 14:43  bank_pepole\Backup\OPC_Client\Properties\Settings.Designer.cs

     文件        249  2012-12-12 14:43  bank_pepole\Backup\OPC_Client\Properties\Settings.settings

     文件        920  2013-05-10 12:14  bank_pepole\Backup\OPC_Client.sln

    ..A..H.     13824  2013-05-14 15:27  bank_pepole\Backup\OPC_Client.v11.suo

     文件   50449456  2014-11-10 15:29  bank_pepole\document\dotNetFx40_Full_x86_x64.exe

     文件     899584  2015-11-19 22:40  bank_pepole\document\OPC Core Components 2.00 SDK 2.30.msi

     文件    1278001  2015-11-05 15:19  bank_pepole\document\Win7系统下的OPC运行配置.pdf

     文件       4608  2016-01-05 16:32  bank_pepole\OpcEnumLib.dll

     文件     200704  2005-11-25 17:07  bank_pepole\OpcNetApi.Com.dll

     文件     225280  2005-11-25 17:07  bank_pepole\OpcNetApi.dll

     文件       9216  2008-07-09 16:50  bank_pepole\OpcRcw.Cmd.dll

     文件       6656  2008-07-09 16:50  bank_pepole\OpcRcw.Comn.dll

     文件      20992  2008-07-09 16:50  bank_pepole\OpcRcw.Da.dll

     文件      15872  2008-07-09 16:50  bank_pepole\OpcRcw.Dx.dll

     文件      12800  2008-07-09 16:50  bank_pepole\OpcRcw.Hda.dll

     文件        474  2016-06-23 14:56  bank_pepole\OPC_Client\app.config

     文件        474  2016-06-23 14:56  bank_pepole\OPC_Client\bin\Debug\app.config

     文件          0  2015-11-29 08:56  bank_pepole\OPC_Client\bin\Debug\log\log.txt

     文件      26773  2015-12-04 09:47  bank_pepole\OPC_Client\bin\Debug\log\log_2015-12-04.txt

     文件      12006  2015-12-08 16:25  bank_pepole\OPC_Client\bin\Debug\log\log_2015-12-08.txt

     文件       4624  2015-12-09 12:36  bank_pepole\OPC_Client\bin\Debug\log\log_2015-12-09.txt

............此处省略106个文件信息

评论

共有 条评论