⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opcgroupreadform.cs

📁 利用OpcNet控件(包含源码)进行OPC通讯的开发样例
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;

using HaiGrang.Package.OpcNetApiChs.Opc;
using HaiGrang.Package.OpcNetApiChs.Da;
using HaiGrang.Package.OpcNetApiChs.DaNet;

namespace OpcGroupReadSample
{
	/// <summary>
	/// OpcGroupReadSample 的摘要说明。
	/// </summary>

	public class OpcGroupReadForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label OpcItemLength;
		private System.Windows.Forms.TextBox textWriteOpcItem;
		private System.Windows.Forms.Label OpcItemWriteValue;
		private System.Windows.Forms.Button WriteOpcItem;
		private System.Windows.Forms.Button ReadOpcItem;
		private System.Windows.Forms.Label OpcItemValue5;
		private System.Windows.Forms.Label OpcItemValue4;
		private System.Windows.Forms.Label OpcItemValue3;
		private System.Windows.Forms.Label OpcItemValue2;
		private System.Windows.Forms.Label OpcItemValue1;
		private System.Windows.Forms.Label OpcRemoveItemName;
		private System.Windows.Forms.Button RemoveOpcItem;
		private System.Windows.Forms.Label OpcItemName;
		private System.Windows.Forms.Button AddOpcItem;
		private System.Windows.Forms.Label OpcRemoveGroupName;
		private System.Windows.Forms.Button RemoveOpcGroup;
		private System.Windows.Forms.Label OpcGroupName;
		private System.Windows.Forms.Button AddOpcGroup;
		private System.Windows.Forms.Button OpcServerDisConnect;
		private System.Windows.Forms.Label OpcServerRemove;
		private System.Windows.Forms.Label bOpcServerName;
		private System.Windows.Forms.Button bOpcServerConnect;

		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		
		private System.ComponentModel.Container components = null;

		public OpcGroupReadForm()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>

		protected override void Dispose( bool disposing )
		{
			if(tOpcServer != null)
			{
				tOpcServer.Disconnect() ;
			}
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.OpcItemLength = new System.Windows.Forms.Label();
			this.textWriteOpcItem = new System.Windows.Forms.TextBox();
			this.OpcItemWriteValue = new System.Windows.Forms.Label();
			this.WriteOpcItem = new System.Windows.Forms.Button();
			this.ReadOpcItem = new System.Windows.Forms.Button();
			this.OpcItemValue5 = new System.Windows.Forms.Label();
			this.OpcItemValue4 = new System.Windows.Forms.Label();
			this.OpcItemValue3 = new System.Windows.Forms.Label();
			this.OpcItemValue2 = new System.Windows.Forms.Label();
			this.OpcItemValue1 = new System.Windows.Forms.Label();
			this.OpcRemoveItemName = new System.Windows.Forms.Label();
			this.RemoveOpcItem = new System.Windows.Forms.Button();
			this.OpcItemName = new System.Windows.Forms.Label();
			this.AddOpcItem = new System.Windows.Forms.Button();
			this.OpcRemoveGroupName = new System.Windows.Forms.Label();
			this.RemoveOpcGroup = new System.Windows.Forms.Button();
			this.OpcGroupName = new System.Windows.Forms.Label();
			this.AddOpcGroup = new System.Windows.Forms.Button();
			this.OpcServerDisConnect = new System.Windows.Forms.Button();
			this.OpcServerRemove = new System.Windows.Forms.Label();
			this.bOpcServerName = new System.Windows.Forms.Label();
			this.bOpcServerConnect = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// OpcItemLength
			// 
			this.OpcItemLength.BackColor = System.Drawing.Color.Yellow;
			this.OpcItemLength.Location = new System.Drawing.Point(540, 56);
			this.OpcItemLength.Name = "OpcItemLength";
			this.OpcItemLength.Size = new System.Drawing.Size(216, 32);
			this.OpcItemLength.TabIndex = 132;
			this.OpcItemLength.Text = "Opc Item Length";
			this.OpcItemLength.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// textWriteOpcItem
			// 
			this.textWriteOpcItem.Location = new System.Drawing.Point(772, 56);
			this.textWriteOpcItem.Name = "textWriteOpcItem";
			this.textWriteOpcItem.Size = new System.Drawing.Size(216, 21);
			this.textWriteOpcItem.TabIndex = 131;
			this.textWriteOpcItem.Text = "0";
			this.textWriteOpcItem.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// OpcItemWriteValue
			// 
			this.OpcItemWriteValue.BackColor = System.Drawing.Color.Yellow;
			this.OpcItemWriteValue.Location = new System.Drawing.Point(772, 184);
			this.OpcItemWriteValue.Name = "OpcItemWriteValue";
			this.OpcItemWriteValue.Size = new System.Drawing.Size(216, 32);
			this.OpcItemWriteValue.TabIndex = 130;
			this.OpcItemWriteValue.Text = "Opc Item Write Value";
			this.OpcItemWriteValue.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// WriteOpcItem
			// 
			this.WriteOpcItem.Location = new System.Drawing.Point(772, 120);
			this.WriteOpcItem.Name = "WriteOpcItem";
			this.WriteOpcItem.Size = new System.Drawing.Size(216, 32);
			this.WriteOpcItem.TabIndex = 129;
			this.WriteOpcItem.Text = "Write Opc Item";
			this.WriteOpcItem.Click += new System.EventHandler(this.WriteOpcItem_Click);
			// 
			// ReadOpcItem
			// 
			this.ReadOpcItem.Location = new System.Drawing.Point(540, 440);
			this.ReadOpcItem.Name = "ReadOpcItem";
			this.ReadOpcItem.Size = new System.Drawing.Size(216, 32);
			this.ReadOpcItem.TabIndex = 128;
			this.ReadOpcItem.Text = "Read Opc Item";
			this.ReadOpcItem.Click += new System.EventHandler(this.ReadOpcItem_Click);
			// 
			// OpcItemValue5
			// 
			this.OpcItemValue5.BackColor = System.Drawing.Color.Yellow;
			this.OpcItemValue5.Location = new System.Drawing.Point(540, 376);
			this.OpcItemValue5.Name = "OpcItemValue5";
			this.OpcItemValue5.Size = new System.Drawing.Size(216, 32);
			this.OpcItemValue5.TabIndex = 127;
			this.OpcItemValue5.Text = "Opc Item Value";
			this.OpcItemValue5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// OpcItemValue4
			// 
			this.OpcItemValue4.BackColor = System.Drawing.Color.Yellow;
			this.OpcItemValue4.Location = new System.Drawing.Point(540, 312);
			this.OpcItemValue4.Name = "OpcItemValue4";
			this.OpcItemValue4.Size = new System.Drawing.Size(216, 32);
			this.OpcItemValue4.TabIndex = 126;
			this.OpcItemValue4.Text = "Opc Item Value";
			this.OpcItemValue4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// OpcItemValue3
			// 
			this.OpcItemValue3.BackColor = System.Drawing.Color.Yellow;
			this.OpcItemValue3.Location = new System.Drawing.Point(540, 248);
			this.OpcItemValue3.Name = "OpcItemValue3";
			this.OpcItemValue3.Size = new System.Drawing.Size(216, 32);
			this.OpcItemValue3.TabIndex = 125;
			this.OpcItemValue3.Text = "Opc Item Value";
			this.OpcItemValue3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// OpcItemValue2
			// 
			this.OpcItemValue2.BackColor = System.Drawing.Color.Yellow;
			this.OpcItemValue2.Location = new System.Drawing.Point(540, 184);
			this.OpcItemValue2.Name = "OpcItemValue2";
			this.OpcItemValue2.Size = new System.Drawing.Size(216, 32);
			this.OpcItemValue2.TabIndex = 124;
			this.OpcItemValue2.Text = "Opc Item Value";
			this.OpcItemValue2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// OpcItemValue1
			// 
			this.OpcItemValue1.BackColor = System.Drawing.Color.Yellow;
			this.OpcItemValue1.Location = new System.Drawing.Point(540, 120);
			this.OpcItemValue1.Name = "OpcItemValue1";
			this.OpcItemValue1.Size = new System.Drawing.Size(216, 32);
			this.OpcItemValue1.TabIndex = 123;
			this.OpcItemValue1.Text = "Opc Item Value";
			this.OpcItemValue1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// OpcRemoveItemName
			// 
			this.OpcRemoveItemName.BackColor = System.Drawing.Color.Yellow;
			this.OpcRemoveItemName.Location = new System.Drawing.Point(28, 248);
			this.OpcRemoveItemName.Name = "OpcRemoveItemName";
			this.OpcRemoveItemName.Size = new System.Drawing.Size(216, 32);
			this.OpcRemoveItemName.TabIndex = 122;
			this.OpcRemoveItemName.Text = "Opc Remove Item Name";
			this.OpcRemoveItemName.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// RemoveOpcItem
			// 
			this.RemoveOpcItem.Location = new System.Drawing.Point(260, 248);
			this.RemoveOpcItem.Name = "RemoveOpcItem";
			this.RemoveOpcItem.Size = new System.Drawing.Size(216, 32);
			this.RemoveOpcItem.TabIndex = 121;
			this.RemoveOpcItem.Text = "Remove Opc Item";
			this.RemoveOpcItem.Click += new System.EventHandler(this.RemoveOpcItem_Click);
			// 
			// OpcItemName
			// 
			this.OpcItemName.BackColor = System.Drawing.Color.Yellow;
			this.OpcItemName.Location = new System.Drawing.Point(28, 184);
			this.OpcItemName.Name = "OpcItemName";
			this.OpcItemName.Size = new System.Drawing.Size(216, 32);
			this.OpcItemName.TabIndex = 120;
			this.OpcItemName.Text = "Opc Item Name";
			this.OpcItemName.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// AddOpcItem
			// 
			this.AddOpcItem.Location = new System.Drawing.Point(260, 184);
			this.AddOpcItem.Name = "AddOpcItem";
			this.AddOpcItem.Size = new System.Drawing.Size(216, 32);
			this.AddOpcItem.TabIndex = 119;
			this.AddOpcItem.Text = "Add Opc Item";
			this.AddOpcItem.Click += new System.EventHandler(this.AddOpcItem_Click);
			// 
			// OpcRemoveGroupName
			// 
			this.OpcRemoveGroupName.BackColor = System.Drawing.Color.Yellow;
			this.OpcRemoveGroupName.Location = new System.Drawing.Point(28, 312);
			this.OpcRemoveGroupName.Name = "OpcRemoveGroupName";
			this.OpcRemoveGroupName.Size = new System.Drawing.Size(216, 32);
			this.OpcRemoveGroupName.TabIndex = 118;
			this.OpcRemoveGroupName.Text = "Opc Remove Group Name";
			this.OpcRemoveGroupName.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// RemoveOpcGroup
			// 
			this.RemoveOpcGroup.Location = new System.Drawing.Point(260, 312);
			this.RemoveOpcGroup.Name = "RemoveOpcGroup";
			this.RemoveOpcGroup.Size = new System.Drawing.Size(216, 32);
			this.RemoveOpcGroup.TabIndex = 117;
			this.RemoveOpcGroup.Text = "Remove Opc Group";
			this.RemoveOpcGroup.Click += new System.EventHandler(this.RemoveOpcGroup_Click);
			// 
			// OpcGroupName
			// 
			this.OpcGroupName.BackColor = System.Drawing.Color.Yellow;
			this.OpcGroupName.Location = new System.Drawing.Point(28, 120);
			this.OpcGroupName.Name = "OpcGroupName";
			this.OpcGroupName.Size = new System.Drawing.Size(216, 32);
			this.OpcGroupName.TabIndex = 116;
			this.OpcGroupName.Text = "Opc Group Name";
			this.OpcGroupName.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// AddOpcGroup
			// 
			this.AddOpcGroup.Location = new System.Drawing.Point(260, 120);
			this.AddOpcGroup.Name = "AddOpcGroup";
			this.AddOpcGroup.Size = new System.Drawing.Size(216, 32);
			this.AddOpcGroup.TabIndex = 115;
			this.AddOpcGroup.Text = "Add Opc Group";
			this.AddOpcGroup.Click += new System.EventHandler(this.AddOpcGroup_Click);
			// 
			// OpcServerDisConnect
			// 
			this.OpcServerDisConnect.Location = new System.Drawing.Point(260, 376);
			this.OpcServerDisConnect.Name = "OpcServerDisConnect";
			this.OpcServerDisConnect.Size = new System.Drawing.Size(216, 32);
			this.OpcServerDisConnect.TabIndex = 114;
			this.OpcServerDisConnect.Text = "Opc Server DisConnect";
			this.OpcServerDisConnect.Click += new System.EventHandler(this.OpcServerDisConnect_Click);
			// 
			// OpcServerRemove
			// 
			this.OpcServerRemove.BackColor = System.Drawing.Color.Yellow;
			this.OpcServerRemove.Location = new System.Drawing.Point(28, 376);
			this.OpcServerRemove.Name = "OpcServerRemove";
			this.OpcServerRemove.Size = new System.Drawing.Size(216, 32);
			this.OpcServerRemove.TabIndex = 113;
			this.OpcServerRemove.Text = "Opc Server Remove";
			this.OpcServerRemove.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// bOpcServerName
			// 
			this.bOpcServerName.BackColor = System.Drawing.Color.Yellow;
			this.bOpcServerName.Location = new System.Drawing.Point(28, 56);
			this.bOpcServerName.Name = "bOpcServerName";
			this.bOpcServerName.Size = new System.Drawing.Size(216, 32);
			this.bOpcServerName.TabIndex = 112;
			this.bOpcServerName.Text = "Opc Server Name";
			this.bOpcServerName.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// bOpcServerConnect

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -