资源简介
希望对有需要的朋友带来便利
![](http://www.nz998.com/pic/58412.jpg)
代码片段和文件信息
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#示波器完整
相关资源
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
- 基于c#的实验室设备管理系统621530
- C# 使用ListView控件实现图片浏览器(源
- C#简单窗体聊天程序
- C#指纹识别系统程序 报告
- c# 高校档案信息管理系统
评论
共有 条评论