-
大小: 257KB文件类型: .zip金币: 2下载: 2 次发布日期: 2021-06-17
- 语言: C#
- 标签: C# OPC automation
资源简介
c#编写的 OPC 客户端 读取程序,将读取值存入SQLserver。

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OPC_Client.Methods;//添加引用
using OPCAutomation;
namespace OPC_Client
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
}
#region 声明变量与定义
DataTable dt = new DataTable();
IpRead ipread = new IpRead();//IP 操作类
SqlHelper sqlhp = new SqlHelper();//数据库操作
string LocalIP = ““;//IP地址
OPCServer KepServer;
OPCGroups KepGroups;
OPCGroup KepGroup;
OPCItems KepItems;
OPCItem KepItem;
int itmHandleClient = 0;//客户端句柄
int itmHandleServer = 0;//服务端句柄
bool opc_connected = false;//opc连接状态
#endregion
private void Frm_Main_Load(object sender EventArgs e)
{
LocalIP = txt_LocalIP.Text = ipread.RetrunIP();//获取本机IP地址
GetLocalServer();//枚举本地OPC服务器
dt.Columns.Add(“标签“ System.Type.GetType(“System.String“));
dt.Columns.Add(“测量值“ System.Type.GetType(“System.String“));
dt.Columns.Add(“质量“ System.Type.GetType(“System.String“));
dt.Columns.Add(“时间戳“ System.Type.GetType(“System.String“));
dgv_dataShow.DataSource = dt;
}
private void GetLocalServer()
{
//检查IP地址是否合法
if (System.Text.Regularexpressions.Regex.IsMatch(LocalIP “[0-9]{13}\\.[0-9]{13}\\.[0-9]{13}\\.[0-9]{13}“))
{
string CoputerName = Dns.GetHostByAddress(LocalIP).HostName.ToString();
try
{
KepServer = new OPCServer();
object serverList = KepServer.GetOPCServers(CoputerName);
foreach (string turn in (Array)serverList)
{
cmb_OpcServer.Items.Add(turn);
}
cmb_OpcServer.SelectedIndex = 0;
Btn_ServerConnect.Enabled = true;
}
catch (Exception err)
{
MessageBox.Show(“枚举本地OPC服务器出错:“ + err.Message “提示信息“ MessageBoxButtons.OK MessageBoxIcon.Warning);
}
}
else { MessageBox.Show(“IP地址不合法,请检查!!!“ “友情提示“); }
}
///
/// 【按钮】连接服务器
///
///
///
private void Btn_ServerConnect_Click(object sender EventArgs e)
{
try
{
KepServer.Connect(cmb_OpcServer.Text txt_LocalIP.Text);
if (KepServer.ServerState == (int)OPCServerState.OPCRunning)
{
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3021 2016-07-25 10:58 51Aspx源码必读.txt
文件 187 2016-07-20 09:01 App.config
目录 0 2016-07-25 10:51 DB_51aspx\
文件 3145728 2016-07-25 10:58 DB_51aspx\OPC_Test.mdf
文件 1048576 2016-07-25 10:58 DB_51aspx\OPC_Test_log.ldf
文件 22960 2016-07-20 14:49 Frm_Main.Designer.cs
文件 11138 2016-07-20 14:51 Frm_Main.cs
文件 12549 2016-07-20 14:49 Frm_Main.resx
目录 0 2016-07-25 10:51 Methods\
文件 1031 2016-07-20 09:16 Methods\IpRead.cs
文件 2051 2016-07-25 10:54 Methods\SqlHelper.cs
文件 4288 2016-07-20 14:21 OPC Client.csproj
文件 909 2016-07-25 10:53 OPC Client.sln
文件 26112 2016-07-25 10:53 OPC Client.v11.suo
文件 525 2016-07-20 09:01 Program.cs
目录 0 2016-07-25 10:51 Properties\
文件 1352 2016-07-20 09:00 Properties\AssemblyInfo.cs
文件 2872 2016-07-20 09:00 Properties\Resources.Designer.cs
文件 5612 2016-07-20 09:00 Properties\Resources.resx
文件 1097 2016-07-20 09:00 Properties\Settings.Designer.cs
文件 249 2016-07-20 09:00 Properties\Settings.settings
目录 0 2016-07-25 10:51 bin\
目录 0 2016-07-25 10:54 bin\Debug\
文件 40960 2009-01-08 16:11 bin\Debug\Interop.OPCAutomation.dll
文件 33792 2016-07-25 10:54 bin\Debug\OPC Client.exe
文件 187 2016-07-20 09:01 bin\Debug\OPC Client.exe.config
文件 38400 2016-07-25 10:54 bin\Debug\OPC Client.pdb
文件 22984 2016-07-25 10:56 bin\Debug\OPC Client.vshost.exe
文件 187 2016-07-20 09:01 bin\Debug\OPC Client.vshost.exe.config
文件 490 2012-06-02 22:34 bin\Debug\OPC Client.vshost.exe.manifest
目录 0 2016-07-25 10:58 bin\Release\
............此处省略16个文件信息
- 上一篇:C# 连连看 源码
- 下一篇:headfirstc#赛狗日源代码
相关资源
- C# IP地址输入控件
- C#在一个窗口刷新更改另一个窗口控件
- C# TIP文件生成和拆解
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- 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 操作摄像头录像附
评论
共有 条评论