📄 connectsampleform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using HaiGrang.Package.OpcNetApiChs.Opc;
using HaiGrang.Package.OpcNetApiChs.Da;
using HaiGrang.Package.OpcNetApiChs.DaNet;
namespace ConnectSample
{
/// <summary>
/// ConnectSample 的摘要说明。
/// </summary>
public class ConnectSampleForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button OpcServerDisConnect;
private System.Windows.Forms.Label OpcServerHostInfo;
private System.Windows.Forms.Label bOpcServerName;
private System.Windows.Forms.Button bOpcServerConnect;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public ConnectSampleForm()
{
//
// 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.OpcServerDisConnect = new System.Windows.Forms.Button();
this.OpcServerHostInfo = new System.Windows.Forms.Label();
this.bOpcServerName = new System.Windows.Forms.Label();
this.bOpcServerConnect = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// OpcServerDisConnect
//
this.OpcServerDisConnect.Location = new System.Drawing.Point(312, 128);
this.OpcServerDisConnect.Name = "OpcServerDisConnect";
this.OpcServerDisConnect.Size = new System.Drawing.Size(216, 32);
this.OpcServerDisConnect.TabIndex = 36;
this.OpcServerDisConnect.Text = "Opc Server DisConnect";
this.OpcServerDisConnect.Click += new System.EventHandler(this.OpcServerDisConnect_Click);
//
// OpcServerHostInfo
//
this.OpcServerHostInfo.BackColor = System.Drawing.Color.Yellow;
this.OpcServerHostInfo.Location = new System.Drawing.Point(56, 128);
this.OpcServerHostInfo.Name = "OpcServerHostInfo";
this.OpcServerHostInfo.Size = new System.Drawing.Size(216, 32);
this.OpcServerHostInfo.TabIndex = 35;
this.OpcServerHostInfo.Text = "Opc Server HostInfo";
this.OpcServerHostInfo.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// bOpcServerName
//
this.bOpcServerName.BackColor = System.Drawing.Color.Yellow;
this.bOpcServerName.Location = new System.Drawing.Point(56, 72);
this.bOpcServerName.Name = "bOpcServerName";
this.bOpcServerName.Size = new System.Drawing.Size(216, 32);
this.bOpcServerName.TabIndex = 34;
this.bOpcServerName.Text = "Opc Server Name";
this.bOpcServerName.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// bOpcServerConnect
//
this.bOpcServerConnect.Location = new System.Drawing.Point(312, 72);
this.bOpcServerConnect.Name = "bOpcServerConnect";
this.bOpcServerConnect.Size = new System.Drawing.Size(216, 32);
this.bOpcServerConnect.TabIndex = 33;
this.bOpcServerConnect.Text = "Opc Server Connect";
this.bOpcServerConnect.Click += new System.EventHandler(this.bOpcServerConnect_Click);
//
// ConnectSampleForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(1016, 741);
this.Controls.Add(this.OpcServerDisConnect);
this.Controls.Add(this.OpcServerHostInfo);
this.Controls.Add(this.bOpcServerName);
this.Controls.Add(this.bOpcServerConnect);
this.Name = "ConnectSampleForm";
this.Text = "ConnectSample";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.ConnectSampleForm_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new ConnectSampleForm());
}
private void ConnectSampleForm_Load(object sender, System.EventArgs e)
{
}
private void bOpcServerConnect_Click(object sender, System.EventArgs e)
{
OpcServerConnect() ;
}
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@ Opc Connect Server @@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
private string tMachineString = "" ;
private string tKEPServerExUrlString = "KEPware.KEPServerEx.V4" ;
OpcServer tOpcServer = new OpcServer() ;
private void OpcServerConnect()
{
tOpcServer.Connect( tMachineString, tKEPServerExUrlString );
bOpcServerName.Text = tOpcServer.ServerName.ToString() ;
OpcServerHostInfo.Text = tOpcServer.HostInfo.ToString() ;
}
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@ Opc DisConnect Server @@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
private void OpcServerDisConnect_Click(object sender, System.EventArgs e)
{
tOpcServer.Disconnect() ;
bOpcServerName.Text = "Opc Server Disconnect" ;
OpcServerHostInfo.Text = "Opc Server Disconnect" ;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -