資源簡介
希望對有需要的朋友帶來便利

代碼片段和文件信息
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?System.Net;
using?System.Collections;
using?OPCAutomation;
namespace?OPCSet?
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????#region?私有變量
????????//?OPCServer?object
????????OPCServer?KepServer;
????????//OPCGroups?object
????????OPCGroups?KepGroups;
????????//?OPCGroup?object
????????OPCGroup?KepGroup;
????????//?OPCItems?object
????????OPCItems?KepItems;
????????//?OPCItem?object
????????OPCItem?KepItem;
????????//主機IP
????????string?strHostIP?=?““;
????????//?主機名稱
????????string?strHostName?=?““;
????????//?連接狀態
????????bool?opc_connected?=?false;
????????//?客戶端句柄
????????int?itmHandleClient?=?0;
????????//服務器句柄
????????int?itmHandleServer?=?0;
????????#endregion
????????#region?方法
????????//枚舉本地OPC服務器
????????private?void?GetLocalServer()
????????{
????????????//獲取本地計算機IP,名稱
????????????IPHostEntry?IPHost?=?Dns.GetHostEntry(Environment.MachineName);?????//將主機名或ip地址解析為IPhostentry實例
????????????if?(IPHost.AddressList.Length?>?0)
????????????{
????????????????strHostIP?=?IPHost.AddressList[0].ToString();
????????????}
????????????else
????????????{
????????????????return;
????????????}
????????????//通過IP來獲取計算機名稱
????????????IPHostEntry?ipHostEntry?=?Dns.GetHostByAddress(strHostIP);
????????????strHostName?=?ipHostEntry.HostName.ToString();
????????????//獲取本地計算機上的OPCServerName
????????????try
????????????{
????????????????KepServer?=?new?OPCServer();?????//創建一個opcserver對象,初始化
????????????????object?serverList?=?KepServer.GetOPCServers(strHostName);
????????????????foreach?(string?turn?in?(Array)serverList)
????????????????{
????????????????????comboBox1.Items.Add(turn);//即服務器combobox1框內顯示的是opcserver的名稱
????????????????}
????????????????comboBox1.SelectedIndex?=?0;
????????????????button1.Enabled?=?true;?????????//即連接按鈕
????????????}
????????????catch?(Exception?err)
????????????{
????????????????MessageBox.Show(“枚舉本地OPC服務器出錯:“?+?err.Message?“提示信息“?MessageBoxButtons.OK?MessageBoxIcon.Warning);
????????????????//提示框樣式
????????????}
????????}
????????//創建組
????????private?bool?CreatGroup()
????????{
????????????try
????????????{
????????????????KepGroups?=?KepServer.OPCGroups;
????????????????KepGroup?=?KepGroups.Add(“OPCDOTNETGROUP“);
????????????????SetGroupProperty();
????????????????KepGroup.DataChange?+=?new?DIOPCGroupEvent_DataChangeEventHandler(KepGroup_DataChange);
????????????????KepGroup.AsyncWriteComplete?+=?new?DIOPCGroupEvent_AsyncWriteCompleteEventHandler(KepGroup_AsyncWriteComplete);
????????????????KepItems?=?KepGroup.OPCItems;
????????????}
????????????catch?(Exception?ex)
????????????{
????????????????MessageBox.Show(“創建組出現錯誤:“?+?ex.
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-10-26?20:01??OPCSet\
?????文件???????18441??2016-10-26?10:02??OPCSet\dictionary.docx
?????目錄???????????0??2016-10-21?10:58??OPCSet\OPCSet\
?????文件?????????908??2016-10-21?10:58??OPCSet\OPCSet.sln
?????文件???????36352??2016-10-29?11:05??OPCSet\OPCSet.v11.suo
?????文件?????????187??2016-10-21?10:58??OPCSet\OPCSet\App.config
?????目錄???????????0??2016-10-21?10:58??OPCSet\OPCSet\bin\
?????目錄???????????0??2016-10-21?17:11??OPCSet\OPCSet\bin\Debug\
?????文件???????24576??2016-10-27?14:12??OPCSet\OPCSet\bin\Debug\OPCSet.exe
?????文件?????????187??2016-10-21?10:58??OPCSet\OPCSet\bin\Debug\OPCSet.exe.config
?????文件???????32256??2016-10-27?14:12??OPCSet\OPCSet\bin\Debug\OPCSet.pdb
?????文件???????22984??2016-10-29?10:27??OPCSet\OPCSet\bin\Debug\OPCSet.vshost.exe
?????文件?????????187??2016-10-21?10:58??OPCSet\OPCSet\bin\Debug\OPCSet.vshost.exe.config
?????文件?????????490??2013-03-18?17:00??OPCSet\OPCSet\bin\Debug\OPCSet.vshost.exe.manifest
?????文件???????11013??2016-10-26?09:47??OPCSet\OPCSet\Form1.cs
?????文件???????18463??2016-10-21?18:45??OPCSet\OPCSet\Form1.Designer.cs
?????文件????????6190??2016-10-21?18:45??OPCSet\OPCSet\Form1.resx
?????目錄???????????0??2016-10-21?10:58??OPCSet\OPCSet\obj\
?????目錄???????????0??2016-10-27?14:12??OPCSet\OPCSet\obj\Debug\
?????文件????????1308??2016-10-21?19:14??OPCSet\OPCSet\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件????????6929??2016-10-21?11:36??OPCSet\OPCSet\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件???????28672??2016-10-21?11:36??OPCSet\OPCSet\obj\Debug\Interop.OPCAutomation.dll
?????文件?????????578??2016-10-29?10:27??OPCSet\OPCSet\obj\Debug\OPCSet.csproj.FileListAbsolute.txt
?????文件?????????975??2016-10-21?19:24??OPCSet\OPCSet\obj\Debug\OPCSet.csproj.GenerateResource.Cache
?????文件?????????735??2016-10-21?11:36??OPCSet\OPCSet\obj\Debug\OPCSet.csproj.ResolveComReference.cache
?????文件????????2209??2016-10-21?17:11??OPCSet\OPCSet\obj\Debug\OPCSet.csprojResolveAssemblyReference.cache
?????文件???????24576??2016-10-27?14:12??OPCSet\OPCSet\obj\Debug\OPCSet.exe
?????文件?????????180??2016-10-21?19:24??OPCSet\OPCSet\obj\Debug\OPCSet.Form1.resources
?????文件???????32256??2016-10-27?14:12??OPCSet\OPCSet\obj\Debug\OPCSet.pdb
?????文件?????????180??2016-10-21?17:11??OPCSet\OPCSet\obj\Debug\OPCSet.Properties.Resources.resources
?????文件???????????0??2016-10-21?10:58??OPCSet\OPCSet\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
............此處省略13個文件信息
- 上一篇:腦電波控制的打磚塊游戲
- 下一篇:C#示波器完整
評論
共有 條評論