?? form1.cs
字號(hào):
using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
class tag
{
public uint handle;
public string name;
public object value;
public ushort quality;
public long timeStamp;
public tag(string pName)
{
handle=0;
quality=0;
value=0;
timeStamp=DateTime.Now.ToFileTime();
name=pName;
}
}
namespace DAS_CSDEMO
{
unsafe public delegate void WRITECALLBACK(uint handle, object value, ref int errorCode);
unsafe public delegate void WRITECALLBACKEX(uint handle, uint propertyID, object value, ref int errorCode);
unsafe public delegate void READCALLBACK(uint handle,ref object value, ref ushort quality,ref long timeStamp,ref int errorCode);
unsafe public delegate void READCALLBACKEX(uint handle, uint propertyID, ref object value, ref ushort quality,ref long timeStamp,ref int errorCode);
unsafe public delegate void SERVERNOTIFY(uint handle, ushort operationType);
unsafe public delegate void GROUPNOTIFY(uint handle, string groupName, ushort operationType);
unsafe public delegate void ITEMNOTIFY(uint handle, uint tagHandle,ushort operationType);
unsafe public delegate void TAGNOTIFY(string tagName, string tagAccessPath, uint* tagHandle);
unsafe public delegate void LOGNOTIFY(string logMsg);
/// <summary>
/// Form1 的摘要說明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem mnFile;
private System.Windows.Forms.MenuItem mnRegister;
private System.Windows.Forms.MenuItem mnUnregister;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem mnExit;
private System.Windows.Forms.MenuItem mnHelp;
private System.Windows.Forms.MenuItem mnAbout;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.StatusBarPanel statusBarPanel1;
private System.Windows.Forms.StatusBarPanel statusBarPanel2;
private System.Windows.Forms.StatusBarPanel statusBarPanel3;
private System.Windows.Forms.TreeView treeView1;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.ListView listView1;
private System.ComponentModel.IContainer components;
private const string ClassID = "{E01F7DF1-6311-48b5-A1A5-E4B3B9C933F2}";
private const string ProgID = "OPC.ASCSDEMO.1";
private const string Desc = "OPC ASCSDEMO 1";
private ArrayList tagList;
private int seed, cntCount=0;
private WRITECALLBACK m_writeCallback;
private READCALLBACK m_readCallback;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ColumnHeader columnHeader4;
private SERVERNOTIFY m_serverNotify;
[DllImport("ASOPCDA.dll")]
public static extern bool RegServer(string classID, string progID, string desc, string path);
[DllImport("ASOPCDA.dll")]
public static extern bool UnregServer(string classID, string progID);
[DllImport("ASOPCDA.dll")]
public static extern bool CreateServer(string classID, uint updateRate);
[DllImport("ASOPCDA.dll")]
public static extern void FreeServer();
[DllImport("ASOPCDA.dll")]
public static extern bool CreateServer(string userID, string passWord);
[DllImport("ASOPCDA.dll")]
public static extern void ShutDown();
[DllImport("ASOPCDA.dll")]
public static extern bool SetServerState(ushort serverState);
[DllImport("ASOPCDA.dll")]
public static extern void SetVersion(string vendor, ushort majorVersion, ushort minorVersion, ushort buildNumber);
[DllImport("ASOPCDA.dll")]
public static extern uint RegTag(uint parentHandle,string tagName, object value, ushort quality, ushort accessRight);
[DllImport("ASOPCDA.dll")]
public static extern uint RegTagEx(uint parentHandle,string tagName, ushort dataType, ushort accessRight);
[DllImport("ASOPCDA.dll")]
public static extern bool UnregTag(uint handle);
[DllImport("ASOPCDA.dll")]
public static extern bool AddTagProperty(uint handle, string propertyName, string propertyDesc, object propertyValue);
[DllImport("ASOPCDA.dll")]
public static extern bool AddTagPropertyEx(uint handle, string propertyName, string propertyDesc, ushort dataType);
[DllImport("ASOPCDA.dll")]
public static extern bool SetTagQualifier(char qualifier);
[DllImport("ASOPCDA.dll")]
public static extern bool UpdateTag(uint handle, object value, ushort quality);
[DllImport("ASOPCDA.dll")]
public static extern bool UpdateTagWithTimeStamp(uint handle, object value, ushort quality, long TimeStamp);
[DllImport("ASOPCDA.dll")]
public static extern bool SetTagProperty(uint handle, uint propertyID, object value);
[DllImport("ASOPCDA.dll")]
public static extern bool SetWriteCallback(WRITECALLBACK lpCallback);
[DllImport("ASOPCDA.dll")]
public static extern bool SetWriteCallbackEx(WRITECALLBACKEX lpCallback);
[DllImport("ASOPCDA.dll")]
public static extern bool SetReadCallback(READCALLBACK lpCallback);
[DllImport("ASOPCDA.dll")]
public static extern bool SetReadCallbackEx(READCALLBACKEX lpCallback);
[DllImport("ASOPCDA.dll")]
public static extern bool SetServerNotify(SERVERNOTIFY lpCallback);
[DllImport("ASOPCDA.dll")]
public static extern bool SetGroupNotify(GROUPNOTIFY lpCallback);
[DllImport("ASOPCDA.dll")]
public static extern bool SetItemNotify(ITEMNOTIFY lpCallback);
[DllImport("ASOPCDA.dll")]
public static extern bool SetLogNotify(LOGNOTIFY lpCallback);
unsafe public void WriteCallback(uint handle, object value, ref int errorCode)
{
errorCode=1;
foreach(tag Tag in tagList)
{
if(Tag.handle==handle)
{
Tag.value=value;
Tag.quality=192;
Tag.timeStamp=DateTime.Now.ToFileTime();
UpdateTagWithTimeStamp(Tag.handle, Tag.value, Tag.quality, Tag.timeStamp);
errorCode=0;
Monitor();
break;
}
}
}
unsafe public void ReadCallback(uint handle, ref object value, ref ushort quality, ref long timeStamp,ref int errorCode)
{
errorCode=1;
foreach(tag Tag in tagList)
{
if(Tag.handle==handle)
{
value=Tag.value;
quality=Tag.quality;
timeStamp=Tag.timeStamp;
errorCode=0;
break;
}
}
}
unsafe public void ServerNotify(uint handle, ushort operationType)
{
if(operationType==0)
cntCount++;
else
cntCount--;
if(cntCount<=0)
Close();
}
public Form1()
{
//
// Windows 窗體設(shè)計(jì)器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼
//
}
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗體設(shè)計(jì)器生成的代碼
/// <summary>
/// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.mnFile = new System.Windows.Forms.MenuItem();
this.mnRegister = new System.Windows.Forms.MenuItem();
this.mnUnregister = new System.Windows.Forms.MenuItem();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.mnExit = new System.Windows.Forms.MenuItem();
this.mnHelp = new System.Windows.Forms.MenuItem();
this.mnAbout = new System.Windows.Forms.MenuItem();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanel3 = new System.Windows.Forms.StatusBarPanel();
this.treeView1 = new System.Windows.Forms.TreeView();
this.splitter1 = new System.Windows.Forms.Splitter();
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).BeginInit();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnFile,
this.mnHelp});
//
// mnFile
//
this.mnFile.Index = 0;
this.mnFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnRegister,
this.mnUnregister,
this.menuItem1,
this.mnExit});
this.mnFile.Text = "&File";
//
// mnRegister
//
this.mnRegister.Index = 0;
this.mnRegister.Text = "&Register Server";
this.mnRegister.Click += new System.EventHandler(this.mnRegister_Click);
//
// mnUnregister
//
this.mnUnregister.Index = 1;
this.mnUnregister.Text = "&Unregister Server";
this.mnUnregister.Click += new System.EventHandler(this.mnUnregister_Click);
//
// menuItem1
//
this.menuItem1.Index = 2;
this.menuItem1.Text = "-";
//
// mnExit
//
this.mnExit.Index = 3;
this.mnExit.Text = "E&xit";
this.mnExit.Click += new System.EventHandler(this.mnExit_Click);
//
// mnHelp
//
this.mnHelp.Index = 1;
this.mnHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnAbout});
this.mnHelp.Text = "&Help";
//
// mnAbout
//
this.mnAbout.Index = 0;
this.mnAbout.Text = "&About...";
//
// timer1
//
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 411);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.statusBarPanel1,
this.statusBarPanel2,
this.statusBarPanel3});
this.statusBar1.ShowPanels = true;
this.statusBar1.Size = new System.Drawing.Size(632, 22);
this.statusBar1.TabIndex = 3;
this.statusBar1.Text = "statusBar1";
//
// statusBarPanel1
//
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -