资源简介
希望对有需要的朋友带来便利
代码片段和文件信息
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#示波器完整
- C#编写的CRC校验软件
- C#开发大全(基础卷)源码
- C#垃圾代码生成器.rar
- 使用c#控制台应用程序写游戏—消消乐
- C#XPS 转为图片并保存
- HTML、C#以及SQL Server学生信息管理系统
- c#两个串口实现图片传输并且实现图片
- opc 客户端c#编写数据同时存入mysql数据
- C# Bitmap转RGB32(NI)
- 智能水表c##代码
- c#随机出题
- C#求矩阵运算代码,特征值特征向量
- C#斑马打印机源程序
- 绘制矢量图C#源码
- c# 自定义的数字键盘和字母键盘
- C#网络应用编程第三版马骏主编上机练
- 项目实战C#聊天工具包含服务器和客户
- 基于C#的网吧计费系统Web+数据库
- web留言板报告C#
- C#全套教程.txt
- C#影院售票系统
- c# 排序算法诠释排序过程
- C#开发大全(基础卷+提高卷)源码
- c#对文件加密
- Asp.net 基础教程含视频+进阶视频
- 24路舵机控制板C#源码
- C#星星程序
- C#简易计算器.zip
- c#TCP与川崎机器人通信
评论
共有 条评论